← 返回命令列表

Linux command

psalm 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Analyze project

psalm

Analyze with specific level

psalm --level=[5]

Analyze specific file

psalm [src/File.php]

Initialize configuration

psalm --init

Generate baseline

psalm --set-baseline=[baseline.xml]

Show info-level issues

psalm --show-info=true

Output as JSON

psalm --output-format=json

Analyze only changed files

psalm --diff

Run security taint analysis

psalm --taint-analysis

Fix issues automatically

psalm --alter --issues=[MissingReturnType]

说明

psalm is a static analysis tool for PHP that finds bugs and enforces type safety. It understands PHP type hints and PHPDoc annotations. Error levels range from 1 (strictest) to 9 (most permissive). Higher levels allow more potential issues, suitable for legacy codebases. Configuration in psalm.xml defines analysis scope, excluded files, and issue severity. Project-specific settings enable gradual adoption. Baselines record existing issues to ignore. New code must pass analysis while legacy problems can be addressed over time. The alter mode automatically fixes certain issues like adding return types or parameter types. This accelerates migration to stricter typing. Psalm understands complex PHP patterns including generics, union types, and template types through PHPDoc syntax.

参数

--level _N_
Error level (1-9, where 1 is strictest).
--config, -c _FILE_
Configuration file.
--init
Initialize psalm.xml.
--set-baseline _FILE_
Generate baseline file.
--use-baseline _FILE_
Use baseline file.
--ignore-baseline
Ignore baseline.
--show-info
Show info-level issues.
--output-format _FMT_
Output format (console, json, xml, etc.).
--alter
Modify files to fix issues.
--issues _LIST_
Issues to fix with --alter.
--threads _N_
Parallel analysis threads.
--memory-limit _SIZE_
Memory limit.
--diff
Only analyze files changed since last run.
--taint-analysis
Enable taint analysis to detect security vulnerabilities in data flow.
--clear-cache
Clear cache.
--stats
Show type coverage statistics.

FAQ

What is the psalm command used for?

psalm is a static analysis tool for PHP that finds bugs and enforces type safety. It understands PHP type hints and PHPDoc annotations. Error levels range from 1 (strictest) to 9 (most permissive). Higher levels allow more potential issues, suitable for legacy codebases. Configuration in psalm.xml defines analysis scope, excluded files, and issue severity. Project-specific settings enable gradual adoption. Baselines record existing issues to ignore. New code must pass analysis while legacy problems can be addressed over time. The alter mode automatically fixes certain issues like adding return types or parameter types. This accelerates migration to stricter typing. Psalm understands complex PHP patterns including generics, union types, and template types through PHPDoc syntax.

How do I run a basic psalm example?

Run `psalm` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --level _N_ do in psalm?

Error level (1-9, where 1 is strictest).