Rector prefixed 0.8.56: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found
Bug Report
| Subject | Details |
|---|---|
| Rector version | 0.8.56 |
| Installed as | prefixed Rector PHAR |
While trying to run a Rector with vendor/bin/rector there's an error happening:
❯ vendor/bin/rector
PHP Fatal error: Uncaught Error: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found in /Users/[...]/vendor/rector/rector-prefixed/bin/rector:39
Stack trace:
#0 {main}
thrown in /Users/[...]/vendor/rector/rector-prefixed/bin/rector on line 39
Fatal error: Uncaught Error: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found in /Users/[...]/vendor/rector/rector-prefixed/bin/rector:39
Stack trace:
#0 {main}
thrown in /Users/[...]vendor/rector/rector-prefixed/bin/rector on line 39
Minimal PHP Code Causing Issue
Expected Behaviour
Rector running properly.
I've seen @michaljusiega comment in #4606 but I feel like this is a separate issue not related to PHPStan. I came across that comment by luck and feel that a separate ticket will be easier to find and track for others so they know when it's fixed.
No, is not related to PHPStan issue.
duplicates https://github.com/rectorphp/rector/issues/4725
It doesn't duplicates #4725 as I have it installed as a normal Composer dependency, not a global one.
Sorry „duplicates“ was the wrong wording. It seems to be the same error though :)
Hello,
Did there is any workaround to use rector to upgrade a symfony 2.8 project ?
@TomasVotruba could you help us with this issue?
@simivar Basically, this PR needs to be finished: https://github.com/rectorphp/rector/pull/4559 The fix is included there. I'm busy with other work, so no ETA on it. Any help is welcomed there.
Hello,
Did there is any workaround to use rector to upgrade a symfony 2.8 project ?
A suggested workaround : use the previous version 0.8.52 wich is based on a phar.
If you current environment contains version 0.8.56, first of all remove it : composer remove rector/rector-prefixed.
Then install the previous version : composer require rector/rector-prefixed 0.8.52
Note : the command init does not work in this version. You will have to copy the rector.php.dist by hand in your main directory.
Resolved by https://github.com/rectorphp/rector/pull/4559
Still seeing this problem on 0.9.5
We'll need a reproducible repository to verify
@TomasVotruba , I have the same error, also if I use Bamarni composer bin plugin.
But my repo is public: https://github.com/Aerendir/component-array-writer
It is only one class, so is perfect for debugging...
I'm trying to solve the issue, but I have no idea where to start... Maybe you can having more experience with the issue that seems already happened...
To reproduce
- Clone the repo locally
- Switch to
devbranch - Run
vendor/bin/rector process --dry-run
Ok, the first problem seems to be in vendor/rector/rector/bin/rector.php:104
/**
* In case Rector is installed as vendor dependency,
* this autoloads the project vendor/autoload.php, including Rector
*/
public function autoloadProjectAutoloaderFile(): void
{
$this->loadIfExistsAndNotLoadedYet(__DIR__ . '/../../autoload.php');
+ $this->loadIfExistsAndNotLoadedYet(__DIR__ . '/../../../../vendor/autoload.php');
}
As I'm using Bamarni Bin Composer plugin, the hard coded path is not correct as Rector is actually installed in vendor-bin/phpstan/vendor/rector/rector.
For this reason we need to go some levels up in the tree.
Adding the change proposed, the error changes to:
PHP Fatal error: Uncaught TypeError: Symplify\PackageBuilder\Reflection\PrivatesCaller::callPrivateMethod(): Argument #3 ($arguments) must be of type array, Symfony\Component\Console\Input\ArgvInput given, called in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/src/Console/Style/SymfonyStyleFactory.php on line 32 and defined in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symplify/package-builder/src/Reflection/PrivatesCaller.php:20
Stack trace:
#0 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/src/Console/Style/SymfonyStyleFactory.php(32): Symplify\PackageBuilder\Reflection\PrivatesCaller->callPrivateMethod(Object(Symfony\Component\Console\Application), 'configureIO', Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/bin/rector.php(39): Rector\Core\Console\Style\SymfonyStyleFactory->create()
#2 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/bin/rector(4): require_once('/Users/Aerendir...')
#3 {main}
thrown in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symplify/package-builder/src/Reflection/PrivatesCaller.php on line 20
Fatal error: Uncaught TypeError: Symplify\PackageBuilder\Reflection\PrivatesCaller::callPrivateMethod(): Argument #3 ($arguments) must be of type array, Symfony\Component\Console\Input\ArgvInput given, called in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/src/Console/Style/SymfonyStyleFactory.php on line 32 and defined in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symplify/package-builder/src/Reflection/PrivatesCaller.php:20
Stack trace:
#0 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/src/Console/Style/SymfonyStyleFactory.php(32): Symplify\PackageBuilder\Reflection\PrivatesCaller->callPrivateMethod(Object(Symfony\Component\Console\Application), 'configureIO', Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/bin/rector.php(39): Rector\Core\Console\Style\SymfonyStyleFactory->create()
#2 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/bin/rector(4): require_once('/Users/Aerendir...')
#3 {main}
thrown in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symplify/package-builder/src/Reflection/PrivatesCaller.php on line 20
it seems the mentioned fix is the same as the one I suggested in https://github.com/rectorphp/rector/pull/4726
@staabm , similar, not the same: your attempt was to support global install; mine supports installation through Bamarni Composer Bin, that is anyway at project level...
@TomasVotruba , the problem seems to be in Symplify.
I changed this:
/**
* @param object|string $object
* @param mixed[] $arguments
*/
- public function callPrivateMethod($object, string $methodName, array $arguments)
+ public function callPrivateMethod($object, string $methodName, $arguments)
{
$this->ensureIsNotNull($object, __METHOD__);
if (is_string($object)) {
$reflectionClass = new ReflectionClass($object);
$object = $reflectionClass->newInstanceWithoutConstructor();
}
$methodReflection = $this->createAccessibleMethodReflection($object, $methodName);
+ if ($arguments instanceof ArgvInput) {
+ $arguments = $arguments->getArguments();
+ }
return $methodReflection->invokeArgs($object, $arguments);
}
But now I have other errors:
Aerendir@Archimede component-array-writer % vendor/bin/rector process --dry-run
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Symfony\Component\Console\Application::configureIO(), 0 passed and exactly 2 expected in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symfony/console/Application.php:880
Stack trace:
#0 [internal function]: Symfony\Component\Console\Application->configureIO()
#1 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symplify/package-builder/src/Reflection/PrivatesCaller.php(36): ReflectionMethod->invokeArgs(Object(Symfony\Component\Console\Application), Array)
#2 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/src/Console/Style/SymfonyStyleFactory.php(32): Symplify\PackageBuilder\Reflection\PrivatesCaller->callPrivateMethod(Object(Symfony\Component\Console\Application), 'configureIO', Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/bin/rector.php(39): Rector\Core\Console\Style\SymfonyStyleFactory->create()
#4 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/bin/rector(4): require_once('/Users/Aerendir...')
#5 {main}
thrown in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symfony/console/Application.php on line 880
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Symfony\Component\Console\Application::configureIO(), 0 passed and exactly 2 expected in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symfony/console/Application.php:880
Stack trace:
#0 [internal function]: Symfony\Component\Console\Application->configureIO()
#1 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symplify/package-builder/src/Reflection/PrivatesCaller.php(36): ReflectionMethod->invokeArgs(Object(Symfony\Component\Console\Application), Array)
#2 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/src/Console/Style/SymfonyStyleFactory.php(32): Symplify\PackageBuilder\Reflection\PrivatesCaller->callPrivateMethod(Object(Symfony\Component\Console\Application), 'configureIO', Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/bin/rector.php(39): Rector\Core\Console\Style\SymfonyStyleFactory->create()
#4 /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/rector/rector/bin/rector(4): require_once('/Users/Aerendir...')
#5 {main}
thrown in /Users/Aerendir/Documents/JooServer/Lab/Components/component-array-writer/vendor-bin/phpstan/vendor/symfony/console/Application.php on line 880
The problem seems to be deeper than what it appeared at a first sight.
Neither barmani or global installation is supported. If paths will be resolved, the different vendor directory name or double nesting or package conflicts will appear. We've experienced that in various private projects, before the prefixed Rector was available.
Now prefixed version is way to go here.
Ok, so Phive to the rescue!
Also if this makes really complex to stay up to date as Dependabot doesn't support Phive I think 🤔