January 6 Johannes Schmitt schmittjoh

New Major Version of PHP Analyzer available

We are very excited to announce the availability of a new major version of PHP Analyzer. If you haven’t heard of PHP Analyzer yet, it is an advanced static analysis tool for PHP code; much like a compiler for PHP, except that it does not transform your source code, but analyzes it.

Faster Type Inference Engine

Before PHP Analyzer runs its bug detection routines and other heuristics, it first performs several flow analyses on your source code to get a better picture of what it does and how data is passed through it. One of these flow analyses is type inference. Our type inference engine had been growing over time as we added new features to make it more accurate. As the architecture was not planned for these new features, the speed of the engine suffered over time.

This new version contains rewritten internals which show speed improvements by 10 to 20 times or even more depending on the analyzed package. Just as an example, analyzing the latest version of the Symfony framework went down from something over an hour to a mere 3 to 4 minutes!

Better Caching & Logging

Since PHP Analyzer is implemented in PHP itself, and PHP is single-threaded, that inherently puts a speed limit on a CPU-intensive tool like PHP Analyzer. To still make inspections as fast as possible, the process of analyzing dependencies of your root package is distributed across several machines and done in parallel whenever possible.

These results are then cached in a persistent storage for subsequent runs and only analyzed again if their versions change. This process is now also nicely displayed in your inspection progress log:

PHP Analyzer Dependency Builds
Note: Currently, we require that the composer.lock file is committed to your repository. You can read more about this in the documentation.

More Checks

Last but not least, this new version also comes with a couple of new checks. An in-depth view will follow over the next days and weeks, here a short summary of things that have changed:

  • Better consideration of doc comments for type inference
  • Full trait support
  • More unused code detection (like parameters)
  • Checks for usage of deprecated code
  • Detection of useless/side-effect-free code
  • Automated fixes for doc comments
  • Analysis of coupling and cohesion of classes
  • Some library specific checks for PHPUnit/Doctrine/Symfony2

How to enable

You can enable PHP Analyzer on your project by adding the following to your configuration:

# .scrutinizer.yml
tools:
    php_analyzer: true

Currently, PHP Analyzer is available for all paid plans and we also started to make it available to a few hundred of the thousands of open-source repositories on Scrutinizer. We will gradually enable it for more open-source repositories as we get a better idea of the necessary capacities.

If you’d like to get access earlier, you can join us on #scrutinizer on Freenode IRC and we might be able to squeeze you in. At any rate, if you enabled PHP Analyzer in your configuration, you will get an email once it becomes available for your repository.

Help us spread the word, and a happy new year!

 

Have Feedback? Tweet to @scrutinizerci

If you experienced a bug or have any questions, please send them to [email protected].