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

Uncaught InvalidArgumentException: Could not get class storage for class-string<kiss\widget\widget> #4198

Closed
Lachee opened this issue Sep 17, 2020 · 8 comments
Labels

Comments

@Lachee
Copy link

Lachee commented Sep 17, 2020

Getting an uncaught exception when trying to analyse my project.

$ ./vendor/bin/psalm
Scanning files...
Analyzing files...

EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE░░E░░░E░EEEEEEEEEEEEEEEE░EEE  60 / 191 (31%)
EEEEEEEEEUncaught InvalidArgumentException: Could not get class storage for class-string<kiss\widget\widget> in D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Provider\ClassLikeStorageProvider.php:42
Stack trace:
#0 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Properties.php(97): Psalm\Internal\Provider\ClassLikeStorageProvider->get('class-string<ki...')
#1 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Expression\Assignment\StaticPropertyAssignmentAnalyzer.php(69): Psalm\Internal\Codebase\Properties->propertyExists('class-string<ki...', false, Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(Psalm\Context))
#2 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Expression\Assignment\ArrayAssignmentAnalyzer.php(646): Psalm\Internal\Analyzer\Statements\Expression\Assignment\StaticPropertyAssignmentAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticPropertyFetch), NULL, Object(Psalm\Type\Union), Object(Psalm\Context))
#3 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Expression\Assignment\ArrayAssignmentAnalyzer.php(53): Psalm\Internal\Analyzer\Statements\Expression\Assignment\ArrayAssignmentAnalyzer::updateArrayType(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\ArrayDimFetch), Object(PhpParser\Node\Expr\Variable), Object(Psalm\Type\Union), Object(Psalm\Context))
#4 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Expression\AssignmentAnalyzer.php(728): Psalm\Internal\Analyzer\Statements\Expression\Assignment\ArrayAssignmentAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\ArrayDimFetch), Object(Psalm\Context), Object(PhpParser\Node\Expr\Variable), Object(Psalm\Type\Union))
#5 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer.php(125): Psalm\Internal\Analyzer\Statements\Expression\AssignmentAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\ArrayDimFetch), Object(PhpParser\Node\Expr\Variable), Object(Psalm\Type\Union), Object(Psalm\Context), NULL)
#6 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer.php(44): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\Assign), Object(Psalm\Context), false, Object(Psalm\Context), true)
#7 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(483): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\Assign), Object(Psalm\Context), false, Object(Psalm\Context), true)
#8 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(164): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Expression), Object(Psalm\Context), Object(Psalm\Context))
#9 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FunctionLikeAnalyzer.php(591): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), Object(Psalm\Context), true)
#10 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ClassAnalyzer.php(1897): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Internal\Provider\NodeDataProvider), Object(Psalm\Context))
#11 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ClassAnalyzer.php(738): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod(Object(PhpParser\Node\Stmt\ClassMethod), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Internal\Analyzer\ClassAnalyzer), Object(Psalm\Context), Object(Psalm\Context))
#12 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FileAnalyzer.php(215): Psalm\Internal\Analyzer\ClassAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Context))
#13 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(336): Psalm\Internal\Analyzer\FileAnalyzer->analyze(NULL)
#14 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(576): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}(69, 'D:\\apache\\htdoc...')
#15 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(268): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1)
#16 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ProjectAnalyzer.php(639): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1, false, true)
#17 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\src\psalm.php(677): Psalm\Internal\Analyzer\ProjectAnalyzer->check('D:\\apache\\htdoc...', false)
#18 D:\apache\htdocs\xve-php\vendor\vimeo\psalm\psalm(2): require_once('D:\\apache\\htdoc...')
#19 {main}
(Psalm 3.16@d03e5ef057d6adc656c0ff7e166c50b73b4f48f3 crashed due to an uncaught Throwable)

The project is fairly large, and I use a lot of documentation within it, with lots of styles of documentation as this project is fairly old and has involved with my use of different PHP tools ( I now use a lot of Intelephense compatible doc stylings).

The file itself it is crashing on is fairly simple:

<?php
namespace kiss\widget;

use kiss\exception\InvalidOperationException;
use kiss\models\BaseObject;

class Widget extends BaseObject {

    /** Stack of in-progress widgets */
    protected static $stack = [];

    /** Adds the start tags for the widget */
    public function begin() {}

    /** Adds the end tags for the widget */
    public function end() {}

    /** echos out the instance immediately */
    public function run() { 
        $this->begin();
        $this->end();
    }

    /** Creates a new wiget instance. */
    public static function widget($options = []) {
        $class = get_called_class();
        $obj = BaseObject::new($class, $options);
        $obj->run();
        return '';
    }

    /** Creates a new widget instance, pushes it to a stack and invokes only its begin() */
    public static function widgetBegin($options = []) {
        $class = get_called_class();
        $obj = BaseObject::new($class, $options);
        $class::$stack[] = $obj;
        $obj->begin();
        return '';
    }

    /** Ends a widget from the stack */
    public static function widgetEnd() {
        $class = get_called_class();
        if (empty($class::$stack)) 
            throw new InvalidOperationException('endWidget was called before a startWidget');

        $obj = array_pop($class::$stack);
        $obj->end();
        return '';
    }
}

While the project is on GitHub, its a private repository. If you need access to the entire project, then I will be happy to invite you to the project temporarily.

@psalm-github-bot
Copy link

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

@Lachee
Copy link
Author

Lachee commented Sep 17, 2020

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

No, the issue is not reproducible on psalm.dev

@muglug
Copy link
Collaborator

muglug commented Sep 18, 2020

@Lachee yes, please invite me to the project if you can

@Lachee
Copy link
Author

Lachee commented Sep 18, 2020

The invite has been sent. The issue is on the ast-kiss branch.

@muglug
Copy link
Collaborator

muglug commented Sep 19, 2020

@Lachee I don't think I received that invite

@Lachee
Copy link
Author

Lachee commented Sep 19, 2020

@muglug just sent it again. The repo is lachee/xve-php

@muglug muglug added the bug label Sep 20, 2020
@muglug
Copy link
Collaborator

muglug commented Sep 20, 2020

You can remove me now.

Reproduced here: https://psalm.dev/r/0f930de10f

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/0f930de10f
<?php

class A {
    public static array $stack = [];

    public static function foo() : void {
        $class = get_called_class();
        $class::$stack[] = 1;
    }
}
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php: Could not get class storage for class-string<a>

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