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

Could not process stringable object #8193

Closed
vjik opened this issue Sep 11, 2023 · 3 comments · Fixed by rectorphp/rector-src#5001
Closed

Could not process stringable object #8193

vjik opened this issue Sep 11, 2023 · 3 comments · Fixed by rectorphp/rector-src#5001
Assignees
Labels

Comments

@vjik
Copy link

vjik commented Sep 11, 2023

Bug Report

Subject Details
Rector version 0.18.2
PHP version 8.0.30

Error in PHP 8.0 only:


[file] tests/Support/StringableObject.php
[rule] Rector\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector


 [ERROR] Could not process "/projects/yiisoft/yii-dev-tool/dev/access/tests/Support/StringableObject.php" file, due to:
         "System error: "Syntax error, unexpected T_STRING, expecting T_VARIABLE906, Syntax error, unexpected T_STRING,
         expecting T_VARIABLE920, Syntax error, unexpected T_STRING, expecting T_VARIABLE945, Syntax error, unexpected
         T_STRING, expecting T_VARIABLE970, Syntax error, unexpected T_STRING, expecting T_VARIABLE1119"

         Stack trace:
         #0 vendor/rector/rector/packages/PhpDocParser/PhpParser/SmartPhpParser.php(29):
         PHPStan\Parser\RichParser->parseFile('phar:///project...')
         #1 vendor/rector/rector/src/PhpParser/AstResolver.php(299):
         Rector\PhpDocParser\PhpParser\SmartPhpParser->parseFile('phar:///project...')
         #2 vendor/rector/rector/src/PhpParser/AstResolver.php(119):
         Rector\Core\PhpParser\AstResolver->parseFileNameToDecoratedNodes('phar:///project...')
         #3 vendor/rector/rector/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php(116):
         Rector\Core\PhpParser\AstResolver->resolveClassMethodFromMethodReflection(Object(PHPStan\Reflection\Native\Nat
         iveMethodReflection))
         #4 vendor/rector/rector/src/Rector/AbstractRector.php(184):
         Rector\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector->refactor(Object(PhpParser\Node\Stmt\Cl
         assMethod))
         #5 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(176):
         Rector\Core\Rector\AbstractRector->enterNode(Object(PhpParser\Node\Stmt\ClassMethod))
         #6 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105):
         PhpParser\NodeTraverser->traverseArray(Array)
         #7 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196):
         PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Class_))
         #8 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105):
         PhpParser\NodeTraverser->traverseArray(Array)
         #9 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196):
         PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Namespace_))
         #10 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(85):
         PhpParser\NodeTraverser->traverseArray(Array)
         #11 vendor/rector/rector/src/PhpParser/NodeTraverser/RectorNodeTraverser.php(41):
         PhpParser\NodeTraverser->traverse(Array)
         #12 vendor/rector/rector/src/Application/FileProcessor.php(44):
         Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser->traverse(Array)
         #13 vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php(100):
         Rector\Core\Application\FileProcessor->refactor(Object(Rector\Core\ValueObject\Application\File))
         #14 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(154):
         Rector\Core\Application\FileProcessor\PhpFileProcessor->process(Object(Rector\Core\ValueObject\Application\Fil
         e), Object(Rector\Core\ValueObject\Configuration))
         #15 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(131):
         Rector\Core\Application\ApplicationFileProcessor->processFile(Object(Rector\Core\ValueObject\Application\File)
         , Array, Object(Rector\Core\ValueObject\Configuration))
         #16 vendor/rector/rector/packages/Parallel/WorkerRunner.php(56):
         Rector\Core\Application\ApplicationFileProcessor->processFiles(Array,
         Object(Rector\Core\ValueObject\Configuration))
         #17 vendor/rector/rector/vendor/evenement/evenement/src/EventEmitterTrait.php(111):
         Rector\Parallel\WorkerRunner->Rector\Parallel\{closure}(Array)
         #18 vendor/rector/rector/vendor/clue/ndjson-react/src/Decoder.php(117):
         RectorPrefix202309\Evenement\EventEmitter->emit('data', Array)
         #19 vendor/rector/rector/vendor/evenement/evenement/src/EventEmitterTrait.php(111):
         RectorPrefix202309\Clue\React\NDJson\Decoder->handleData(Array)
         #20 vendor/rector/rector/vendor/react/stream/src/Util.php(62):
         RectorPrefix202309\Evenement\EventEmitter->emit('data', Array)
         #21 vendor/rector/rector/vendor/evenement/evenement/src/EventEmitterTrait.php(111):
         RectorPrefix202309\React\Stream\Util::RectorPrefix202309\React\Stream\{closure}('{"action":"main...')
         #22 vendor/rector/rector/vendor/react/stream/src/DuplexResourceStream.php(154):
         RectorPrefix202309\Evenement\EventEmitter->emit('data', Array)
         #23 vendor/rector/rector/vendor/react/event-loop/src/StreamSelectLoop.php(201):
         RectorPrefix202309\React\Stream\DuplexResourceStream->handleData(Resource id #1845)
         #24 vendor/rector/rector/vendor/react/event-loop/src/StreamSelectLoop.php(173):
         RectorPrefix202309\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)
         #25 vendor/rector/rector/src/Console/Command/WorkerCommand.php(73):
         RectorPrefix202309\React\EventLoop\StreamSelectLoop->run()
         #26 vendor/rector/rector/vendor/symfony/console/Command/Command.php(327):
         Rector\Core\Console\Command\WorkerCommand->execute(Object(RectorPrefix202309\Symfony\Component\Console\Input\A
         rgvInput), Object(RectorPrefix202309\Symfony\Component\Console\Output\ConsoleOutput))
         #27 vendor/rector/rector/vendor/symfony/console/Application.php(944):
         RectorPrefix202309\Symfony\Component\Console\Command\Command->run(Object(RectorPrefix202309\Symfony\Component\
         Console\Input\ArgvInput), Object(RectorPrefix202309\Symfony\Component\Console\Output\ConsoleOutput))
         #28 vendor/rector/rector/vendor/symfony/console/Application.php(326):
         RectorPrefix202309\Symfony\Component\Console\Application->doRunCommand(Object(Rector\Core\Console\Command\Work
         erCommand), Object(RectorPrefix202309\Symfony\Component\Console\Input\ArgvInput),
         Object(RectorPrefix202309\Symfony\Component\Console\Output\ConsoleOutput))
         #29 vendor/rector/rector/src/Console/ConsoleApplication.php(61):
         RectorPrefix202309\Symfony\Component\Console\Application->doRun(Object(RectorPrefix202309\Symfony\Component\Co
         nsole\Input\ArgvInput), Object(RectorPrefix202309\Symfony\Component\Console\Output\ConsoleOutput))
         #30 vendor/rector/rector/vendor/symfony/console/Application.php(212):
         Rector\Core\Console\ConsoleApplication->doRun(Object(RectorPrefix202309\Symfony\Component\Console\Input\ArgvIn
         put), Object(RectorPrefix202309\Symfony\Component\Console\Output\ConsoleOutput))
         #31 vendor/rector/rector/bin/rector.php(132): RectorPrefix202309\Symfony\Component\Console\Application->run()
         #32 vendor/rector/rector/bin/rector(5): require_once('/projects/yiiso...')
         #33 vendor/bin/rector(119): include('/projects/yiiso...')
         #34 {main}". On line: 56

PHP code:

use Stringable;

final class StringableObject implements Stringable
{
    public function __construct(
        private string $string,
    ) {
    }

    public function __toString(): string
    {
        return $this->string;
    }
}

Expected Behaviour

No errors.

@samsonasik
Copy link
Member

Hi, could you reproduce at https://getrector.com/demo with provide single/two rules that cause it? Thank you.

@vjik
Copy link
Author

vjik commented Sep 11, 2023

Hi, could you reproduce at https://getrector.com/demo with provide single/two rules that cause it? Thank you.

I couldn't reproduce it there. May be demo use PHP not 8.0 version. There is error in PHP 8.0 only.

@samsonasik
Copy link
Member

@vjik that seems due to read jetbrains/phpstorm-stubs in AstResolver

php80 vendor/bin/rector process src/StringableObject.php --dry-run --clear-cache
 0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%string(226) "phar:///Users/samsonasik/www/rector-custom/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/../../../../../jetbrains/phpstorm-stubs/Core/Core_c.stub"
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
                                                                                                                        
 [ERROR] Could not process "src/StringableObject.php" file, due to:                                                     
         "System error: "Syntax error, unexpected T_STRING, expecting T_VARIABLE906, Syntax error, unexpected T_STRING, 
         expecting T_VARIABLE920, Syntax error, unexpected T_STRING, expecting T_VARIABLE945, Syntax error, unexpected  
         T_STRING, expecting T_VARIABLE970, Syntax error, unexpected T_STRING, expecting T_VARIABLE1119"                
         Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 56
                                                                                                                        

Try catch may be needed

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