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

Rector prefixed 0.8.56: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found #4736

Closed
simivar opened this issue Nov 30, 2020 · 21 comments
Labels

Comments

@simivar
Copy link
Contributor

simivar commented Nov 30, 2020

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.

@simivar simivar added the bug label Nov 30, 2020
@simivar
Copy link
Contributor Author

simivar commented Nov 30, 2020

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.

@michaljusiega
Copy link

No, is not related to PHPStan issue.

@staabm
Copy link
Contributor

staabm commented Nov 30, 2020

duplicates #4725

@simivar
Copy link
Contributor Author

simivar commented Nov 30, 2020

It doesn't duplicates #4725 as I have it installed as a normal Composer dependency, not a global one.

@staabm
Copy link
Contributor

staabm commented Nov 30, 2020

Sorry „duplicates“ was the wrong wording. It seems to be the same error though :)

@bbouabou
Copy link

bbouabou commented Dec 7, 2020

Hello,

Did there is any workaround to use rector to upgrade a symfony 2.8 project ?

@simivar
Copy link
Contributor Author

simivar commented Dec 7, 2020

@TomasVotruba could you help us with this issue?

@TomasVotruba
Copy link
Member

TomasVotruba commented Dec 7, 2020

@simivar Basically, this PR needs to be finished: #4559
The fix is included there. I'm busy with other work, so no ETA on it. Any help is welcomed there.

@arnaud-fr
Copy link

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.

@TomasVotruba
Copy link
Member

Resolved by #4559

@u01jmg3
Copy link
Contributor

u01jmg3 commented Jan 6, 2021

Still seeing this problem on 0.9.5

@TomasVotruba
Copy link
Member

We'll need a reproducible repository to verify

@Aerendir
Copy link
Contributor

Aerendir commented Jan 11, 2021

@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

  1. Clone the repo locally
  2. Switch to dev branch
  3. Run vendor/bin/rector process --dry-run

@Aerendir
Copy link
Contributor

Aerendir commented Jan 11, 2021

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

@staabm
Copy link
Contributor

staabm commented Jan 11, 2021

it seems the mentioned fix is the same as the one I suggested in #4726

@Aerendir
Copy link
Contributor

@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...

@Aerendir
Copy link
Contributor

@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.

Aerendir added a commit to Aerendir/component-array-writer that referenced this issue Jan 11, 2021
@TomasVotruba
Copy link
Member

TomasVotruba commented Jan 11, 2021

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.

Aerendir added a commit to Aerendir/component-array-writer that referenced this issue Jan 11, 2021
@Aerendir
Copy link
Contributor

Ok, so Phive to the rescue!

@Aerendir
Copy link
Contributor

Aerendir commented Jan 11, 2021

Also if this makes really complex to stay up to date as Dependabot doesn't support Phive I think 🤔

@TomasVotruba
Copy link
Member

TomasVotruba commented Jan 11, 2021

Phive is packaged phar, that's what we droppped in 0.9 - Why? See https://getrector.org/blog/2020/12/28/rector-09-released#debuggable-rector-prefixed

This is prefixed Rector now: https://github.com/rectorphp/rector-prefixed

We go for the future of downgraded and prefixed version. Thank's to that Rector will be able to run on PHP 5.6 in composer and without Docker.

TomasVotruba added a commit that referenced this issue Aug 9, 2023
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

8 participants