SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances (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
 

En vedette

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
 

En vedette (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?
 

Similaire à 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
 

Similaire à 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++
 

Plus de Michele Orselli

Plus 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
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

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

Notes de l'éditeur

  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