I am trying to scan an old php project with psalm. I performed the following steps:
composer --initcomposer require --dev vimeo/psalmvendor/bin/psalm --initInit operation leads to the below error.
$ vendor/bin/psalm --init
Calculating best config level based on project files
Scanning files...
Analyzing files...
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEâ–‘â–‘EEEâ–‘â–‘â–‘EEâ–‘â–‘â–‘ 60 / 922 (6%)
â–‘EEEEEâ–‘â–‘â–‘EEEâ–‘â–‘EEEEEâ–‘â–‘Eâ–‘Eâ–‘EEEEEEEEEEEEEâ–‘â–‘EEEEEEEEEEEEEEEEEEEE 120 / 922 (13%)
EEEEEEâ–‘EEEEEEEâ–‘EEEEEEEEEEEEEEEEEEEâ–‘EEEEEâ–‘EEEEEEEEEEEEEEEâ–‘Uncaught Exception: Could not get class storage for editable
Stack trace in the forked worker:
#0 /home/prabhu/sandbox/mutillidae/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Methods.php(908): Psalm\Internal\Provider\ClassLikeStorageProvider->get()
#1 /home/prabhu/sandbox/mutillidae/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/MethodAnalyzer.php(208): Psalm\Internal\Codebase\Methods->getDeclaringMethodId()
#2 /home/prabhu/sandbox/mutillidae/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/CloneAnalyzer.php(66): Psalm\Internal\Analyzer\MethodAnalyzer::isMethodVisible()
#3 /home/prabhu/sandbox/mutillidae/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(299): Psalm\Internal\Analyzer\Statements\Expression\CloneAnalyzer::analyze()
#4 /home/prabhu/sandbox/mutillidae/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(45): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression()
#5 /home/prabhu/sandbox/mutillidae/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php(138): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze()
Any ideas?
Hey @prabhu, can you reproduce the issue on https://psalm.dev ?
Have you tried running with --debug-by-line switch?
It ran for an hour but didn't produce psalm.xml. What is that flag supposed to do?
It's supposed to produce a lot of debug output - basically a line for every line Psalm analyzes. Usually the last log entry points to the line in your source code that makes Psalm crash.
Reproduced with https://psalm.dev/r/7abe81ec41
The crash is triggered by invalid return type in docblock for HTMLPurifier_DoctypeRegistry::get() method:
/**
* Retrieves reference to a doctype of a certain name
* @note This function resolves aliases
* @note When possible, use the more fully-featured make()
* @param $doctype Name of doctype
* @return Editable doctype object
*/
public function get($doctype) {
// .......
I found these snippets:
https://psalm.dev/r/7abe81ec41
<?php
/**
* @psalm-suppress UndefinedDocblockClass
* @psalm-suppress InvalidReturnType
* @return Editable
*/
function get() {}
clone get();
Psalm encountered an internal error:
/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php: Could not get class storage for editable
Thanks. Now I have a hang of how this tool works so can file better defects in the future.