Code analysis tools
Tools that we consider • PHP Copy/Paste Detector • PHP Mess Detector • PHP_CodeSniffer • PHP Depend
PHP Copy/Paste Detector Allows to search for duplicate source code fragments in projects. Usage example:
PHP Mess Detector Takes a given PHP source code base and look for several potential problems within that source. These problems can be things like: • Possible bugs • Suboptimal code • Over complicated expressions • Unused parameters, methods, properties
PHP Mess Detector (cont.) PHPMD uses so called rule sets that configure/define a set of rules which will be applied against the source under test. It only provides a set of predefined rules. List of rule sets: • Code size rules • Controversial rules • Design rules • Naming rules
PHP Mess Detector (cont.) Usage example: You can pass a filename or a directory name containing PHP source code to PHPMD.
PHP_CodeSniffer PHP5 script that tokenizes and "sniffs" PHP, Javascript and CSS files to detect violations of a defined coding standard. A coding standard in PHP_CodeSniffer is a collection of sniff files. Each sniff file checks one part of the coding standard only. The default coding standard used by PHP_CodeSniffer is the PEAR coding standard.
PHP_CodeSniffer (cont.) Sample PHP_CodeSniffer output:
PHP_CodeSniffer (cont.) Sample PHP_CodeSniffer full report with source codes: Both the full and summary reports can additionally show information about the source of errors and warnings.
PHP_CodeSniffer (cont.) Sample PHP_CodeSniffer summary report with source codes:
PHP Depend A small program that performs static code analysis on a given code base. Static code analysis: • takes the source code and parses it into an easily processable internal data structure (Abstract Syntax Tree) • takes the generated AST and measures several values, the so called software metrics Software metrics are the sum of some statements or code fragments found in the analyzed source.
PHP Depend (cont.) Usage example: This command has produced one xml-report named summary.xml that contains a summary of all metrics collected for the analyzed php source code.
PHP Depend (cont.) XML Report (summary.xml):
PHP Depend (cont.) Shows the inter package Shows a visual summary of the dependencies analyzed project source code
Thank you! by Karlen Kishmiryan (Sourcio CJSC)

Code analysis tools (for PHP)

  • 1.
  • 2.
    Tools that weconsider • PHP Copy/Paste Detector • PHP Mess Detector • PHP_CodeSniffer • PHP Depend
  • 3.
    PHP Copy/Paste Detector Allowsto search for duplicate source code fragments in projects. Usage example:
  • 4.
    PHP Mess Detector Takesa given PHP source code base and look for several potential problems within that source. These problems can be things like: • Possible bugs • Suboptimal code • Over complicated expressions • Unused parameters, methods, properties
  • 5.
    PHP Mess Detector(cont.) PHPMD uses so called rule sets that configure/define a set of rules which will be applied against the source under test. It only provides a set of predefined rules. List of rule sets: • Code size rules • Controversial rules • Design rules • Naming rules
  • 6.
    PHP Mess Detector(cont.) Usage example: You can pass a filename or a directory name containing PHP source code to PHPMD.
  • 7.
    PHP_CodeSniffer PHP5 script thattokenizes and "sniffs" PHP, Javascript and CSS files to detect violations of a defined coding standard. A coding standard in PHP_CodeSniffer is a collection of sniff files. Each sniff file checks one part of the coding standard only. The default coding standard used by PHP_CodeSniffer is the PEAR coding standard.
  • 8.
  • 9.
    PHP_CodeSniffer (cont.) Sample PHP_CodeSnifferfull report with source codes: Both the full and summary reports can additionally show information about the source of errors and warnings.
  • 10.
    PHP_CodeSniffer (cont.) Sample PHP_CodeSniffersummary report with source codes:
  • 11.
    PHP Depend A smallprogram that performs static code analysis on a given code base. Static code analysis: • takes the source code and parses it into an easily processable internal data structure (Abstract Syntax Tree) • takes the generated AST and measures several values, the so called software metrics Software metrics are the sum of some statements or code fragments found in the analyzed source.
  • 12.
    PHP Depend (cont.) Usage example: This command has produced one xml-report named summary.xml that contains a summary of all metrics collected for the analyzed php source code.
  • 13.
    PHP Depend (cont.) XMLReport (summary.xml):
  • 14.
    PHP Depend (cont.) Showsthe inter package Shows a visual summary of the dependencies analyzed project source code
  • 15.
    Thank you! by Karlen Kishmiryan (Sourcio CJSC)