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 lexik\bundle\jwtauthenticationbundle\security\authenticator\forwardcompatauthenticatortrait #8953

Open
adeptofvoltron opened this issue Dec 20, 2022 · 8 comments

Comments

@adeptofvoltron
Copy link

when running psalm --init

Uncaught InvalidArgumentException: Could not get class storage for lexik\bundle\jwtauthenticationbundle\security\authenticator\forwardcompatauthenticatortrait in phar:///var/www/blackbird/psalm.phar/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php:39

psalm I got in dev-master version
"lexik/jwt-authentication-bundle": "2.16.0"

the problematic file I try to ignore. I tried to run no diff etc

@psalm-github-bot
Copy link

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

@hyptos
Copy link

hyptos commented Dec 20, 2022

Hello,

I have the same problem.

here is the detailed stack trace :

/var/www/symfony/src/Service/User/Security/RefreshTokenAuthenticator.php:47
Uncaught InvalidArgumentException: Could not get class storage for lexik\bundle\jwtauthenticationbundle\security\authenticator\forwardcompatauthenticatortrait in /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php:45
Stack trace:
#0 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/ClassLikes.php(778): Psalm\Internal\Provider\ClassLikeStorageProvider->get('Lexik\\Bundle\\JW...')
#1 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php(142): Psalm\Internal\Codebase\ClassLikes->getTraitNode('Lexik\\Bundle\\JW...')
#2 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(414): Psalm\Internal\Analyzer\ClassLikeAnalyzer->getMethodMutations('__construct', Object(Psalm\Context))
#3 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(1375): Psalm\Internal\Analyzer\FileAnalyzer->getMethodMutations(Object(Psalm\Internal\MethodIdentifier), Object(Psalm\Context), true)
#4 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(381): Psalm\Internal\Analyzer\ProjectAnalyzer->getMethodMutations(Object(Psalm\Internal\MethodIdentifier), Object(Psalm\Context), '/var/www/symfon...', 'src/Service/Use...')
#5 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/ExistingAtomicStaticCallAnalyzer.php(130): Psalm\Internal\Analyzer\FileAnalyzer->getMethodMutations(Object(Psalm\Internal\MethodIdentifier), Object(Psalm\Context))
#6 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php(881): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticMethod\ExistingAtomicStaticCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(PhpParser\Node\Identifier), Array, Object(Psalm\Context), Object(Psalm\Type\Atomic\TNamedObject), Object(Psalm\Internal\MethodIdentifier), 'Lexik\\Bundle\\JW...', Object(Psalm\Storage\ClassLikeStorage), false, NULL)
#7 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticMethod/AtomicStaticCallAnalyzer.php(207): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticMethod\AtomicStaticCallAnalyzer::handleNamedCall(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(PhpParser\Node\Identifier), Object(Psalm\Context), Object(Psalm\Type\Atomic\TNamedObject), Array, 'Lexik\\Bundle\\JW...', false, true, NULL)
#8 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php(208): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticMethod\AtomicStaticCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context), Object(Psalm\Type\Atomic\TNamedObject), false, false, false, true, NULL)
#9 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(190): Psalm\Internal\Analyzer\Statements\Expression\Call\StaticCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context), NULL)
#10 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(86): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context), false, Object(Psalm\Context), true, NULL, false)
#11 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(565): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\StaticCall), Object(Psalm\Context), false, Object(Psalm\Context), true)
#12 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(194): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Expression), Object(Psalm\Context), Object(Psalm\Context))
#13 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php(457): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), Object(Psalm\Context), true)
#14 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1250): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Internal\Provider\NodeDataProvider), Object(Psalm\Context), true)
#15 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(550): Psalm\Internal\Analyzer\ClassAnalyzer->checkPropertyInitialization(Object(Psalm\Codebase), Object(Psalm\Config), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Context), Object(Psalm\Context), Object(Psalm\Internal\Analyzer\MethodAnalyzer))
#16 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(203): Psalm\Internal\Analyzer\ClassAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Context))
#17 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(1581): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#18 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(522): Psalm\Internal\Codebase\Analyzer->analysisWorker(1692, '/var/www/symfon...')
#19 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(272): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1)
#20 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(651): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1, false, true)
#21 /var/www/symfony/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(380): Psalm\Internal\Analyzer\ProjectAnalyzer->check('/var/www/symfon...', true)
#22 /var/www/symfony/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run(Array)
#23 {main}
(Psalm 5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863 crashed due to an uncaught Throwable)$refreshToken

@hyptos
Copy link

hyptos commented Dec 20, 2022

I removed a constructor call in classes that extends JWTAuthenticator

public function __construct(
        EntityManagerInterface $entityManager,
        UrlGeneratorInterface $urlGenerator,
        CsrfTokenManagerInterface $csrfTokenManager,
        UserPasswordHasherInterface $passwordEncoder,
        JWTTokenManagerInterface $jwtManager,
        UserProviderInterface $userProvider,
        EventDispatcherInterface $dispatcher,
        TokenExtractorInterface $tokenExtractor
    ) {
//        parent::__construct($jwtManager, $dispatcher, $tokenExtractor, $userProvider);
        $this->entityManager = $entityManager;
        $this->urlGenerator = $urlGenerator;
        $this->csrfTokenManager = $csrfTokenManager;
        $this->passwordEncoder = $passwordEncoder;
        $this->jwtManager = $jwtManager;
    }

And the init worked, so this is the culprit but how to fix it properly, i don't know.

@orklah
Copy link
Collaborator

orklah commented Dec 20, 2022

Note: this lib is known to have difficulties with static tools: lexik/LexikJWTAuthenticationBundle#944

It seems related to compatibility layers:
https://github.com/lexik/LexikJWTAuthenticationBundle/blob/7c4c887c4652445a5c587d96caa36cc49b760925/Security/Authenticator/ForwardCompatAuthenticatorTrait.php

I think Psalm has difficulties to extract dynamic declarations of symbols here

Did it used to work and then broke?

@hyptos
Copy link

hyptos commented Dec 21, 2022

Hello, thank you for your time.

It's a first run on my project for me and it just don't work with the constructor, init or not.

I'm going to fix the whole thing without the constructor and then put it back.

It looks like there is a fix on a recent version : #7863

I'm running : Psalm 5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863

So either it's not really fixed or I'm missing something.

@orklah
Copy link
Collaborator

orklah commented Dec 21, 2022

Oh, I missed the link with #7863

ping @weirdan if you can take a look

@weirdan
Copy link
Collaborator

weirdan commented Dec 21, 2022

The backtrace is different. We would need a minimal reproducer on psalm.dev (or in a separate repo, if that's not possible on psalm.dev).

@faizanakram99
Copy link

I've the same error and this class triggers it, not sure why.

<?php

declare(strict_types=1);

namespace Qbil\CommonBundle\Services;

use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Qbil\Numbering\Domain\Entity\SupportsNumbering;
use Qbil\Numbering\Domain\Exception\InvalidNumberingScheme;
use Qbil\Numbering\Domain\Exception\NoActiveNumberingSchemeFound;
use Qbil\Numbering\Domain\Repository\NumberingSchemeRepository;
use Qbil\Numbering\Domain\Repository\RepositorySupportsGeneratingNextSequenceNumber;
use Qbil\Numbering\Domain\Services\DetermineNumberingRequirementsVisitor;
use Qbil\TradeBundle\Entity\Afroep;
use Qbil\TradeBundle\Entity\AfroepRepository;
use Qbil\TradeBundle\Entity\Contract;
use Qbil\TradeBundle\Entity\ContractRepository;
use Qbil\TradeBundle\Entity\FreeformDocument;
use Qbil\TradeBundle\Entity\FreeformDocumentRepository;
use Qbil\TradeBundle\Entity\Productieopdracht;
use Qbil\TradeBundle\Entity\ProductieopdrachtRepository;
use Qbil\TradeBundle\Entity\PurchaseInvoice;
use Qbil\TradeBundle\Entity\PurchaseInvoiceRepository;
use Qbil\TradeBundle\Entity\Salesinvoice;
use Qbil\TradeBundle\Entity\SalesinvoiceRepository;
use Qbil\TradeBundle\Entity\Transportorder;
use Qbil\TradeBundle\Entity\TransportorderRepository;
use Symfony\Contracts\Service\ServiceSubscriberInterface;

class NumberAssigner implements ServiceSubscriberInterface
{
    public function __construct(
        private NumberingSchemeRepository $numberingSchemeRepository,
        private ContainerInterface $nextSequenceNumberGeneratorFinder,
    ) {
    }

    /**
     * @throws InvalidNumberingScheme
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws \LogicException
     */
    public function assignDisplayNumber(SupportsNumbering $entity): void
    {
        if ($entity->hasDisplayNumber()) {
            return;
        }

        $numberingRequirements = $entity->determineNumberingRequirements(
            new DetermineNumberingRequirementsVisitor(),
        );

        $numberingScheme = $this->numberingSchemeRepository->findNumberingScheme($numberingRequirements);

        if (null === $numberingScheme) {
            throw new NoActiveNumberingSchemeFound();
        }

        if (!$this->nextSequenceNumberGeneratorFinder->has($entity::class)) {
            throw new \LogicException(\sprintf("Repository of entity '%s' is not among subscribed services.", $entity::class));
        }

        $repository = $this->nextSequenceNumberGeneratorFinder->get($entity::class);

        if (!$repository instanceof RepositorySupportsGeneratingNextSequenceNumber) {
            throw new \LogicException(\sprintf("EntityRepository '%s' does not implement '%s'", $repository::class, RepositorySupportsGeneratingNextSequenceNumber::class));
        }

        $displayNumber = $numberingScheme->resolve(
            $entity,
            $repository->generateNextSequenceNumber($entity, $numberingScheme->scheme()),
        );

        $entity->assignDisplayNumber($displayNumber);
    }

    public static function getSubscribedServices(): array
    {
        return [
            Afroep::class => AfroepRepository::class,
            Contract::class => ContractRepository::class,
            FreeformDocument::class => FreeformDocumentRepository::class,
            Productieopdracht::class => ProductieopdrachtRepository::class,
            PurchaseInvoice::class => PurchaseInvoiceRepository::class,
            Salesinvoice::class => SalesinvoiceRepository::class,
            Transportorder::class => TransportorderRepository::class,
        ];
    }
}
Uncaught RuntimeException: PHP Error: Uninitialized string offset 0 in /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Type/Atomic/TNamedObject.php:58 for command with CLI args "/home/ubuntu/Repositories/qbil-trade/vendor/bin/psalm --debug" in /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/ErrorHandler.php:75
Stack trace:
#0 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Type/Atomic/TNamedObject.php(58): Psalm\Internal\ErrorHandler::Psalm\Internal\{closure}()
#1 /home/ubuntu/Repositories/qbil-trade/vendor/psalm/plugin-symfony/src/Handler/ContainerHandler.php(82): Psalm\Type\Atomic\TNamedObject->__construct()
#2 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/EventDispatcher.php(269): Psalm\SymfonyPsalmPlugin\Handler\ContainerHandler::afterMethodCallAnalysis()
#3 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/ExistingAtomicMethodCallAnalyzer.php(491): Psalm\Internal\EventDispatcher->dispatchAfterMethodCallAnalysis()
#4 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php(469): Psalm\Internal\Analyzer\Statements\Expression\Call\Method\ExistingAtomicMethodCallAnalyzer::analyze()
#5 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php(184): Psalm\Internal\Analyzer\Statements\Expression\Call\Method\AtomicMethodCallAnalyzer::analyze()
#6 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(186): Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze()
#7 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(86): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression()
#8 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php(242): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze()
#9 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(544): Psalm\Internal\Analyzer\Statements\Expression\AssignmentAnalyzer::analyze()
#10 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(178): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyzeAssignment()
#11 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(86): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression()
#12 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(565): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze()
#13 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(194): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement()
#14 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php(457): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze()
#15 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1798): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->analyze()
#16 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(425): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod()
#17 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(203): Psalm\Internal\Analyzer\ClassAnalyzer->analyze()
#18 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(1581): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#19 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(522): Psalm\Internal\Codebase\Analyzer->analysisWorker()
#20 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(272): Psalm\Internal\Codebase\Analyzer->doAnalysis()
#21 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(651): Psalm\Internal\Codebase\Analyzer->analyzeFiles()
#22 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(380): Psalm\Internal\Analyzer\ProjectAnalyzer->check()
#23 /home/ubuntu/Repositories/qbil-trade/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run()
#24 /home/ubuntu/Repositories/qbil-trade/vendor/bin/psalm(120): include('...')
#25 {main}
(Psalm 5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863 crashed due to an uncaught Throwable)
Script psalm handling the psalm event returned with error code 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants