Giter VIP home page Giter VIP logo

php-analyzer's Introduction

PHP-Analzyer

Homepage: https://github.com/mfn/php-analyzer

Blurb

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

Install

Via composer:

composer require mfn/php-analyzer 0.0.1

Usage

A command line tool is provided: php_analyzer.php analyze <files or dirs>

See the --help switch for more details.

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.

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 blocks

Learn more:

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:

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 <file> option.

The file is a plain PHP file simply returning an array of analyzers you want to run. See 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

© Markus Fischer [email protected]

php-analyzer's People

Contributors

mfn avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.