Static analyzer tool for PHP : Coupling, Cyclomatic complexity, Maintainability Index, Halstead's metrics... and more !

Installs: 4 195 890

Dependents: 256

Suggesters: 2

Security: 0

Stars: 2 158

Watchers: 80

Forks: 247


License Build Status Latest Stable Version Slack

Standard report


PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report.

Documentation | Twitter | Contributing

Quick start

composer require phpmetrics/phpmetrics --dev
php ./vendor/bin/phpmetrics --report-html=myreport <folder-to-analyze>

Then open the generated ./myreport/index.html file in your browser.


Use the --config=<file>.json option. For example:

    "includes": [   // directory and files to analyze, relative to config file directory 
    "exclude": [    // regex of files (or directory) to exclude from analyze
    "report": {     // list of reports to generate (html, json, csv or violation)
        "html": "/tmp/report/",             // destination directory of HTML report 
        "csv": "/tmp/report.csv",           // destination file for CSV report
        "json": "/tmp/report.json",         // destination file for JSON report
        "violations": "/tmp/violations.xml" // destination file for XML violations report
    "groups": [     // "layers" of code. You can group your classes and packages by regex, 
                    // to visualise specific HTML report for each of them
            "name": "Component",      // name of the layer
            "match": "!component!i"   // regular expression used to match the group (based on 
                                      // the name of the fully qualified class name)
                                      // remember to double escape (for json, then for regex): 
                                      // set "!\\\\MyPackage\\\\!" if you want to capture  
                                      // expression "\MyPackage\"
            "name": "Example",
            "match": "!example!"
    "plugins": {
        "git": {
            "binary": "git"           // if defined, runs git analyze
        "junit": {
            "file": "/tmp/junit.xml"  // if defined, JUnit report file will be analyzed            
    "extensions": [ "php", "php8" ]   // default: ["php", "inc"]


If want, you can install PhpMetrics globally with your favorite package manager (APT, Brew...). You can also visit our documentation.

Metrics list

See the metrics file.



See the LICENSE file.


See the CONTRIBUTING file.