# Fixing Code Psalm is good at finding potential issues in large codebases, but once found, it can be something of a gargantuan task to fix all the issues. It comes with a tool, called Psalter, that helps you fix code. You can either run it via its binary ``` vendor/bin/psalter [args] ``` or via Psalm's binary: ``` vendor/bin/psalm --alter [args] ``` ## Safety features Updating code is inherently risky, doing so automatically is even more so. I've added a few features to make it a little more reassuring: - To see what changes Psalter will make ahead of time, you can run it with `--dry-run`. - You can target particular versions of PHP via `--php-version`, so that (for example) you don't add nullable typehints to PHP 7.0 code, or any typehints at all to PHP 5.6 code. `--php-version` defaults to your current version. - it has a `--safe-types` mode that will only update PHP 7 return typehints with information Psalm has gathered from non-docblock sources of type information (e.g. typehinted params, `instanceof` checks, other return typehints etc.) - using `--allow-backwards-incompatible-changes=false` you can make sure to not create backwards incompatible changes ## Plugins You can pass in your own manipulation plugins e.g. ```bash vendor/bin/psalter --plugin=vendor/vimeo/psalm/examples/plugins/ClassUnqualifier.php --dry-run ``` The above example plugin converts all unnecessarily qualified classnames in your code to shorter aliased versions. ## Supported fixes This initial release provides support for the following alterations, corresponding to the names of issues Psalm finds. To fix all of these at once, run `vendor/bin/psalter --issues=all` ### MissingReturnType Running `vendor/bin/psalter --issues=MissingReturnType --php-version=7.0` on ```php foo = 5; } else { $this->foo = "hello"; } $this->bar = "baz"; } public function setBaz() { $this->baz = [1, 2, 3]; } } ``` gives ```php |null * @psalm-var non-empty-list|null */ public $baz; public function __construct() { if (rand(0, 1)) { $this->foo = 5; } else { $this->foo = "hello"; } $this->bar = "baz"; } public function setBaz() { $this->baz = [1, 2, 3]; } } ``` ### MismatchingDocblockParamType Given ```php