Skip to content

Could not process due to: System error: "Typed property PHPStan\Type\StaticType::$classReflection must not be accessed before initialization" #9194

@LordSimal

Description

@LordSimal

Bug Report

Subject Details
Rector version a099fd5433a6a10d18770ad8612b7c67b58b20dc

We are currently in the process of trying to make a new ruleset for CakePHP 6.0 adjustments and have noticed a weird problem with rector.

Unfortunately I have not yet found an "easy" way to reproduce the problem, but please let me try to explain it.

  • Checkout https://github.com/cakephp/upgrade/tree/6.x, aka the upgrade wrapper
  • Checkout https://github.com/cakephp/cakephp/tree/6.x, aka the app/framework to upgrade
  • execute make install-dev on the upgrade repo (i used PHP 8.4.5)
  • Adjust src/Command/RectorCommand.php Line 86 in the upgrade repo to contain --debug for the rector command
  • Execute bin/cake upgrade rector --rules cakephp60 /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller (or whatever your path to the app/framework repo is - make sure to point ot the Controller directory specifically)

This should lead to the following error (cleaned up stacktrace):

[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Component.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Component/CheckHttpCacheComponent.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Component/FlashComponent.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Component/FormProtectionComponent.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/ComponentRegistry.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Controller.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/ControllerFactory.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/ErrorController.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Exception/FormProtectionException.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Exception/InvalidParameterException.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Exception/MissingActionException.php
[file] /Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Exception/MissingComponentException.php

 [ERROR] Could not process                                                      
         "/Users/kevin/Documents/CakePHP/Org/cakephp/src/Controller/Controller.php" file, due to:                                                      
         "System error: "Typed property PHPStan\Type\StaticType::$classReflection must not be accessed before initialization" 

#0  PHPStan\Type\StaticType->getStaticObjectType()
    phar://vendor/phpstan/phpstan/phpstan.phar/src/Type/StaticType.php:117

#1  PHPStan\Type\StaticType->isSuperTypeOf(
        Object(PHPStan\Type\StaticType)
    )
    vendor/rector/rector/src/NodeTypeResolver/TypeComparator/TypeComparator.php:103

#2  Rector\NodeTypeResolver\TypeComparator\TypeComparator->isSubtype(
        Object(PHPStan\Type\StaticType),
        Object(Rector\StaticTypeMapper\ValueObject\Type\SimpleStaticType)
    )
    vendor/rector/rector/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php:78

#3  Rector\VendorLocker\ParentClassMethodTypeOverrideGuard->shouldSkipReturnTypeChange(
        Object(PhpParser\Node\Stmt\ClassMethod),
        Object(Rector\StaticTypeMapper\ValueObject\Type\SimpleStaticType)
    )
    vendor/rector/rector/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationRector.php:125

#4  Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector->processClassMethodNodeWithTypehints(
        Object(PhpParser\Node\Stmt\ClassMethod),
        Object(PhpParser\Node\Stmt\Class_),
        Object(Rector\StaticTypeMapper\ValueObject\Type\SimpleStaticType),
        Object(PHPStan\Type\ObjectType)
    )
    vendor/rector/rector/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationRector.php:94

#5  Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector->refactor(
        Object(PhpParser\Node\Stmt\Class_)
    )
    vendor/rector/rector/src/Rector/AbstractRector.php:112

#6  Rector\Rector\AbstractRector->enterNode(
        Object(PhpParser\Node\Stmt\Class_)
    )
    vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:173

#7  PhpParser\NodeTraverser->traverseArray(Array)
    vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:90

#8  PhpParser\NodeTraverser->traverseNode(
        Object(PhpParser\Node\Stmt\Namespace_)
    )
    vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:200

#9  PhpParser\NodeTraverser->traverseArray(Array)
    vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:71

#10 Rector\PhpParser\NodeTraverser\RectorNodeTraverser->traverse(Array)
    vendor/rector/rector/src/PhpParser/NodeTraverser/RectorNodeTraverser.php:49

#11 Rector\Application\FileProcessor->processFile(
        Object(Rector\ValueObject\Application\File),
        Object(Rector\ValueObject\Configuration)
    )
    vendor/rector/rector/src/Application/FileProcessor.php:95

#12 Rector\Application\ApplicationFileProcessor->processFile(...)
    vendor/rector/rector/src/Application/ApplicationFileProcessor.php:174

#13 Rector\Application\ApplicationFileProcessor->processFile(...)
    vendor/rector/rector/src/Application/ApplicationFileProcessor.php:151

#14 Rector\Application\ApplicationFileProcessor->processFiles(...)
    vendor/rector/rector/src/Application/ApplicationFileProcessor.php:128

#15 Rector\Application\ApplicationFileProcessor->run(
        Object(Rector\ValueObject\Configuration),
        Object(Symfony\Component\Console\Input\ArgvInput)
    )
    vendor/rector/rector/src/Console/Command/ProcessCommand.php:172

#16 Rector\Console\Command\ProcessCommand->execute(...)
    vendor/rector/rector/vendor/symfony/console/Command/Command.php:285

#17 Symfony\Component\Console\Command\Command->run(...)
    vendor/rector/rector/vendor/symfony/console/Application.php:900

#18 Symfony\Component\Console\Application->doRunCommand(...)
    vendor/rector/rector/vendor/symfony/console/Application.php:279

#19 Rector\Console\ConsoleApplication->doRun(...)
    vendor/rector/rector/src/Console/ConsoleApplication.php:63

#20 Symfony\Component\Console\Application->doRun(...)
    vendor/rector/rector/vendor/symfony/console/Application.php:162

#21 {main}
    vendor/rector/rector/bin/rector.php:130
    vendor/rector/rector/bin/rector:5
    vendor/bin/rector:119

so something inside the https://github.com/cakephp/cakephp/blob/6.x/src/Controller/Controller.php triggers rector - or more specifically the PHPStan\Type\StaticType - to error since the classReflection property has not yet been initialized.

Minimal PHP Code Causing Issue

I am not able to reproduce this in a "simple" way, since our cakephp/upgrade tool is wrapper for rector with a bunch of custom configs in there and I have absolutely no idea which rector rule it is which triggers the error (if its a rector rule at all)

I am pretty sure though this is NOT a problem with our config, especially looking at the stacktrace above.

Expected Behaviour

Don't error 😁

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions