https://github.com/mfn/php-analyzer
Framework for performaing static PHP code analysis
https://github.com/mfn/php-analyzer
Last synced: 2 months ago
JSON representation
Framework for performaing static PHP code analysis
- Host: GitHub
- URL: https://github.com/mfn/php-analyzer
- Owner: mfn
- License: mit
- Created: 2014-10-26T15:28:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-11-25T11:53:28.000Z (over 6 years ago)
- Last Synced: 2025-01-23T21:31:21.383Z (4 months ago)
- Language: PHP
- Size: 200 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# PHP-Analzyer
Homepage: https://github.com/mfn/php-analyzer
## Blurb
A [framework](doc/framework.md) for performing static PHP source analysis.
The modular concept hands analysis over to [Analyzers](doc/analyzers.md) which
report back any possible warnings/errors.## Install
Via [composer](https://getcomposer.org):
```
composer require mfn/php-analyzer 0.0.1
```## Usage
A command line tool is provided: `php_analyzer.php analyze `
See the `--help` switch for more details.
# What analysis is performed?
All files are run through the [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser)
and after that an internal graph of the classes/interfaces is built.All analyzers available are run against the sources reports are generated.
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 blocksLearn more:
- [The architecture of the Framework itself](doc/framework.md)
- [Documentations of all Analyzers](doc/analyzers.md)
- [Default Analyzer configuration](res/defaultAnalyzerConfiguration.php)## Graphviz
The internal [ObjectGraph](lib/Analyzers/ObjectGraph/ObjectGraph.php) 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](http://www.graphviz.org/) package to generate graphics from it:`php_analyzer.php graphviz yoursource/ > myproject.dot`
See `--help` for more options.
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:`dot -Tpng myproject.dot > myproject.png`
## 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 ` option.The file is a plain PHP file simply returning an array of analyzers you want to
run. See [res/defaultAnalyzerConfiguration.php](res/defaultAnalyzerConfiguration.php)
for an example.# 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](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)© Markus Fischer