Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using psalm with non-composer projects #3719

Closed
prabhu opened this issue Jun 30, 2020 · 7 comments
Closed

Using psalm with non-composer projects #3719

prabhu opened this issue Jun 30, 2020 · 7 comments
Labels

Comments

@prabhu
Copy link

prabhu commented Jun 30, 2020

I am trying to scan an old php project with psalm. I performed the following steps:

  1. clone https://github.com/webpwnized/mutillidae
  2. do composer --init
  3. Install psalm composer require --dev vimeo/psalm
  4. Do psalm init - vendor/bin/psalm --init

Init 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?

@psalm-github-bot
Copy link

Hey @prabhu, can you reproduce the issue on https://psalm.dev ?

@weirdan weirdan added the bug label Jun 30, 2020
@weirdan
Copy link
Collaborator

weirdan commented Jun 30, 2020

Have you tried running with --debug-by-line switch?

@prabhu
Copy link
Author

prabhu commented Jun 30, 2020

It ran for an hour but didn't produce psalm.xml. What is that flag supposed to do?

@weirdan
Copy link
Collaborator

weirdan commented Jun 30, 2020

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.

@weirdan
Copy link
Collaborator

weirdan commented Jun 30, 2020

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) {
// .......

@psalm-github-bot
Copy link

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

@prabhu
Copy link
Author

prabhu commented Jul 1, 2020

Thanks. Now I have a hang of how this tool works so can file better defects in the future.

@muglug muglug closed this as completed in 6047b7b Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants