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.7 throw '...PhpStormStubsMap' errors #2879

Closed
shaal opened this issue Feb 18, 2020 · 15 comments · Fixed by #2941
Closed

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

shaal opened this issue Feb 18, 2020 · 15 comments · Fixed by #2941

Comments

@shaal
Copy link
Contributor

shaal commented Feb 18, 2020

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:

  • composer create-project drupal/recommended-project drupal8
  • cd drupal8
  • composer require rector/rector-prefixed:0.6.13 --dev
  • (create the rector.yaml above)
  • vendor/bin/rector process web/core/modules/aggregator/src/Plugin/views/row/Rss.php --set deadcode --dry-run

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:

  • composer require rector/rector-prefixed:0.7 --dev
  • vendor/bin/rector process web/core/modules/aggregator/src/Plugin/views/row/Rss.php --set deadcode --dry-run
 [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 

// put file content here

Expected Behaviour

@shaal shaal changed the title rector-prefixed 0.7 throw ...PhpStormStubsMap errors rector-prefixed 0.7 throw '...PhpStormStubsMap' errors Feb 18, 2020
@shaal
Copy link
Contributor Author

shaal commented Feb 18, 2020

Related issues:
#2749
#2816

@TomasVotruba
Copy link
Member

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

@shaal
Copy link
Contributor Author

shaal commented Feb 18, 2020

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

@TomasVotruba
Copy link
Member

Basically copy this file:

run: |
# cannot install dev deps (--no-dev), because doctrine/orm might inherit from them in different version
composer install --no-progress --no-dev
git clone https://github.com/doctrine/orm.git
# older version have breaking "object" type
composer require doctrine/cache:^1.10 -d orm --no-update
# remove phsptan config to prevent rector loading configs
rm phpstan.neon
rm orm/phpstan.neon.dist
# do not intall doctrine/orm phpstan, it conflicts with Retor's one
composer install -d orm --no-dev

and replace run part with your commands

@shaal
Copy link
Contributor Author

shaal commented Feb 20, 2020

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
Copy link
Member

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

@shaal
Copy link
Contributor Author

shaal commented Feb 20, 2020

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
Copy link
Member

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

@ondrejmirtes
Copy link
Contributor

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
Copy link
Member

@shaal I made the CI fail finally: https://github.com/rectorphp/rector-prefixed/runs/470008289

@TomasVotruba
Copy link
Member

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

foreach ($stubFinder->getIterator() as $fileInfo) {
// mirrors https://github.com/phpstan/phpstan-src/commit/04f777bc4445725d17dac65c989400485454b145
if ($fileInfo->getPathName() === '../../vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php') {
continue;
}
/** @var SplFileInfo $fileInfo */
$stubs[] = $fileInfo->getPathName();
}

Or is there any difference?

@ondrejmirtes
Copy link
Contributor

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

@TomasVotruba
Copy link
Member

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
Copy link
Member

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
Copy link
Member

TomasVotruba commented Feb 26, 2020

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

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

Successfully merging a pull request may close this issue.

3 participants