rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.78k stars 688 forks source link

rector-prefixed 0.7 throw '...PhpStormStubsMap' errors #2879

Closed shaal closed 4 years ago

shaal commented 4 years ago
Subject Details
Rector version v0.7
PHP version PHP 7.3.11
Full Command vendor/bin/rector process web/modules/contrib/config_filter --set dead-code --dry-run
Demo link
rector.yaml (see below)
parameters:
  autoload_paths:
    - 'web/core'
    - 'web/core/modules'
    - 'web/modules'
    - 'web/profiles'

  file_extensions:
    - module
    - theme
    - install
    - profile
    - inc
    - engine

Current Behaviour

Installing Drupal8 and adding rector-prefixed 0.6.13 works as expected Steps to replicate:

The output is correct and it display the diff of berfore/after the rector

1 file with changes
===================

1) web/core/modules/aggregator/src/Plugin/views/row/Rss.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -66,14 +66,12 @@
         'attributes' => ['isPermaLink' => 'false'],
       ],
     ];
-
-    $build = [
+    return [
       '#theme' => $this->themeFunctions(),
       '#view' => $this->view,
       '#options' => $this->options,
       '#row' => $item,
     ];
-    return $build;
   }

 }
    ----------- end diff -----------

Applied rules:

 * Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector

But upgrading to rector-prefix v0.7 is causing problems:

 [ERROR] Could not process "web/core/modules/aggregator/src/Plugin/views/row/Rss.php" file, due to: "Class '_HumbugBox46c80243413c\JetBrains\PHPStormStub\PhpStormStubsMap' not found".                            

 [ERROR] Could not process "web/core/modules/aggregator/src/Plugin/views/row/Rss.php" file, due to: "Call to a member function hasByType() on null".                                                               

report from command line with --debug vendor/bin/rector process web/core/modules/aggregator/src/Plugin/views/row/Rss.php --set deadcode --dry-run --debug

File "/Users/shaal/code/test/my_site_name_dir/vendor/autoload.php" is about to be loaded in "_HumbugBox46c80243413c\AutoloadIncluder::includeCwdVendorAutoloadIfExists()" on line 53"
File "/Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/../../autoload.php" is about to be loaded in "_HumbugBox46c80243413c\AutoloadIncluder::autoloadProjectAutoloaderFile()" on line 86"
File "phar://rector.phar/vendor/autoload.php" is about to be loaded in "_HumbugBox46c80243413c\AutoloadIncluder::includeDependencyOrRepositoryVendorAutoloadIfExists()" on line 65"
File "/Users/shaal/code/test/my_site_name_dir/vendor/autoload.php" is about to be loaded in "_HumbugBox46c80243413c\AutoloadIncluder::includeCwdVendorAutoloadIfExists()" on line 53"
File "/Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/../../autoload.php" is about to be loaded in "_HumbugBox46c80243413c\AutoloadIncluder::autoloadProjectAutoloaderFile()" on line 86"
File "phar://rector.phar/vendor/autoload.php" is about to be loaded in "_HumbugBox46c80243413c\AutoloadIncluder::includeDependencyOrRepositoryVendorAutoloadIfExists()" on line 65"
Rector v0.7.0
Config file: rector.yml

[parsing] web/core/modules/aggregator/src/Plugin/views/row/Rss.php
PHP Fatal error:  Uncaught Error: Class '_HumbugBox46c80243413c\JetBrains\PHPStormStub\PhpStormStubsMap' not found in phar:///Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/rector/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:67
Stack trace:
#0 phar:///Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/rector/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(38): _HumbugBox46c80243413c\Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber->generateClassStub('key')
#1 phar:///Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/rector/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(31): _HumbugBox46c80243413c\Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator->getClassSource(Object(_HumbugBox46c80243413c\Roave\BetterReflection\Identifier\Identifier))
#2 phar:///Users/shaal/code/test/my_site_name_dir in phar:///Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/rector/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php on line 67
Fatal error: Uncaught Error: Class '_HumbugBox46c80243413c\JetBrains\PHPStormStub\PhpStormStubsMap' not found in phar:///Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/rector/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:67
Stack trace:
#0 phar:///Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/rector/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(38): _HumbugBox46c80243413c\Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber->generateClassStub('key')
#1 phar:///Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/rector/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(31): _HumbugBox46c80243413c\Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator->getClassSource(Object(_HumbugBox46c80243413c\Roave\BetterReflection\Identifier\Identifier))
#2 phar:///Users/shaal/code/test/my_site_name_dir in phar:///Users/shaal/code/test/my_site_name_dir/vendor/rector/rector-prefixed/rector/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php on line 67

Minimal PHP Code Causing Issue

```php
shaal commented 4 years ago
TomasVotruba commented 4 years ago

Could you send Github Action just for this so we have it covered?

shaal commented 4 years ago

I am not familiar with Github Action. How do I send it?

TomasVotruba commented 4 years ago
shaal commented 4 years ago

On additional testing locally, I found that when I install rector/rector v0.7 in a separate directory, outside of Drupal project, works as expected with no errors. But rector/rector-prefixed v0.7 - throw the error messages on top of this issue.

TomasVotruba commented 4 years ago

I'd love to look at it. Failing CI is needed.

shaal commented 4 years ago

Well... currently CI is failing but not because of Rector... I still can't figure out how to set it up correctly / or debug it.

TomasVotruba commented 4 years ago

@ondrejmirtes Hi Ondra, the PhpStormStubsMap is still there. Any idea why?

ondrejmirtes commented 4 years ago

I just compared how rector.phar vs. phpstan.phar looks like:

Rector:

PhpStormStubsMap.php - NOT inside prefixed _HumbugBox namespace PhpStormStubsSourceStubber.php - uses PhpStormStubsMap prefixed with _HumbugBox, leading to the error in OP.

PHPStan:

PhpStormStubsMap.php - inside prefixed _HumbugBox namespace PhpStormStubsSourceStubber.php - uses PhpStormStubsMap prefixed with _HumbugBox, so it's consistent and does not lead to an error.

This PhpStormStubsMap is not whitelisted from prefixing thanks to this line (https://github.com/phpstan/phpstan-src/blob/e18b3b47c8e1b91f1844dd3c91d961e912476d86/compiler/build/scoper.inc.php#L16-L18) so I guess that Rector's PHP-Scoper prefixing process is somehow broken.

@TomasVotruba You should be able to debug these issues yourself, if you consider Rector's PHAR file first-class citizen. Of course if the cause is in PHPStan itself, I'm happy to help you. But in this case it doesn't seem PHPStan's fault.

TomasVotruba commented 4 years ago
TomasVotruba commented 4 years ago

@ondrejmirtes Thanks for the check. I have exact the same lines in scoper.inc.php:

https://github.com/rectorphp/rector/blob/37cd497baff6a6ff0aacb485732bb8db0dfd2fe6/compiler/build/scoper.inc.php#L22-L30

Or is there any difference?

ondrejmirtes commented 4 years ago

I don't know, try debugging to see why it's happening what's happening...

TomasVotruba commented 4 years ago

How do you debug scoper? I don't use xdebug and I have troubles just using it. Error messages are very random to me

TomasVotruba commented 4 years ago

So according to CI: https://travis-ci.org/rectorphp/rector/builds/655444246?utm_source=github_status&utm_medium=notification

The PhpStormStubsMap.php is not there at all :D

TomasVotruba commented 4 years ago

I've solved it by adding it as a dependency + renaming stubs as you recommended.

Locally it works... but in Travis CI it fails, on missing rectorphp/rector/compiler/bin/../../vendor/je tbrains/phpstorm-stubs directory... no idea why :/

image

https://travis-ci.org/rectorphp/rector/builds/655482789#L322