phan
Analyze PHP code for errors
TLDR
Generate a .phan/config.php in the current directory
Generate a Phan configuration file using a specific level (1 being strictest to 5 being the least strict)
Analyze the current directory
Analyze one or more directories
Specify a configuration file (defaults to .phan/config.php)
Specify the output mode
Specify the number of parallel processes
SYNOPSIS
vendor/bin/phan [options]
php phan.phar [options]
(Note: Specific options and arguments are often managed via a .phan/config.php file.)
PARAMETERS
--help
Displays detailed help information about available options and usage.--version
Shows the installed Phan version.--config-file <path>
Specifies an alternative path to the Phan configuration file (default is .phan/config.php
).--project-root <path>
Defines the root directory of the PHP project being analyzed. Affects relative path resolution.--analyze-directory <path>
Adds a specific directory to the list of paths to be analyzed, overriding configuration settings.--exclude-directory <path>
Excludes a specific directory from analysis, overriding configuration settings.--output <file>
Redirects analysis results to a specified file instead of standard output.--progress-bar
Displays a progress bar during the analysis process.--color
Enables colorized output for better readability of warnings and errors.
DESCRIPTION
Phan is a powerful static analyzer for PHP that aims to find common errors and suggest improvements in codebases without executing them. It identifies various issues such as undefined variables, inaccessible code, type mismatches, and incorrect function or method calls. While not a standard core Linux utility, Phan is widely used by PHP developers on Linux environments to enhance code quality, enforce type safety, and minimize runtime errors. It's often integrated into Continuous Integration (CI) pipelines for automated code quality checks. Phan is highly configurable, allowing users to define strictness levels, custom analysis plugins, and integrate seamlessly with existing PHP ecosystems. It is typically invoked via Composer's `vendor/bin/phan` executable or a standalone `phan.phar` file.
CAVEATS
Phan is a PHP static analyzer, not a core Linux system utility. It requires a PHP environment and typically Composer for installation. Its effectiveness depends heavily on correct configuration and the quality of type hints in the PHP codebase. As a static analyzer, it may occasionally produce false positives or false negatives.
CONFIGURATION
Phan's primary configuration is managed via a .phan/config.php
file, typically located in the project root. This file offers extensive control over analysis levels, plugin usage, directory inclusions/exclusions, and custom stub definitions, significantly reducing the need for complex command-line arguments and ensuring consistent analysis settings across a project.
INTEGRATION
Phan is commonly integrated into Continuous Integration (CI) pipelines (e.g., GitHub Actions, GitLab CI, Jenkins). This automation ensures that code quality checks are performed on every commit or pull request, preventing potential issues from being merged into the main codebase and maintaining high development standards.
HISTORY
Phan was initially created by Rasmus Schultz, with development beginning around 2016. It emerged as a response to the growing demand for robust static analysis in modern PHP development, particularly with the introduction of stricter type declarations in PHP 7 and beyond. It quickly gained traction for its deep analysis capabilities and extensible plugin system, becoming a significant tool in the PHP ecosystem for improving code quality and catching errors early in the development lifecycle.
SEE ALSO
php(1), composer(1), php-cs-fixer(1), psalm(1), phpstan(1)