Rector: Rector-Prefixed 0.8.50 not compatible with PHPStan PHAR

Created on 14 Nov 2020  路  14Comments  路  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | 0.8.50 |
| Installed as | prefixed Rector PHAR |

Fatal error: Cannot redeclare PHPStan\dumpType() (previously declared in phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/phpstan/phpstan-src/src/dumpType.php:9) in phar:///var/www/intranet/vendor/phpstan/phpstan/phpstan.phar/src/dumpType.php on line 9

Call Stack:
    0.0194     355632   1. {main}() /var/www/intranet/vendor/rector/rector-prefixed/rector:0
    0.1129    7362112   2. require('phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/bin/rector') /var/www/intranet/vendor/rector/rector-prefixed/rector:6
    0.2181    7545440   3. _HumbugBox56c424d11509\AutoloadIncluder->includeDependencyOrRepositoryVendorAutoloadIfExists() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/bin/rector:33
    0.2182    7545400   4. _HumbugBox56c424d11509\AutoloadIncluder->loadIfNotLoadedYet() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/bin/rector:94
    0.2212    7545920   5. require_once('phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/autoload.php') phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/bin/rector:143
    0.2573    7620192   6. class_exists() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/autoload.php:17
    0.2573    7620256   7. spl_autoload_call() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/autoload.php:17
    0.2576    7620320   8. {closure:/var/www/intranet/vendor/phpstan/phpstan/bootstrap.php:3-46}() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/autoload.php:17
    0.3900   10339952   9. require('phar:///var/www/intranet/vendor/phpstan/phpstan/phpstan.phar/vendor/autoload.php') /var/www/intranet/vendor/phpstan/phpstan/bootstrap.php:15
    0.3957   10348400  10. ComposerAutoloaderInit1b31f9ba3c6a9ade651b8f50c04f5966::getLoader() phar:///var/www/intranet/vendor/phpstan/phpstan/phpstan.phar/vendor/autoload.php:9
    0.4027   10349088  11. composerRequire1b31f9ba3c6a9ade651b8f50c04f5966() phar:///var/www/intranet/vendor/phpstan/phpstan/phpstan.phar/vendor/composer/autoload_real.php:50

Minimal PHP Code Causing Issue

./vendor/bin/rector show -c rector.php

Expected Behaviour

Should show actual configuration. Downgrade to 0.8.48 not generate above issue.

Additional content

composer show
phpstan/phpstan                      0.12.54   PHPStan - PHP Static Analysis Tool
rector/rector-prefixed               0.8.50    Prefixed version of Rector compiled in PHAR
bug prefixed

Most helpful comment

@TomasVotruba

I see now, 0.8.56 has extracted files from .phar file, shouldn't it be that there are 6000+ files for one .phar?
https://github.com/rectorphp/rector-prefixed/compare/0.8.52...0.8.56

Now there is this problem:

root@c1c331a7a54e:/var/www/intranet# ./vendor/bin/rector show -c rector.php

Fatal error: Uncaught Error: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found in /var/www/intranet/vendor/rector/rector-prefixed/bin/rector on line 39

Error: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found in /var/www/intranet/vendor/rector/rector-prefixed/bin/rector on line 39

Call Stack:
    0.0010     382448   1. {main}() /var/www/intranet/vendor/rector/rector-prefixed/bin/rector:0

All 14 comments

Hi,

thanks for reporting.
How exactly (bash command) have you installed the Rector?

How does rector/rector-prefixed:dev-master perform?

Hi,

just added entry in composer.json if that's what you mean:

    "require-dev": {
        "phpstan/phpstan": "^0.12",
        "phpunit/phpunit": "^9.4",
        "phpunit/phpcov": "^8.2",
        "rector/rector-prefixed": "^0.8",
        "squizlabs/php_codesniffer": "^3.5",
        "symfony/panther": "^0.8",
        "symfony/phpunit-bridge": "^5.1"
    },

Dev-Master:

root@3480654d8830:/var/www/intranet# composer show | grep rector && ./vendor/bin/rector show -c rector.php
rector/rector-prefixed               dev-master 58dcb0e Prefixed version of Rector compiled in PHAR

Fatal error: Cannot redeclare PHPStan\dumpType() (previously declared in phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/phpstan/phpstan-src/src/dumpType.php:9) in phar:///var/www/intranet/vendor/phpstan/phpstan/phpstan.phar/src/dumpType.php on line 9

Call Stack:
    0.0171     355632   1. {main}() /var/www/intranet/vendor/rector/rector-prefixed/rector:0
    0.1093    7365032   2. require('phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/bin/rector') /var/www/intranet/vendor/rector/rector-prefixed/rector:6
    0.2067    7548360   3. _HumbugBoxdb6b4f532663\AutoloadIncluder->includeDependencyOrRepositoryVendorAutoloadIfExists() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/bin/rector:33
    0.2067    7548320   4. _HumbugBoxdb6b4f532663\AutoloadIncluder->loadIfNotLoadedYet() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/bin/rector:94
    0.2092    7548840   5. require_once('phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/autoload.php') phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/bin/rector:143
    0.2436    7623112   6. class_exists() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/autoload.php:17
    0.2436    7623176   7. spl_autoload_call() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/autoload.php:17
    0.2436    7623240   8. {closure:/var/www/intranet/vendor/phpstan/phpstan/bootstrap.php:3-46}() phar:///var/www/intranet/vendor/rector/rector-prefixed/rector/vendor/autoload.php:17
    0.4527   10342872   9. require('phar:///var/www/intranet/vendor/phpstan/phpstan/phpstan.phar/vendor/autoload.php') /var/www/intranet/vendor/phpstan/phpstan/bootstrap.php:15
    0.4541   10351320  10. ComposerAutoloaderInit1b31f9ba3c6a9ade651b8f50c04f5966::getLoader() phar:///var/www/intranet/vendor/phpstan/phpstan/phpstan.phar/vendor/autoload.php:9
    0.4577   10352008  11. composerRequire1b31f9ba3c6a9ade651b8f50c04f5966() phar:///var/www/intranet/vendor/phpstan/phpstan/phpstan.phar/vendor/composer/autoload_real.php:50

0.8.48:

root@3480654d8830:/var/www/intranet# composer show | grep rector && ./vendor/bin/rector show -c rector.php
rector/rector-prefixed               0.8.48    Prefixed version of Rector compiled in PHAR
Rector 0.8.48
Config file: rector.php


Loaded Rector rules
===================

 * Rector\CodingStyle\Rector\FuncCall\FunctionCallToConstantRector
      functionsToConstants: {  }

 * Rector\Php74\Rector\FuncCall\GetCalledClassToStaticClassRector
 * Rector\Php74\Rector\Class_\ClassConstantToSelfClassRector
 * Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector
 * Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector
 * Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector
 * Rector\CodeQuality\Rector\Identical\GetClassToInstanceOfRector
 * Rector\CodeQuality\Rector\Ternary\ArrayKeyExistsTernaryThenValueToCoalescingRector
 * Rector\Performance\Rector\FuncCall\PreslashSimpleFunctionRector
 * Rector\CodeQuality\Rector\FuncCall\ArrayKeysAndInArrayToArrayKeyExistsRector
 * Rector\CodeQuality\Rector\Catch_\ThrowWithPreviousExceptionRector


 [OK] 11 loaded Rectors                                                                                                 

I see, thanks. Seems like autoload.php is added twice for some reason :/

PHPStan is needed in Rector-Prefixed ?

Rector depends on PHPStan, so yes.

@TomasVotruba There is some feedback ? ;)

Not sure what you mean. Reproducible repository with failing Github Action would speed this up though :)

Ok, I will try to prepare a test environment with error reproduction in my free time;)

Thank you

Hi!

I came across this error using phpstan/phpstan 0.12.56 along with rector/rector-prefixed 0.8.52 or the dowloaded rector.phar.

Just for the record before I try to continue later to check what's going on.

phpstan/phpstan have a bootstrap.php file that is autoloaded which contains a specific part for HumbugBox in a spl_autoload_register() function:

if (strpos($class, '_HumbugBox') === 0) {
    if (!in_array('phar', stream_get_wrappers(), true)) {
        throw new \Exception('Phar wrapper is not registered. Please review your php.ini settings.');
    }
    if ($composerAutoloader === null) {
        $composerAutoloader = require 'phar://' . __DIR__ . '/phpstan.phar/vendor/autoload.php';
        require_once 'phar://' . __DIR__ . '/phpstan.phar/vendor/clue/block-react/src/functions_include.php';
        require_once 'phar://' . __DIR__ . '/phpstan.phar/vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php';
        require_once 'phar://' . __DIR__ . '/phpstan.phar/vendor/react/promise-stream/src/functions_include.php';
        require_once 'phar://' . __DIR__ . '/phpstan.phar/vendor/react/promise-timer/src/functions_include.php';
        require_once 'phar://' . __DIR__ . '/phpstan.phar/vendor/react/promise/src/functions_include.php';
        require_once 'phar://' . __DIR__ . '/phpstan.phar/vendor/ringcentral/psr7/src/functions_include.php';
    }
    $composerAutoloader->loadClass($class);
    return;
}

When I comment the part

$composerAutoloader = require 'phar://' . __DIR__ . '/phpstan.phar/vendor/autoload.php';

I'm able to execute rector (and $composerAutoloader->loadClass($class); is commented too of course).
(./bin/rector list takes nearly 5min to execute but at least it is a start 馃槄 )

Thank you @brambaud very much !

@TomasVotruba

I see now, 0.8.56 has extracted files from .phar file, shouldn't it be that there are 6000+ files for one .phar?
https://github.com/rectorphp/rector-prefixed/compare/0.8.52...0.8.56

Now there is this problem:

root@c1c331a7a54e:/var/www/intranet# ./vendor/bin/rector show -c rector.php

Fatal error: Uncaught Error: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found in /var/www/intranet/vendor/rector/rector-prefixed/bin/rector on line 39

Error: Class 'Rector\Core\Console\Style\SymfonyStyleFactory' not found in /var/www/intranet/vendor/rector/rector-prefixed/bin/rector on line 39

Call Stack:
    0.0010     382448   1. {main}() /var/www/intranet/vendor/rector/rector-prefixed/bin/rector:0

The last issue is duplicate of
https://github.com/rectorphp/rector/issues/4736

Was this page helpful?
0 / 5 - 0 ratings