SlideShare una empresa de Scribd logo
1 de 59
#phpday
          Dica trentatrè <?php echo ’33’ ?>
           Controllare lo stato di salute di una applicazione con le
                             metriche del codice




                                            Michele Orselli (@_orso_)
#phpday


          Code Metrics
Measure of some property of a piece
#phpday



               of software (Wikipedia)
#phpday


          Who Cares?
#phpday

          How long will it take to add feature X?
#phpday

          Internal vs External Quality
Code Metrics as a mean to expose
#phpday



                  internal quality
#phpday

          How long will it take to add feature X?
#phpday


          Classic
Lines and Numbers

          Lines
                  LOC: Lines Of Code
#phpday           ELOC: Executable LOC
                  CLOC: Comment LOC
                  NCLOC: Non-Comment LOC

          Numbers
             NOC: Number Of Classes
             NOM: Number Of Methods
             NOP: Number Of Packages
Lines and Numbers
                            1    <?php
                            2
           Lines            3    namespace shapestwodimensional;
                            4
                            5    abstract class shape {
                            6      /* Returns the area of the shape */
#phpday                     7      abstract function area();
                            8    }
                            9
                            10   class circle extends shape {
                            11      public function area() {}
                            12
                            13        /* Ret the diameter of the circle */
          Numbers           14        public function diameter() {}
                            15   }
                            16
                            17   class triangle extends shape {
                            18
                            19        public function area() {}
                            20   }
                            21
                            22   ?>
Lines and Numbers
                            1    <?php
                            2
           Lines            3    namespace shapestwodimensional;
                            4
                   LOC 22   5    abstract class shape {
                            6      /* Returns the area of the shape */
#phpday                     7      abstract function area();
                            8    }
                            9
                            10   class circle extends shape {
                            11      public function area() {}
                            12
                            13        /* Ret the diameter of the circle */
          Numbers           14        public function diameter() {}
                            15   }
                            16
                            17   class triangle extends shape {
                            18
                            19        public function area() {}
                            20   }
                            21
                            22   ?>
Lines and Numbers
                            1    <?php
                            2
           Lines            3    namespace shapestwodimensional;
                            4
                   LOC 22   5    abstract class shape {
                            6      /* Returns the area of the shape */
#phpday       CLOC      2   7      abstract function area();
                            8    }
                            9
                            10   class circle extends shape {
                            11      public function area() {}
                            12
                            13        /* Ret the diameter of the circle */
          Numbers           14        public function diameter() {}
                            15   }
                            16
                            17   class triangle extends shape {
                            18
                            19        public function area() {}
                            20   }
                            21
                            22   ?>
Lines and Numbers
                            1    <?php
                            2
           Lines            3    namespace shapestwodimensional;
                            4
                   LOC 22   5    abstract class shape {
                            6      /* Returns the area of the shape */
#phpday       CLOC      2   7      abstract function area();
                            8    }
            NCLOC 20        9
                            10   class circle extends shape {
                            11      public function area() {}
                            12
                            13        /* Ret the diameter of the circle */
          Numbers           14        public function diameter() {}
                            15   }
                            16
                            17   class triangle extends shape {
                            18
                            19        public function area() {}
                            20   }
                            21
                            22   ?>
Lines and Numbers
                            1    <?php
                            2
           Lines            3    namespace shapestwodimensional;
                            4
                   LOC 22   5    abstract class shape {
                            6      /* Returns the area of the shape */
#phpday       CLOC      2   7      abstract function area();
                            8    }
            NCLOC 20        9
                            10   class circle extends shape {
               ELOC     3   11      public function area() {}
                            12
                            13        /* Ret the diameter of the circle */
          Numbers           14        public function diameter() {}
                            15   }
                            16
                            17   class triangle extends shape {
                            18
                            19        public function area() {}
                            20   }
                            21
                            22   ?>
Lines and Numbers
                            1    <?php
                            2
           Lines            3    namespace shapestwodimensional;
                            4
                   LOC 22   5    abstract class shape {
                            6      /* Returns the area of the shape */
#phpday       CLOC      2   7      abstract function area();
                            8    }
            NCLOC 20        9
                            10   class circle extends shape {
               ELOC     3   11      public function area() {}
                            12
                            13        /* Ret the diameter of the circle */
          Numbers           14        public function diameter() {}
                            15   }
               NOP      1   16
                            17   class triangle extends shape {
                            18
                            19        public function area() {}
                            20   }
                            21
                            22   ?>
Lines and Numbers
                            1    <?php
                            2
           Lines            3    namespace shapestwodimensional;
                            4
                   LOC 22   5    abstract class shape {
                            6      /* Returns the area of the shape */
#phpday       CLOC      2   7      abstract function area();
                            8    }
            NCLOC 20        9
                            10   class circle extends shape {
               ELOC     3   11      public function area() {}
                            12
                            13        /* Ret the diameter of the circle */
          Numbers           14        public function diameter() {}
                            15   }
               NOP      1   16
                            17   class triangle extends shape {
               NOC      3   18
                            19        public function area() {}
                            20   }
                            21
                            22   ?>
Lines and Numbers
                            1    <?php
                            2
           Lines            3    namespace shapestwodimensional;
                            4
                   LOC 22   5    abstract class shape {
                            6      /* Returns the area of the shape */
#phpday       CLOC      2   7      abstract function area();
                            8    }
            NCLOC 20        9
                            10   class circle extends shape {
               ELOC     3   11      public function area() {}
                            12
                            13        /* Ret the diameter of the circle */
          Numbers           14        public function diameter() {}
                            15   }
               NOP      1   16
                            17   class triangle extends shape {
               NOC      3   18
                            19        public function area() {}
               NOM      4   20   }
                            21
                            22   ?>
#phpday
                       phploc
          http://sebastianbergmann.github.com/phploc/
#phpday
#phpday


          Complexity
Complexity


#phpday
          Control Structures Complexity
           if, elseif, for, while, foreach, catch, case, xor,
           and, or, &&, ||, ?:
          Ciclomatic Complexity (CCN)
          NPath Complexity
Ciclomatic Complexity
                              1    <?php
                              2
          # decision points   3    class polygon {
                              4
                              5    public function perimeter()
                              6    {
#phpday           CCN         7        if (!is_array($this->vertices)) {
                              8            return false;
                              9        }
                              10
                              11        $perimeter = 0;
                              12
                              13        foreach ($this->vertices as $vertex) {
                              14          $perimenter += $vertex;
                              15        }
                              16
                              17        return $perimeter;
                              18        }
                              19   }
                              20   ?>
Ciclomatic Complexity
                                  1    <?php
                                  2
          # decision points       3    class polygon {
                                  4
                                  5    public function perimeter()
                                  6    {
#phpday           CCN         1   7        if (!is_array($this->vertices)) {
                                  8            return false;
                                  9        }
                                  10
                                  11        $perimeter = 0;
                                  12
                                  13        foreach ($this->vertices as $vertex) {
                                  14          $perimenter += $vertex;
                                  15        }
                                  16
                                  17        return $perimeter;
                                  18        }
                                  19   }
                                  20   ?>
Ciclomatic Complexity
                                  1    <?php
                                  2
          # decision points       3    class polygon {
                                  4
                                  5    public function perimeter()
                                  6    {
#phpday           CCN         2   7        if (!is_array($this->vertices)) {
                                  8            return false;
                                  9        }
                                  10
                                  11        $perimeter = 0;
                                  12
                                  13        foreach ($this->vertices as $vertex) {
                                  14          $perimenter += $vertex;
                                  15        }
                                  16
                                  17        return $perimeter;
                                  18        }
                                  19   }
                                  20   ?>
Ciclomatic Complexity
                                  1    <?php
                                  2
          # decision points       3    class polygon {
                                  4
                                  5    public function perimeter()
                                  6    {
#phpday           CCN         3   7        if (!is_array($this->vertices)) {
                                  8            return false;
                                  9        }
                                  10
                                  11        $perimeter = 0;
                                  12
                                  13        foreach ($this->vertices as $vertex) {
                                  14          $perimenter += $vertex;
                                  15        }
                                  16
                                  17        return $perimeter;
                                  18        }
                                  19   }
                                  20   ?>
Ciclomatic Complexity
                                  1    <?php
                                  2
          # decision points       3    class polygon {
                                  4
                                  5    public function perimeter()
                                  6    {
#phpday           CCN         4   7        if (!is_array($this->vertices)) {
                                  8            return false;
                                  9        }
                                  10
                                  11        $perimeter = 0;
                                  12
                                  13        foreach ($this->vertices as $vertex) {
                                  14          $perimenter += $vertex;
                                  15        }
                                  16
                                  17        return $perimeter;
                                  18        }
                                  19   }
                                  20   ?>
CCN Range Values


#phpday         1 - 4: low
               5-7: medium
                8-10: high
                11+: wtf
NPath Complexity
                            1    <?php
                            2
          # acyclic paths   3    class polygon {
                            4
                            5    public function perimeter()
                            6    {
#phpday           NPath     7        if (!is_array($this->vertices)) {
                            8            return false;
                            9        }
                            10
                            11        $perimeter = 0;
                            12
                            13        foreach ($this->vertices as $vertex) {
                            14          $perimenter += $vertex;
                            15        }
                            16
                            17        return $perimeter;
                            18        }
                            19   }
                            20   ?>
NPath Complexity
                                1    <?php
                                2
          # acyclic paths       3    class polygon {
                                4
                                5    public function perimeter()
                                6    {
#phpday           NPath     1   7        if (!is_array($this->vertices)) {
                                8            return false;
                                9        }
                                10
                                11        $perimeter = 0;
                                12
                                13        foreach ($this->vertices as $vertex) {
                                14          $perimenter += $vertex;
                                15        }
                                16
                                17        return $perimeter;
                                18        }
                                19   }
                                20   ?>
NPath Complexity
                                1    <?php
                                2
          # acyclic paths       3    class polygon {
                                4
                                5    public function perimeter()
                                6    {
#phpday           NPath     2   7        if (!is_array($this->vertices)) {
                                8            return false;
                                9        }
                                10
                                11        $perimeter = 0;
                                12
                                13        foreach ($this->vertices as $vertex) {
                                14          $perimenter += $vertex;
                                15        }
                                16
                                17        return $perimeter;
                                18        }
                                19   }
                                20   ?>
NPath Complexity
                                1    <?php
                                2
          # acyclic paths       3    class polygon {
                                4
                                5    public function perimeter()
                                6    {
#phpday           NPath     3   7        if (!is_array($this->vertices)) {
                                8            return false;
                                9        }
                                10
                                11        $perimeter = 0;
                                12
                                13        foreach ($this->vertices as $vertex) {
                                14          $perimenter += $vertex;
                                15        }
                                16
                                17        return $perimeter;
                                18        }
                                19   }
                                20   ?>
NPath Complexity
                                1    <?php
                                2
          # acyclic paths       3    class polygon {
                                4
                                5    public function perimeter()
                                6    {
#phpday           NPath     4   7        if (!is_array($this->vertices)) {
                                8            return false;
                                9        }
                                10
                                11        $perimeter = 0;
                                12
                                13        foreach ($this->vertices as $vertex) {
                                14          $perimenter += $vertex;
                                15        }
                                16
                                17        return $perimeter;
                                18        }
                                19   }
                                20   ?>
NPath Treshold


#phpday




             Critical if > 200
#phpday
          PHP Depend
           http://pdepend.org
#phpday
Overview Pyramid


#phpday
#phpday


          OO Metrics
Afferent/Efferent Coupling


#phpday



          Ca: no. of unique incoming dependencies
          Ce: no. of unique outgoing dependencies
Afferent/Efferent Coupling

                         Shape
                         area()
#phpday



               Circle             Triangle
                area()              area()




              Math
               PI
Afferent/Efferent Coupling

                            Shape
                             area()
#phpday



               Circle                 Triangle
                area()                  area()




              Math       Ca: 1
               PI        Ce: 0
Afferent/Efferent Coupling

                               Shape
                                area()
#phpday



          Ca: 0   Circle                 Triangle
          Ce: 2    area()                  area()




                  Math      Ca: 1
                   PI       Ce: 0
Afferent/Efferent Coupling

                               Shape     Ca: 2
                                area()   Ce: 0
#phpday



          Ca: 1   Circle                  Triangle
          Ce: 1    area()                   area()




                  Math      Ca: 1
                   PI       Ce: 0
Afferent/Efferent Coupling

                               Shape     Ca: 2
                                area()   Ce: 0
#phpday



          Ca: 1   Circle                  Triangle Ca: 0
          Ce: 1    area()                   area() Ce: 1



                  Math      Ca: 1
                   PI       Ce: 0
#phpday

          $ pdepend --jdepend-chart=j.png .
Instability Chart


#phpday




          A = AC / (CC + AC)
                               D = | A + I | -1
          I = Ce / (Ce + Ca)
#phpday
          PHP MD
          http://phpmd.org
PHP MD


#phpday    Code Size Rules
            Design Rules
            Naming Rules
          Unused Code Rules
#phpday             $ phpmd src/ xml
          codesize,design,naming,unusedcode --
                   reportfile pmd.xml
#phpday
#phpday


          Non Static Analysis
C.R.A.P


           Change Risk Analysis Predictions or
#phpday

                  “Your code is crap”


          CRAP = CCN^2 * (1 – COV/100)^3 + CCN
#phpday


          Putting it all together
#phpday
             PHP_CodeBrowser
          https://github.com/mayflowergmbh/PHP_CodeBrowser.git
$ phpcb --log logs --source src --output
#phpday



                      code-browser
#phpday
             PHP Project Wizard
          https://github.com/sebastianbergmann/php-project-wizard.git
Code Metrics as a mean to expose
#phpday



                  internal quality
Further Reading


          http://manuel-pichler.de/
#phpday

          http://pdepend.org
          http://phpmd.org
          http://www.artima.com/weblogs/viewpost.jsp?thread=215899
Questions?

              @_orso_
#phpday
            mo@ideato.it


          http://joind.in/2989

Más contenido relacionado

La actualidad más candente (6)

005 ellipse
005 ellipse005 ellipse
005 ellipse
 
Pmr trial-2010-math-qa-perak
Pmr trial-2010-math-qa-perakPmr trial-2010-math-qa-perak
Pmr trial-2010-math-qa-perak
 
FP305 data structure june 2012
FP305   data structure june 2012FP305   data structure june 2012
FP305 data structure june 2012
 
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMINGFINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
 
Gate-Cs 1995
Gate-Cs 1995Gate-Cs 1995
Gate-Cs 1995
 
Ec2203 digital electronics questions anna university by www.annaunivedu.org
Ec2203 digital electronics questions anna university by www.annaunivedu.orgEc2203 digital electronics questions anna university by www.annaunivedu.org
Ec2203 digital electronics questions anna university by www.annaunivedu.org
 

Destacado

Solor system pp
Solor system ppSolor system pp
Solor system pp
balle1km
 
Kebijakan moneter
Kebijakan moneterKebijakan moneter
Kebijakan moneter
Tedy El
 
Solar system
Solar system Solar system
Solar system
balle1km
 
Let’s count money
Let’s count moneyLet’s count money
Let’s count money
schra2ja
 

Destacado (13)

Solor system pp
Solor system ppSolor system pp
Solor system pp
 
Kebijakan moneter
Kebijakan moneterKebijakan moneter
Kebijakan moneter
 
Solar system
Solar system Solar system
Solar system
 
Continuous, continuous, continuous
Continuous, continuous, continuousContinuous, continuous, continuous
Continuous, continuous, continuous
 
DPC Tutorial
DPC TutorialDPC Tutorial
DPC Tutorial
 
Let's take over the world with Zend Framework
Let's take over the world with Zend FrameworkLet's take over the world with Zend Framework
Let's take over the world with Zend Framework
 
AChE
AChEAChE
AChE
 
Solor system pp
Solor system ppSolor system pp
Solor system pp
 
Final Solor system pp
Final Solor system ppFinal Solor system pp
Final Solor system pp
 
Let’s count money
Let’s count moneyLet’s count money
Let’s count money
 
Productive & easy mobile app dev
Productive & easy mobile app devProductive & easy mobile app dev
Productive & easy mobile app dev
 
High quality live broadcasting with PHP 27 07-2016
High quality live broadcasting with PHP 27 07-2016High quality live broadcasting with PHP 27 07-2016
High quality live broadcasting with PHP 27 07-2016
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similar a Dica trentatrè. &lt;?php echo "33"; ?>. Controllare lo stato di salute di una applicazione con le metriche del codice

Refactoring - improving the smell of your code
Refactoring - improving the smell of your codeRefactoring - improving the smell of your code
Refactoring - improving the smell of your code
vmandrychenko
 
Part 3-functions
Part 3-functionsPart 3-functions
Part 3-functions
ankita44
 
breaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdf
breaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdfbreaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdf
breaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdf
VishalKumarJha10
 
User defined functions
User defined functionsUser defined functions
User defined functions
shubham_jangid
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
Romain Francois
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
Romain Francois
 
Fosdem 2011 - A Common Graph Database Access Layer for .Net and Mono
Fosdem 2011 - A Common Graph Database Access Layer for .Net and MonoFosdem 2011 - A Common Graph Database Access Layer for .Net and Mono
Fosdem 2011 - A Common Graph Database Access Layer for .Net and Mono
Achim Friedland
 
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxCSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
faithxdunce63732
 

Similar a Dica trentatrè. &lt;?php echo "33"; ?>. Controllare lo stato di salute di una applicazione con le metriche del codice (20)

Refactoring - improving the smell of your code
Refactoring - improving the smell of your codeRefactoring - improving the smell of your code
Refactoring - improving the smell of your code
 
Functions12
Functions12Functions12
Functions12
 
Functions123
Functions123 Functions123
Functions123
 
Part 3-functions
Part 3-functionsPart 3-functions
Part 3-functions
 
breaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdf
breaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdfbreaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdf
breaking_dependencies_the_solid_principles__klaus_iglberger__cppcon_2020.pdf
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10
 
3433 Ch10 Ppt
3433 Ch10 Ppt3433 Ch10 Ppt
3433 Ch10 Ppt
 
cpp_sample
cpp_samplecpp_sample
cpp_sample
 
Chapter 17 corba
Chapter 17 corbaChapter 17 corba
Chapter 17 corba
 
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo FinochiettiRoslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
 
Roslyn: el futuro de C#
Roslyn: el futuro de C#Roslyn: el futuro de C#
Roslyn: el futuro de C#
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
 
Example for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfExample for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdf
 
C++ classes
C++ classesC++ classes
C++ classes
 
Fosdem 2011 - A Common Graph Database Access Layer for .Net and Mono
Fosdem 2011 - A Common Graph Database Access Layer for .Net and MonoFosdem 2011 - A Common Graph Database Access Layer for .Net and Mono
Fosdem 2011 - A Common Graph Database Access Layer for .Net and Mono
 
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxCSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 

Más de Michele Orselli

Más de Michele Orselli (20)

Tackling Tech Debt with Rector
Tackling Tech Debt with RectorTackling Tech Debt with Rector
Tackling Tech Debt with Rector
 
Comunicare, condividere e mantenere decisioni architetturali nei team di svil...
Comunicare, condividere e mantenere decisioni architetturali nei team di svil...Comunicare, condividere e mantenere decisioni architetturali nei team di svil...
Comunicare, condividere e mantenere decisioni architetturali nei team di svil...
 
A dive into Symfony 4
A dive into Symfony 4A dive into Symfony 4
A dive into Symfony 4
 
A recommendation engine for your applications codemotion ams
A recommendation engine for your applications codemotion amsA recommendation engine for your applications codemotion ams
A recommendation engine for your applications codemotion ams
 
A recommendation engine for your applications phpday
A recommendation engine for your applications phpdayA recommendation engine for your applications phpday
A recommendation engine for your applications phpday
 
Hopping in clouds - phpuk 17
Hopping in clouds - phpuk 17Hopping in clouds - phpuk 17
Hopping in clouds - phpuk 17
 
A recommendation engine for your php application
A recommendation engine for your php applicationA recommendation engine for your php application
A recommendation engine for your php application
 
Symfony e micro (non così tanto) services
Symfony e micro (non così tanto) servicesSymfony e micro (non così tanto) services
Symfony e micro (non così tanto) services
 
Hopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to anotherHopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to another
 
Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)
 
Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))
 
Migrare a Symfony 3
Migrare a Symfony 3Migrare a Symfony 3
Migrare a Symfony 3
 
Vagrant for real
Vagrant for realVagrant for real
Vagrant for real
 
Implementing data sync apis for mibile apps @cloudconf
Implementing data sync apis for mibile apps @cloudconfImplementing data sync apis for mibile apps @cloudconf
Implementing data sync apis for mibile apps @cloudconf
 
Server side data sync for mobile apps with silex
Server side data sync for mobile apps with silexServer side data sync for mobile apps with silex
Server side data sync for mobile apps with silex
 
Deploy a PHP App on Google App Engine
Deploy a PHP App on Google App EngineDeploy a PHP App on Google App Engine
Deploy a PHP App on Google App Engine
 
Implementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile AppsImplementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile Apps
 
Deploy a php app on Google App Engine
Deploy a php app on Google App EngineDeploy a php app on Google App Engine
Deploy a php app on Google App Engine
 
Sf2 wtf
Sf2 wtfSf2 wtf
Sf2 wtf
 
Manage a project portfolio
Manage a project portfolioManage a project portfolio
Manage a project portfolio
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Dica trentatrè. &lt;?php echo "33"; ?>. Controllare lo stato di salute di una applicazione con le metriche del codice

  • 1. #phpday Dica trentatrè <?php echo ’33’ ?> Controllare lo stato di salute di una applicazione con le metriche del codice Michele Orselli (@_orso_)
  • 2. #phpday Code Metrics
  • 3. Measure of some property of a piece #phpday of software (Wikipedia)
  • 4. #phpday Who Cares?
  • 5. #phpday How long will it take to add feature X?
  • 6. #phpday Internal vs External Quality
  • 7. Code Metrics as a mean to expose #phpday internal quality
  • 8. #phpday How long will it take to add feature X?
  • 9. #phpday Classic
  • 10. Lines and Numbers Lines LOC: Lines Of Code #phpday ELOC: Executable LOC CLOC: Comment LOC NCLOC: Non-Comment LOC Numbers NOC: Number Of Classes NOM: Number Of Methods NOP: Number Of Packages
  • 11. Lines and Numbers 1 <?php 2 Lines 3 namespace shapestwodimensional; 4 5 abstract class shape { 6 /* Returns the area of the shape */ #phpday 7 abstract function area(); 8 } 9 10 class circle extends shape { 11 public function area() {} 12 13 /* Ret the diameter of the circle */ Numbers 14 public function diameter() {} 15 } 16 17 class triangle extends shape { 18 19 public function area() {} 20 } 21 22 ?>
  • 12. Lines and Numbers 1 <?php 2 Lines 3 namespace shapestwodimensional; 4 LOC 22 5 abstract class shape { 6 /* Returns the area of the shape */ #phpday 7 abstract function area(); 8 } 9 10 class circle extends shape { 11 public function area() {} 12 13 /* Ret the diameter of the circle */ Numbers 14 public function diameter() {} 15 } 16 17 class triangle extends shape { 18 19 public function area() {} 20 } 21 22 ?>
  • 13. Lines and Numbers 1 <?php 2 Lines 3 namespace shapestwodimensional; 4 LOC 22 5 abstract class shape { 6 /* Returns the area of the shape */ #phpday CLOC 2 7 abstract function area(); 8 } 9 10 class circle extends shape { 11 public function area() {} 12 13 /* Ret the diameter of the circle */ Numbers 14 public function diameter() {} 15 } 16 17 class triangle extends shape { 18 19 public function area() {} 20 } 21 22 ?>
  • 14. Lines and Numbers 1 <?php 2 Lines 3 namespace shapestwodimensional; 4 LOC 22 5 abstract class shape { 6 /* Returns the area of the shape */ #phpday CLOC 2 7 abstract function area(); 8 } NCLOC 20 9 10 class circle extends shape { 11 public function area() {} 12 13 /* Ret the diameter of the circle */ Numbers 14 public function diameter() {} 15 } 16 17 class triangle extends shape { 18 19 public function area() {} 20 } 21 22 ?>
  • 15. Lines and Numbers 1 <?php 2 Lines 3 namespace shapestwodimensional; 4 LOC 22 5 abstract class shape { 6 /* Returns the area of the shape */ #phpday CLOC 2 7 abstract function area(); 8 } NCLOC 20 9 10 class circle extends shape { ELOC 3 11 public function area() {} 12 13 /* Ret the diameter of the circle */ Numbers 14 public function diameter() {} 15 } 16 17 class triangle extends shape { 18 19 public function area() {} 20 } 21 22 ?>
  • 16. Lines and Numbers 1 <?php 2 Lines 3 namespace shapestwodimensional; 4 LOC 22 5 abstract class shape { 6 /* Returns the area of the shape */ #phpday CLOC 2 7 abstract function area(); 8 } NCLOC 20 9 10 class circle extends shape { ELOC 3 11 public function area() {} 12 13 /* Ret the diameter of the circle */ Numbers 14 public function diameter() {} 15 } NOP 1 16 17 class triangle extends shape { 18 19 public function area() {} 20 } 21 22 ?>
  • 17. Lines and Numbers 1 <?php 2 Lines 3 namespace shapestwodimensional; 4 LOC 22 5 abstract class shape { 6 /* Returns the area of the shape */ #phpday CLOC 2 7 abstract function area(); 8 } NCLOC 20 9 10 class circle extends shape { ELOC 3 11 public function area() {} 12 13 /* Ret the diameter of the circle */ Numbers 14 public function diameter() {} 15 } NOP 1 16 17 class triangle extends shape { NOC 3 18 19 public function area() {} 20 } 21 22 ?>
  • 18. Lines and Numbers 1 <?php 2 Lines 3 namespace shapestwodimensional; 4 LOC 22 5 abstract class shape { 6 /* Returns the area of the shape */ #phpday CLOC 2 7 abstract function area(); 8 } NCLOC 20 9 10 class circle extends shape { ELOC 3 11 public function area() {} 12 13 /* Ret the diameter of the circle */ Numbers 14 public function diameter() {} 15 } NOP 1 16 17 class triangle extends shape { NOC 3 18 19 public function area() {} NOM 4 20 } 21 22 ?>
  • 19. #phpday phploc http://sebastianbergmann.github.com/phploc/
  • 21. #phpday Complexity
  • 22. Complexity #phpday Control Structures Complexity if, elseif, for, while, foreach, catch, case, xor, and, or, &&, ||, ?: Ciclomatic Complexity (CCN) NPath Complexity
  • 23. Ciclomatic Complexity 1 <?php 2 # decision points 3 class polygon { 4 5 public function perimeter() 6 { #phpday CCN 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 24. Ciclomatic Complexity 1 <?php 2 # decision points 3 class polygon { 4 5 public function perimeter() 6 { #phpday CCN 1 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 25. Ciclomatic Complexity 1 <?php 2 # decision points 3 class polygon { 4 5 public function perimeter() 6 { #phpday CCN 2 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 26. Ciclomatic Complexity 1 <?php 2 # decision points 3 class polygon { 4 5 public function perimeter() 6 { #phpday CCN 3 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 27. Ciclomatic Complexity 1 <?php 2 # decision points 3 class polygon { 4 5 public function perimeter() 6 { #phpday CCN 4 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 28. CCN Range Values #phpday 1 - 4: low 5-7: medium 8-10: high 11+: wtf
  • 29. NPath Complexity 1 <?php 2 # acyclic paths 3 class polygon { 4 5 public function perimeter() 6 { #phpday NPath 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 30. NPath Complexity 1 <?php 2 # acyclic paths 3 class polygon { 4 5 public function perimeter() 6 { #phpday NPath 1 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 31. NPath Complexity 1 <?php 2 # acyclic paths 3 class polygon { 4 5 public function perimeter() 6 { #phpday NPath 2 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 32. NPath Complexity 1 <?php 2 # acyclic paths 3 class polygon { 4 5 public function perimeter() 6 { #phpday NPath 3 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 33. NPath Complexity 1 <?php 2 # acyclic paths 3 class polygon { 4 5 public function perimeter() 6 { #phpday NPath 4 7 if (!is_array($this->vertices)) { 8 return false; 9 } 10 11 $perimeter = 0; 12 13 foreach ($this->vertices as $vertex) { 14 $perimenter += $vertex; 15 } 16 17 return $perimeter; 18 } 19 } 20 ?>
  • 34. NPath Treshold #phpday Critical if > 200
  • 35. #phpday PHP Depend http://pdepend.org
  • 38. #phpday OO Metrics
  • 39. Afferent/Efferent Coupling #phpday Ca: no. of unique incoming dependencies Ce: no. of unique outgoing dependencies
  • 40. Afferent/Efferent Coupling Shape area() #phpday Circle Triangle area() area() Math PI
  • 41. Afferent/Efferent Coupling Shape area() #phpday Circle Triangle area() area() Math Ca: 1 PI Ce: 0
  • 42. Afferent/Efferent Coupling Shape area() #phpday Ca: 0 Circle Triangle Ce: 2 area() area() Math Ca: 1 PI Ce: 0
  • 43. Afferent/Efferent Coupling Shape Ca: 2 area() Ce: 0 #phpday Ca: 1 Circle Triangle Ce: 1 area() area() Math Ca: 1 PI Ce: 0
  • 44. Afferent/Efferent Coupling Shape Ca: 2 area() Ce: 0 #phpday Ca: 1 Circle Triangle Ca: 0 Ce: 1 area() area() Ce: 1 Math Ca: 1 PI Ce: 0
  • 45. #phpday $ pdepend --jdepend-chart=j.png .
  • 46. Instability Chart #phpday A = AC / (CC + AC) D = | A + I | -1 I = Ce / (Ce + Ca)
  • 47. #phpday PHP MD http://phpmd.org
  • 48. PHP MD #phpday Code Size Rules Design Rules Naming Rules Unused Code Rules
  • 49. #phpday $ phpmd src/ xml codesize,design,naming,unusedcode -- reportfile pmd.xml
  • 51. #phpday Non Static Analysis
  • 52. C.R.A.P Change Risk Analysis Predictions or #phpday “Your code is crap” CRAP = CCN^2 * (1 – COV/100)^3 + CCN
  • 53. #phpday Putting it all together
  • 54. #phpday PHP_CodeBrowser https://github.com/mayflowergmbh/PHP_CodeBrowser.git
  • 55. $ phpcb --log logs --source src --output #phpday code-browser
  • 56. #phpday PHP Project Wizard https://github.com/sebastianbergmann/php-project-wizard.git
  • 57. Code Metrics as a mean to expose #phpday internal quality
  • 58. Further Reading http://manuel-pichler.de/ #phpday http://pdepend.org http://phpmd.org http://www.artima.com/weblogs/viewpost.jsp?thread=215899
  • 59. Questions? @_orso_ #phpday mo@ideato.it http://joind.in/2989

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n