Writing quality code and code analysis

Beside writing tests, there are more factors that affect the quality of your code. Let’s check some tools for PHP that can improve your code quality.

PhpMetrics

PhpMetrics

PhpMetrics is a very convenient static analysis tool for your code and your PHP projects.

It can be installed with Composer or by downloading phar:

composer global require 'halleck45/phpmetrics'
phpmetrics --report-html=myreport.html /path/of/your/sources

PhpMetrics can even interact with Jenkins and Sonar.

After running PhpMetrics from terminal you get an HTML file that looks something like this:

PhpMetrics Report

Some examples of PhpMetrics reports:

See also

Other useful tools to check out:

  • PHP Parser - This is a PHP 5.2 to PHP 7.1 parser written in PHP. Its purpose is to simplify static code analysis and manipulation.
  • PHP QA tools - List of PHP Quality Assurance tools
  • Jenkins PHP - Template for Jenkins Jobs for PHP Projects
  • PHP Mess Detector - User friendly and easy to configure frontend for the raw metrics measured by PHP Depend
  • PHPCheckStyle - open-source tool that helps PHP programmers adhere to certain coding conventions
  • Qafoo Quality Analyzer - Tool helping us to analyze software projects.
  • SensioLabsInsight - A quick way to run over 100 quality tests on your code (free version available).