Psalm: switch from Phive to Composer
This switches the installation method for Psalm from Phive to Composer, while still using a Phar file for running Psalm.
- Removing Psalm from the Phive configuration.
- Adding Psalm to the Composer configuration. Includes upgrading from version
3.11.2 to version
- Adjusting the script used in the
👉 Please verify and test this as things work differently on different OS-es and this should work for you.
- Adjusting the GH Actions script to use the Composer installed version of Psalm.
Note: due to the committed
composer.lock file, Psalm will not automatically upgrade when newer versions are available.
Utils::pregSplit: limit is not nullable
Correctly flagged by Psalm:
ERROR: PossiblyNullArgument - src\Utils.php:50:53 - Argument 3 of preg_split cannot be null, possibly null value provided (see https://psalm.dev/078)
$parts = php_preg_split($pattern, $subject, $limit, $flags);
$limit argument of the PHP native
preg_split() function is not nullable.
Tags::__toString(): remove redundant type casts
Psalm flags these type casts as redundant:
ERROR: RedundantCastGivenDocblockType - src/DocBlock/Tags/Author.php:80:23 - Redundant cast to string given docblock-provided type (see https://psalm.dev/263)
$authorName = (string) $this->authorName;
ERROR: RedundantCastGivenDocblockType - src/DocBlock/Tags/Example.php:150:21 - Redundant cast to string given docblock-provided type (see https://psalm.dev/263)
$filePath = (string) $this->filePath;
ERROR: RedundantCastGivenDocblockType - src/DocBlock/Tags/Link.php:74:17 - Redundant cast to string given docblock-provided type (see https://psalm.dev/263)
$link = (string) $this->link;
ERROR: RedundantCastGivenDocblockType - src/DocBlock/Tags/Method.php:228:23 - Redundant cast to string given docblock-provided type (see https://psalm.dev/263)
$methodName = (string) $this->methodName;
I have verified each and can confirm that these are redundant. They are probably a left-over from the time when the
__construct() method in these classes did not yet have type declarations.
Tags/Return: remove redundant condition
Psalm flags this condition as redundant:
ERROR: RedundantCondition - src/DocBlock/Tags/Return_.php:62:48 - "" can never contain non-empty-lowercase-string (see https://psalm.dev/122)
return $type . ($description !== '' ? ($type !== '' ? ' ' : '') . $description : '');
Based on the statement in the line above -
$type = $this->type ? '' . $this->type : 'mixed'; -, Psalm is correct and the
$type variable can never be an empty string.
Psalm: suppress two notices
The current version of Psalm flags the following issues:
ERROR: InvalidReturnType - src\Utils.php:44:16 - The declared return type 'array<array-key, string>' for phpDocumentor\Reflection\Utils::pregSplit is incorrect, got 'list<list<int|string>|string>' (see https://psalm.dev/011)
* @return string Returns an array containing substrings of subject split along boundaries matched by pattern
ERROR: InvalidReturnStatement - src\Utils.php:55:16 - The inferred type 'list<list<int|string>|string>' does not match the declared return type 'array<array-key, string>' for phpDocumentor\Reflection\Utils::pregSplit (see https://psalm.dev/128)
I'm suggest ignoring this as
list isn't an officially supported type.
After this PR, there is still one issue remaining.
Argument 4 of preg_split expects 0|1|2|3|4|5|6|7, parent type int provided (see https://psalm.dev/193)
I believe this issue is for the
phpDocumentor\Reflection\Utils class and expects the
pregSplit() method to apply input validation to the value received for
$flags before passing it off to the PHP native
IMO that's taking things a little too far as PHP will handle this internally without errors. Want me to add it to the list of issues to be ignored ?
Side-note: the weird thing is that this issue does show up in CI, but with the same PHP + Psalm Phar version, I cannot reproduce this locally.