- The default configuration analyzes the
srcdirectory with error level 2 (strict). - The default configuration includes the Symfony and PHPUnit plugins.
- The
--configflag is used to specify the configuration to be used.
vendor/bin/psalm --config=vendor/kununu/code-tools/dist/psalm.xml.distvendor/bin/psalm --config=vendor/kununu/code-tools/dist/psalm.xml.dist --no-cache- You can customize the
psalm.xmlfile to include/exclude directories, add stubs, configure issue handlers, or use a baseline. - The easiest way to customize the configuration is to copy the
psalm.xml.distfile to your project and modify it, for this we provide the following command:
vendor/bin/code-tools publish:config psalm- The
psalm.xmlfile will be copied to your project root, and you can modify it to suit your needs.
See some customization examples
Stubs help Psalm understand types from external libraries that lack proper type declarations:
<?xml version="1.0"?>
<psalm
errorLevel="2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins>
<stubs>
<file name="vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php"/>
<file name="vendor/squizlabs/php_codesniffer/src/Files/File.php"/>
</stubs>
</psalm>Suppress specific issues for certain directories or files:
<?xml version="1.0"?>
<psalm
errorLevel="2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins>
<issueHandlers>
<ClassMustBeFinal>
<errorLevel type="suppress">
<directory name="src/Sniffs"/>
</errorLevel>
</ClassMustBeFinal>
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="src/Entity"/>
</errorLevel>
</PropertyNotSetInConstructor>
</issueHandlers>
</psalm>Baselines allow you to suppress existing issues while enforcing strict analysis on new code:
<?xml version="1.0"?>
<psalm
errorLevel="2"
errorBaseline="psalm-baseline.xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins>
</psalm>vendor/bin/psalm --config=psalm.xml| Option | Default | Description |
|---|---|---|
errorLevel |
2 |
Strictness level (1=strictest, 8=most lenient) |
findUnusedCode |
false |
Detect unused classes, methods, and variables |
ensureOverrideAttribute |
false |
Require #[Override] attribute on overridden methods |
errorBaseline |
— |
Path to baseline file for suppressing existing issues |
Baselines allow you to suppress existing issues while enforcing strict analysis on new code.
vendor/bin/psalm --config=psalm.xml --set-baseline=psalm-baseline.xmlAfter fixing issues, regenerate to remove resolved entries:
vendor/bin/psalm --config=psalm.xml --update-baselineRun analysis without baseline to see all issues:
vendor/bin/psalm --config=psalm.xml --ignore-baseline