psalm
Static analysis tool for PHP code
TLDR
Generate a Psalm configuration
Analyze the current working directory
Analyze a specific directory or file
Analyze a project with a specific configuration file
Include informational findings in the output
Analyze a project and display statistics
Analyze a project in parallel with 4 threads
SYNOPSIS
psalm [options] [files...]
Commonly invoked as vendor/bin/psalm [options] [files...] after Composer installation.
Key invocation modes include running for a full analysis, --diff for changed files, --lint for quick checks, --baseline for managing existing errors, and --alter for automatic code modifications.
PARAMETERS
--config=
Specify a custom Psalm configuration file.
--set-config=
Override specific configuration values directly.
--diff
Analyze only files that have changed since the last Git commit.
--lint
Run a quick syntax check and show errors on the console.
--output-format=
Set the output format (e.g., `text`, `json`, `xml`, `github`).
--report=
Write the analysis results to a specified file.
--issues=
Filter issues to check or ignore (e.g., `MissingReturnType,UndefinedClass`).
--show-info
Display informational messages during analysis.
--baseline[=
Create or update a baseline file to ignore existing errors.
--alter
Run code alteration plugins to fix identified issues automatically.
--threads=
Specify the number of parallel threads for analysis.
--help
Display detailed help information.
--version
Show the Psalm version.
DESCRIPTION
PSALM is a robust static analysis tool designed for PHP. It meticulously examines PHP source code without executing it, identifying potential bugs, type errors, undefined variables, and other inconsistencies. By parsing the code and building a detailed understanding of its structure and types, PSALM helps developers catch issues early in the development lifecycle, significantly improving code quality, reliability, and maintainability, especially in large and complex projects. It supports modern PHP language features and can be integrated into continuous integration/delivery (CI/CD) pipelines to enforce coding standards and prevent regressions.
CAVEATS
Psalm is not a built-in or standard Linux command; it is primarily a PHP application that runs within a Linux environment. It requires PHP (version 7.1 or higher) and Composer for installation and execution. Effective use often demands careful configuration via its `psalm.xml` file. While powerful, it may occasionally produce false positives or miss some edge cases.
CONFIGURATION FILE (PSALM.XML)
Psalm's behavior is primarily controlled by its configuration file (typically `psalm.xml` or `psalm.xml.dist`), which defines the source directories, allowed issues, plugins, and other analysis parameters.
BASELINES
Baselines (`psalm-baseline.xml`) allow developers to commit Psalm with existing errors, then only report new errors, facilitating gradual adoption and refactoring.
PLUGINS
Psalm supports a rich plugin ecosystem, enabling extensions to its analysis capabilities, integration with other tools, and support for specific frameworks or libraries.
HISTORY
Psalm originated from Vimeo engineering as an internal tool to improve the reliability and maintainability of their large PHP codebase. It was subsequently open-sourced and has since become a widely adopted and actively developed project within the PHP community, continually evolving to support new PHP features and provide more robust analysis capabilities. Its development focuses on deep type inference and control flow analysis.