2017 © Pedro Peláez
 

ibrary php-analyzer

Framework for performaing static PHP code analysis

image

mfn/php-analyzer

Framework for performaing static PHP code analysis

  • Sunday, February 1, 2015
  • by mfn
  • Repository
  • 1 Watchers
  • 1 Stars
  • 20 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

PHP-Analzyer

Homepage: https://github.com/mfn/php-analyzer, (*1)

Blurb

A framework for performing static PHP source analysis. The modular concept hands analysis over to Analyzers which report back any possible warnings/errors., (*2)

Install

Via composer:, (*3)

composer require mfn/php-analyzer 0.0.1

Usage

A command line tool is provided: php_analyzer.php analyze <files or dirs>, (*4)

See the --help switch for more details., (*5)

What analysis is performed?

All files are run through the nikic/PHP-Parser and after that an internal graph of the classes/interfaces is built., (*6)

All analyzers available are run against the sources reports are generated., (*7)

The following analysis is currently performed: - detection of missing method implementations of abstract classes - detecting of missing method implementations of interfaces - incompatibility of methods declared in interfaces - methods defined abstract on an interface
Probably a bit pointless because the php linter detects this. - warns when using dynamic class instantiation, i.e. new $foo - warns when encountering empty exception catch blocks, (*8)

Learn more: - The architecture of the Framework itself - Documentations of all Analyzers - Default Analyzer configuration, (*9)

Graphviz

The internal ObjectGraph lends itself to generate a class relationship diagram for which a graphviz generator exists. This will produce a .dot file which can be further used with the Graphviz package to generate graphics from it:, (*10)

php_analyzer.php graphviz yoursource/ > myproject.dot, (*11)

See --help for more options., (*12)

To convert this to e.g. png the aforementioned graphviz package has to be installed on your system. This includes the dot command which can be used to generate a PNG file:, (*13)

dot -Tpng myproject.dot > myproject.png, (*14)

Configuration

If you want to use a differnet set of analyzers or you've written your own and want to use them, you can use the --config <file> option., (*15)

The file is a plain PHP file simply returning an array of analyzers you want to run. See res/defaultAnalyzerConfiguration.php for an example., (*16)

TODOs / Ideas

  • the analyzers depending on the graph have no logic whether they've visited a node already or not; thus visiting the same nodes/methods multiple times
  • Use namespacedName property generated by \PhpParser\NodeVisitor\NameResolver
  • Add support for traits

Contribution

  • one feature per branch/PR
  • coding standard is PSR-2

© Markus Fischer markus@fischer.name, (*17)

The Versions

01/02 2015

dev-master

9999999-dev http://github.com/mfn/php-analyzer

Framework for performaing static PHP code analysis

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus Fischer

code analysis source

01/02 2015

v0.0.2

0.0.2.0 http://github.com/mfn/php-analyzer

Framework for performaing static PHP code analysis

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus Fischer

code analysis source

01/02 2015

v0.0.1

0.0.1.0 http://github.com/mfn/php-analyzer

Framework for performaing static PHP code analysis

  Sources   Download

MIT

The Requires

 

The Development Requires

by Markus Fischer

code analysis source