Psalm

v7.28.0
io.github.psalm/psalm Checked 1 day ago Published 12 hours ago

PHP 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.

ParameterTypeDescription
pathsarrayFiles or directories, relative to the project root. Omit to check the whole project.
show_infobooleanAlso 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.
typesarrayOnly 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.

ParameterTypeDescription
file *stringThe PHP file, relative to the project root
line *integerThe line, starting at 1
columnintegerThe column, starting at 1 (in bytes, as Psalm reports columns)
textstringCode 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.

ParameterTypeDescription
columnintegerThe column, starting at 1 (in bytes, as Psalm reports columns)
filestringThe PHP file, relative to the project root
lineintegerThe line, starting at 1
symbolstringThe fully qualified name of the symbol
textstringCode 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.

ParameterTypeDescription
query *stringA 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.

ParameterTypeDescription
columnintegerThe column, starting at 1 (in bytes, as Psalm reports columns)
filestringThe PHP file, relative to the project root
lineintegerThe line, starting at 1
namestringOnly list the members whose name has this in it
textstringCode on that line to point at instead of a column, e.g. `$user` or `getName`: its first occurrence on the line
typestringA 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`.

ParameterTypeDescription
columnintegerThe column, starting at 1 (in bytes, as Psalm reports columns)
filestringThe PHP file, relative to the project root
lineintegerThe line, starting at 1
symbolstringThe fully qualified name of the class or method
textstringCode 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.

ParameterTypeDescription
filestringOnly the issues reported in this file, relative to the project root
lineintegerOnly the issues reported on this line
typesarrayOnly 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.

ParameterTypeDescription
types *arrayThe issue types to fix
pathsarrayOnly 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.

ParameterTypeDescription
symbol *stringThe fully qualified name: `App\User`, `App\User::getName`, `App\User::$name` or `App\User::ROLE`
to *stringThe 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.

ParameterTypeDescription
into *stringThe namespace for classes (`App\Model`), or the class for members (`App\UserFactory`)
symbols *arrayThe 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.

ParameterTypeDescription
change *stringThe 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.

ParameterTypeDescription
issue *stringThe issue type (`PossiblyNullReference`), its shortcode (`78`) or its link (`https://psalm.dev/078`)