Linux command
phpstan 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Analyze source directory
phpstan analyse [src/]
Analyze with specific level
phpstan analyse --level [5] [src/]
Analyze using config file
phpstan analyse -c [phpstan.neon]
Analyze with max level
phpstan analyse --level max [src/]
Generate baseline
phpstan analyse --generate-baseline
Clear cache
phpstan clear-result-cache
Show version
phpstan --version
说明
phpstan performs static analysis on PHP code, finding bugs without running the code. It catches type errors, undefined methods, and incorrect function calls. Analysis levels range from 0 (basic) to 9 (strictest). Higher levels check more conditions but may find more false positives in legacy code. Start low and increase gradually. Configuration files (phpstan.neon) define paths, excludes, and custom rules. They enable consistent analysis across team members and CI pipelines. Baseline files ignore existing errors, enabling gradual adoption. New code must pass analysis while legacy issues can be fixed over time. The tool integrates with IDEs through plugins, showing errors as you type. CI integration catches regressions before merge. PHPStan supports PHPDoc annotations for type hints in older code. Modern PHP type declarations are preferred when possible.
参数
- analyse, analyze
- Run analysis.
- --level, -l _N_
- Rule level (0-9 or max).
- -c _FILE_
- Configuration file.
- --configuration _FILE_
- Configuration file (long form).
- --memory-limit _SIZE_
- Memory limit.
- --debug
- Debug mode.
- --generate-baseline
- Generate error baseline.
- -b _FILE_
- Baseline file.
- --error-format _FMT_
- Output format (table, json, raw, etc.).
- --no-progress
- Disable progress bar.
- clear-result-cache
- Clear analysis cache.
FAQ
What is the phpstan command used for?
phpstan performs static analysis on PHP code, finding bugs without running the code. It catches type errors, undefined methods, and incorrect function calls. Analysis levels range from 0 (basic) to 9 (strictest). Higher levels check more conditions but may find more false positives in legacy code. Start low and increase gradually. Configuration files (phpstan.neon) define paths, excludes, and custom rules. They enable consistent analysis across team members and CI pipelines. Baseline files ignore existing errors, enabling gradual adoption. New code must pass analysis while legacy issues can be fixed over time. The tool integrates with IDEs through plugins, showing errors as you type. CI integration catches regressions before merge. PHPStan supports PHPDoc annotations for type hints in older code. Modern PHP type declarations are preferred when possible.
How do I run a basic phpstan example?
Run `phpstan analyse [src/]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does analyse, analyze do in phpstan?
Run analysis.