phploc
Analyze PHP code size and structure
TLDR
Analyze a directory and print the result
Include only specific files from a comma-separated list (globs are allowed)
Exclude specific files from a comma-separated list (globs are allowed)
Exclude a specific directory from analysis
Log the results to a specific CSV file
Log the results to a specific XML file
Count PHPUnit test case classes and test methods
SYNOPSIS
phploc [options] <path> [<path> ...]
PARAMETERS
--help -h
Display help message.
--quiet -q
Do not output any message.
--version -V
Display application version.
--ansi
Force ANSI output.
--no-ansi
Disable ANSI output.
--no-interaction -n
Do not ask interactive questions.
--profile
Display timing and memory usage.
--verbose -v|-vv|-vvv
Increase verbosity level.
--configuration=
Read configuration from file.
--count-tests
Include test code in analysis.
--names=
Use custom names from file.
--no-configuration
Ignore default config file.
--progress[=<type>]
Show progress bar.
--no-progress
Disable progress output.
--log-json=<file>
Log JSON report to file.
--log-xml=<file>
Log XML report to file.
--log-csv=<file>
Log CSV report to file.
--log-html=<file>
Log HTML report to file.
DESCRIPTION
phploc is a command-line tool designed to analyze PHP codebases, providing metrics on project size, structure, and complexity. It recursively scans specified directories or files, counting lines of code (physical, logical, executable), comments, blanks, namespaces, interfaces, traits, classes, abstract classes, methods, functions, and more.
It calculates key metrics like average lines per method, cyclomatic complexity (minimum, average, maximum), and lack of cohesion in methods (LCOM). Output is a formatted console report, with options for JSON, XML, CSV, or HTML logs. Ideal for code audits, CI/CD pipelines, and maintaining code quality in PHP projects. Supports modern PHP features and can optionally include test code in analysis.
CAVEATS
Analyzes only PHP files (.php, .php5, .phtml, .inc); requires PHP ≥7.3. Ignores non-PHP files and vendor dirs by default in configs. Not suitable for runtime analysis.
INSTALLATION
Install via Composer: composer global require phploc/phploc. Add ~/.composer/vendor/bin to PATH.
Usage: phploc src tests.
OUTPUT EXAMPLE
Console shows tables with directories, volumes, complexity, hierarchies, etc. Logs enable parsing in tools like Jenkins.
HISTORY
Developed by Sebastian Bergmann, first released in 2011 as part of PHP QA tools. Evolved to support PHP 8+, integrated into CI workflows. Maintained on GitHub; version 10+ focuses on modern metrics.


