Psalm
v7.28.0PHP security analysis: Psalm's taint analysis finds SQL injection, XSS and more, plus type checks
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
psalm_check Check PHP code with Psalm
Runs Psalm and returns the issues it reports, each with its location, issue type, message and code snippet. Give the files or directories you changed for a fast check (incremental, in memory). Without paths it runs Psalm on the whole project, like CI does, which also finds unused code and taint paths between files: do that before you finish.
| Parameter | Type | Description |
|---|---|---|
paths | array | Files or directories, relative to the project root. Omit to check the whole project. |
show_info | boolean | Also report the issues that the errorLevel of psalm.xml downgrades to INFO, which are bugs to fix too (default true). false shows only what fails the run. |
types | array | Only report these issue types, such as `PossiblyNullReference`. Use it to see the issues that a long result left out. |
psalm_inspect Inspect types and symbols
Shows what Psalm knows about the code at a position: the type it infers for each variable and expression there, and for a class, function, method, property or constant, its signature, docblock and where it is declared. Point at the code with `column` or `text`; with neither, it lists everything on the line. Use it to find out why Psalm reports an issue, instead of guessing a type.
| Parameter | Type | Description |
|---|---|---|
file * | string | The PHP file, relative to the project root |
line * | integer | The line, starting at 1 |
column | integer | The column, starting at 1 (in bytes, as Psalm reports columns) |
text | string | Code on that line to point at instead of a column, e.g. `$user` or `getName`: its first occurrence on the line |
psalm_references Find references
Lists where a class, interface, trait, enum, function, method, property or class constant is used in the project. Name it with `symbol` (fully qualified: `App\User`, `App\User::getName`, `App\User::$name`, `App\User::ROLE`, `App\format_name`), or point at a use of it with `file`, `line` and `column` or `text`. The first call analyses the whole project.
| Parameter | Type | Description |
|---|---|---|
column | integer | The column, starting at 1 (in bytes, as Psalm reports columns) |
file | string | The PHP file, relative to the project root |
line | integer | The line, starting at 1 |
symbol | string | The fully qualified name of the symbol |
text | string | Code on that line to point at instead of a column, e.g. `$user` or `getName`: its first occurrence on the line |
psalm_symbols Find symbols by name
Finds the classes, interfaces, traits, enums and functions whose name has the query in it, and the methods, properties and constants of the project's classes, with where they are declared. Use it to get the fully qualified name that the other tools need.
| Parameter | Type | Description |
|---|---|---|
query * | string | A part of the name in any case: `user`, or `user::get` for the members of the classes named so |
psalm_members List the members of a type
Lists the methods (with their signatures), properties and constants of a class or of another type, also the inherited and the magic ones, with the type arguments filled in. Give the `type`, or point at an expression with `file`, `line` and `column` or `text`. Use it instead of guessing what can be called on an object.
| Parameter | Type | Description |
|---|---|---|
column | integer | The column, starting at 1 (in bytes, as Psalm reports columns) |
file | string | The PHP file, relative to the project root |
line | integer | The line, starting at 1 |
name | string | Only list the members whose name has this in it |
text | string | Code on that line to point at instead of a column, e.g. `$user` or `getName`: its first occurrence on the line |
type | string | A fully qualified class (`App\User`) or type (`ArrayObject<int, App\User>`) |
psalm_implementations Find implementations and overrides
Lists the classes that extend or implement a class or interface or use a trait, or the methods that override or implement a method. Name it with `symbol` (`App\User`, `App\User::getName`), or point at it with `file`, `line` and `column` or `text`.
| Parameter | Type | Description |
|---|---|---|
column | integer | The column, starting at 1 (in bytes, as Psalm reports columns) |
file | string | The PHP file, relative to the project root |
line | integer | The line, starting at 1 |
symbol | string | The fully qualified name of the class or method |
text | string | Code on that line to point at instead of a column, e.g. `$user` or `getName`: its first occurrence on the line |
psalm_trace Trace taint issues
Runs the taint analysis of the whole project and returns each security issue with every step from the source (such as `$_GET`) to the sink. Use it to find where to escape or validate the value.
| Parameter | Type | Description |
|---|---|---|
file | string | Only the issues reported in this file, relative to the project root |
line | integer | Only the issues reported on this line |
types | array | Only these issue types, such as `TaintedSql` |
psalm_fix Fix issues automatically
Fixes the issues that Psalm knows how to fix, such as `MissingReturnType`, `MissingParamType`, `UnusedVariable` or `RedundantCast`. Returns the diff and writes nothing: psalm_apply writes it.
| Parameter | Type | Description |
|---|---|---|
types * | array | The issue types to fix |
paths | array | Only change these files or directories, relative to the project root |
psalm_rename Rename a symbol
Renames a class, or a method (with its overrides), property or class constant, and the uses that Psalm finds in the project. Returns the diff and writes nothing: psalm_apply writes it. It does not change names in strings and comments.
| Parameter | Type | Description |
|---|---|---|
symbol * | string | The fully qualified name: `App\User`, `App\User::getName`, `App\User::$name` or `App\User::ROLE` |
to * | string | The new name: fully qualified for a class, whose file is moved to it (`App\Model\Customer`); for a member, its new name alone (`getFullName`) |
psalm_move Move symbols
Moves classes into a namespace, or static methods, static properties and constants into another class, and changes their uses in the project. Returns the diff and writes nothing: psalm_apply writes it.
| Parameter | Type | Description |
|---|---|---|
into * | string | The namespace for classes (`App\Model`), or the class for members (`App\UserFactory`) |
symbols * | array | The fully qualified names: `App\User` or `App\User::create` |
psalm_apply Write a previewed change
Writes the change that psalm_fix, psalm_rename or psalm_move showed to the files, unless they changed since. Psalm can't undo it.
| Parameter | Type | Description |
|---|---|---|
change * | string | The number at the end of the preview |
psalm_explain Explain an issue type
Returns the documentation of a Psalm issue type: what it means, an example, and how to fix it.
| Parameter | Type | Description |
|---|---|---|
issue * | string | The issue type (`PossiblyNullReference`), its shortcode (`78`) or its link (`https://psalm.dev/078`) |