PhpCodeArcheology is a PHP static analysis tool designed to measure code quality through more than 60 metrics, including cyclomatic complexity, cognitive complexity, maintainability index, LCOM, Halstead metrics, coupling, instability, and more. It generates comprehensive reports for files, classes, methods, and functions, detects code smells, identifies hotspots through Git change analysis, and tracks quality trends. Unlike PHPStan or Psalm, PhpCodeArcheology focuses more on architecture and maintainability, and can be seen as an alternative to PHPMetrics, offering deeper Git integration, baseline management, and AI-ready output.
Main capabilities:
- 60+ code quality metrics: Calculate cyclomatic complexity, cognitive complexity, maintainability index, LCOM, Halstead metrics, coupling, instability, and more for each file, class, and function.
- Issue detection: Built-in 14 rules, covering god classes, excessive complexity, dead code, security smells, SOLID violations, deep inheritance, low type coverage, untested complex code, and more.
- Test analysis: Automatically detect PHPUnit/Pest/Codeception, map test files to production classes, integrate Clover XML for line-level coverage, and highlight untested hotspots.
- Git integration: Change analysis, hotspot detection (high change + high complexity), author tracking.
- Source code display: View method source code directly in HTML reports, with PHP syntax highlighting and nesting depth heatmaps, visually displaying complexity hotspots.
- Multiple report formats: Interactive HTML, Markdown, JSON, SARIF (GitHub Code Scanning), AI summary, knowledge graph (JSON).
- Health score: Generate a single 0-100 score and A-F grade for the entire project.
- Technical debt score: Weighted based on issue severity, normalized per 100 logical lines of code.
- Historical tracking: Trend charts across multiple analysis runs.
- Baseline management: Track only new issues and ignore existing issues, suitable for legacy projects.
- CI/CD ready: Configurable exit codes, support for SARIF and JSON output.
- Fast mode: Terminal output only, no report generation.
- CLAUDE.md generation: Automatically generate project overviews for AI coding assistants.
- AI integration: Native MCP server, for Claude Code and other AI assisManual use.
Usage: No configuration file required, works out of the box: scans the src directory and generates an HTML report in tmp/report; open tmp/report/index.html in a browser to view it. It is recommended to add tmp/report to .gitignore. Requires PHP 8.2 or higher (supports 8.2, 8.3, 8.4, 8.5). Can be installed globally via Composer, or as a project dependency. A standalone PHAR can also be downloaded from the Releases page, suitable for dependency conflicts or legacy codebases. PhpCodeArcheology is registered as a Composer plugin, allowing analysis to be run directly through Composer. When no path is provided and there is no configuration file, it automatically detects the PSR-4 source directory from composer.json. Interactively create a configuration file: run init to generate php-codearch-config.yaml, automatically detecting common source directories. Comparison reports: the compare command shows metric differences, issue counts, and lists newly introduced/resolved issues. Baseline management: the baseline command's create saves the current issue set as a baseline, check runs a new analysis and reports only new issues, returning exit code 1 when new errors are found. Test analysis: automatically detects test infrastructure, maps test files to production classes. Per-class provides a hasTest flag and test file count; untested complex code (cyclomatic complexity >= 8 and no tests) triggers a warning; untested code serves as a driver for refactoring priorities; HTML and Markdown reports include a test page showing a coverage gap table and dashboard tiles. For Pest projects, it is recommended to generate a Clover XML report for accurate coverage. Coverage data serves as the 10th factor in the health score (weight 10%). Source display: the HTML report can embed the actual source code of methods and functions, supporting PHP syntax highlighting and nesting depth heatmaps, issue badges, and severity borders. Control the display scope via problems-only (default) or all. Knowledge graph export: the graph report type exports the codebase structure as a machine-readable knowledge graph, containing nodes, edges, clusters, and cycles arrays, for use by AI tools, graph databases, and custom visualizations. MCP server: built-in origRaw MCP server, AI assistants can directly query analysis results. It supports setup via global installation or project dependency, and a .mcp.json can be added for team sharing. Available tools include get_test_coverage, etc.; AI assistants can answer questions such as "which classes have the highest technical debt". Health score: 0-100 points, weighting 10 factors (maintainability index, issue density, complexity, coupling, code structure, HTML ratio, encapsulation, dependencies, abstraction, test coverage). The score is used to track trends rather than make absolute judgments, and should not be compared across projects. Memory and performance: automatically excludes vendor/, node_modules/, .git/. Large codebases (50,000+ files) may require more memory, and memoryLimit can be adjusted through the configuration file. Version notes: v2.7.0 fixed calculation errors that existed since earlier versions, including method-level Halstead operand tracking, duplicate counting in complexity prediction, god class false positives, etc. After upgrading, error counts will decrease significantly and health scores will improve. The HTML report template uses Tailwind CSS; the compiled output.css has been committed to the repository, so Node.js is not required. After modifying the template or CSS, it needs to be rebuilt. Version 3.0 is under development and will refactor the calculation method for relative issue thresholds, adopting robust statistical outlier detection. Contributions: contributions are welcome; check open issues or view the roadmap.
Use cases: Suitable for code quality assessment, architecture analysis, technical debt management, refactoring priority determination, legacy codebase assessment, quality gates in CI/CD integration, and codebase queries through AI assistants for PHP projects.
Limitations: Information about pricing, fees, specific platform support, effectiveness guarantees, etc. is not currently provided. The accuracy of some metrics had known issues before v2.7.0, which have been fixed.