phpstan
Analyze PHP code for errors
TLDR
Analyze one or more directories
Analyze a directory using a configuration file
Analyze using a specific rule level (0-10, higher is stricter)
Specify an autoload file to load before analyzing
Specify a memory limit during analysis
Display available options for analysis
SYNOPSIS
phpstan [command] [options]
PARAMETERS
analyse
Analyzes the given paths. Paths can be files or directories.
--level
Sets the level of analysis (0-9, higher is stricter). Defaults to 0.
--configuration
Path to the configuration file (phpstan.neon or phpstan.neon.dist).
--autoload-file
Path to a custom autoload file.
--memory-limit
Sets the memory limit for PHP.
--error-format
Specifies the format of the output (table, raw, json, checkstyle).
--no-progress
Hides the progress bar.
--debug
Enables debug mode.
--version
Displays the PHPStan version.
--help
Displays help information.
DESCRIPTION
PHPStan is a static analysis tool for PHP. It focuses on finding errors in your code without actually running it. It catches whole classes of bugs early in the development cycle, improving code quality and preventing runtime issues. PHPStan analyzes your code and reports issues such as undefined variables, incorrect method calls, type mismatches, and dead code. It helps developers write more robust and maintainable PHP applications by identifying potential problems before they reach production. PHPStan supports a wide range of PHP features and coding standards, making it a valuable tool for any PHP project. The level of analysis can be configured to progressively stricter rules, enabling a gradual adoption and providing tailored feedback.
CAVEATS
PHPStan relies on static analysis and cannot detect all possible runtime errors. Code that uses dynamic features extensively might not be fully analyzed.
CONFIGURATION
PHPStan can be configured using a `phpstan.neon` or `phpstan.neon.dist` file. This file allows you to customize the analysis level, specify paths to exclude, define custom rules, and more. Refer to the PHPStan documentation for details on configuration options.
RULE DEFINITION
Custom rules can be created to enforce project-specific coding standards or detect particular patterns. This allows developers to extend PHPStan's capabilities to meet unique project requirements.