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

Prefixed Rector PHAR not working #2749

Closed
theofidry opened this issue Jan 23, 2020 · 43 comments · Fixed by #2844
Closed

Prefixed Rector PHAR not working #2749

theofidry opened this issue Jan 23, 2020 · 43 comments · Fixed by #2844

Comments

@theofidry
Copy link

Subject Details
Rector version Rector 0.6.x-dev@262e8d8
PHP version 7.2.18
Full Command See below
Demo link https://github.com/infection/infection
rector.yaml See below
$ php rector.phar process /Users/tfidry/Project/Humbug/infection/src/Config/Exception/InvalidConfigException.php --dry-run --set=dead-classes -vvv
rector.yaml
parameters:
    paths:
        - 'src'
        - 'tests'

    exclude_rectors:
        - 'Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector'

    autoload_paths:
        - 'vendor/autoload.php'

    exclude_paths:
        - 'tests/e2e/**/*'

Current behaviour

Rector 0.6.x-dev@262e8d8
Config file: rector.yaml

[parsing] src/Config/Exception/InvalidConfigException.php
PHP Fatal error:  Uncaught Error: Class '_HumbugBox60f4f031e4cc\JetBrains\PHPStormStub\PhpStormStubsMap' not found in phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:67
Stack trace:
#0 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(38): _HumbugBox60f4f031e4cc\Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber->generateClassStub('self')
#1 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(31): _HumbugBox60f4f031e4cc\Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator->getClassSource(Object(_HumbugBox60f4f031e4cc\Roave\BetterReflection\Identifier\Identifier))
#2 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/Abst in phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php on line 67
Fatal error: Uncaught Error: Class '_HumbugBox60f4f031e4cc\JetBrains\PHPStormStub\PhpStormStubsMap' not found in phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:67
Stack trace:
#0 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(38): _HumbugBox60f4f031e4cc\Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber->generateClassStub('self')
#1 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(31): _HumbugBox60f4f031e4cc\Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator->getClassSource(Object(_HumbugBox60f4f031e4cc\Roave\BetterReflection\Identifier\Identifier))
#2 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/Abst in phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php on line 67
@theofidry
Copy link
Author

I got a report from PHPStan that its PHAR had an issue with the jetbrains stubs: they were being removed by dg/composer-cleaner. So it might be related, I have no idea; the above command works fine with the non-prefixed version

@ondrejmirtes
Copy link
Contributor

Looks like this issue is from dev-master of PHPStan. Not sure why Rector uses that. I fixed it yesterday evening.

@ondrejmirtes
Copy link
Contributor

I probably realize why - building Rector PHAR consists of cloning and using phpstan-src. But it should check out a stable tag, not use master...

@ondrejmirtes
Copy link
Contributor

I understand now - the root issue is that I released ondrejmirtes/better-reflection 3.5.6 that breaks this by using newer jetbrains/phpstorm-stubs. These two commits fix that:

@ondrejmirtes
Copy link
Contributor

I'll probably start requiring ondrejmirtes/better-reflection without ^.

@ondrejmirtes
Copy link
Contributor

Again, this is why I think no one should use phpstan-src directly :)

@ondrejmirtes
Copy link
Contributor

And there's another one: phpstan/phpstan-src@23d5ca0

@theofidry
Copy link
Author

huh Hoa is such a pain... (for PHP-Scoper)

@ondrejmirtes
Copy link
Contributor

Yes, it is, but I realized, it doesn't have to be prefixed in the PHAR since PHPStan already knows how to do static reflection partially...

@TomasVotruba
Copy link
Member

Any idea how to fix this?

@ondrejmirtes
Copy link
Contributor

You need to update your scoper.php.inc when prefixing PHPStan the same way I did.

@TomasVotruba
Copy link
Member

Allright, I'll give a try to the unboxing :)

@escopecz
Copy link
Contributor

escopecz commented Jan 31, 2020

A way around until it's fixed is to downgrade. composer require --dev rector/rector-prefixed:0.6.13

@TomasVotruba
Copy link
Member

@ondrejmirtes Just trying the update to PHPStan 0.12.8 and running only phpstan.phar doesn't work here. See failing Github action: https://github.com/rectorphp/rector/pull/2800/checks?check_run_id=425544838#step:5:6

It's not related to rector, nor rector scoping.

Even when I run:

vendor/bin/phpstan analyse src/Php

I get:

Note: Using configuration file /var/www/rector/phpstan.neon.
PHP Fatal error:  Uncaught Error: Class '_HumbugBox4c23c5592d6a\JetBrains\PHPStormStub\PhpStormStubsMap' not found in phar:///var/www/rector/vendor/phpstan/phpstan/phpstan/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:67
Stack trace:
#0 phar:///var/www/rector/vendor/phpstan/phpstan/phpstan/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(38): _HumbugBox4c23c5592d6a\Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber->generateClassStub('T')

Any idea why?

@ondrejmirtes
Copy link
Contributor

That's currently fixed in PHPStan's dev-master. I should release a bugfix version.

@TomasVotruba
Copy link
Member

Uff :) good to hear that

@ondrejmirtes
Copy link
Contributor

PHPStan 0.12.9 just released.

@TomasVotruba
Copy link
Member

I bumped PHPStan version to 0.12.9 in #2800,
but the error is still there:

Error: Class '_HumbugBoxebb6c51d1e3e\JetBrains\PHPStormStub\PhpStormStubsMap' not found

Paths:

phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:67
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php:38
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php:31
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AbstractSourceLocator.php:38
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php:31
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/ClassReflector.php:37
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingClassReflector.php:28
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php:92
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/ChainReflectionProvider.php:25
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php:30
phar:///var/www/rector/vendor/phpstan/phpstan/phpstan.phar/src/Broker/Broker.php:53

@ondrejmirtes
Copy link
Contributor

Can you point me to which build step failed like this in #2800? I see that PHPStan itself works: https://github.com/rectorphp/rector/pull/2800/checks?check_run_id=427074168

@TomasVotruba
Copy link
Member

@ondrejmirtes
Copy link
Contributor

Yes, you're right, I understand why. Try to manually include the file like this (https://github.com/phpstan/phpstan-src/blob/63707915d487f032574bf76d5cb25d42b73909b0/bin/phpstan#L58) in your tests bootstrap before I fix this in PHPStan itself. Thanks.

@TomasVotruba
Copy link
Member

Thanks! I tried adding this:

require_once 'phar://vendor/phpstan/phpstan/phpstan.phar/vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php';

@TomasVotruba
Copy link
Member

It works sometimes, but run after Docker build fails
https://github.com/rectorphp/rector/runs/431264847

And external run too:
9e0ca0f#diff-c2ba69ed4d667444d40e5d2573d8bcb5

Seems like it can be only solved in PHPStan correctly. This is blocker for Rector releases last 2 weeks. Any ETA for fixed release?

@ondrejmirtes
Copy link
Contributor

The normal run should have been fixed in 0.12.9. If it isn’t, show me a build log where it fails. But I don’t know about any issue now.

The unit test problem is a new one for me, I’ll look at it next week. You can use 0.12.7 until then.

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 7, 2020

This one: https://github.com/rectorphp/rector/runs/430045396?check_suite_focus=true

It would be better to autolaod the file in PHPStan's composer.json. Now I have to duplicate bin/phpstan, that is sometimes loaded and sometimes not. That's why there is eaither class missing or loaded twice error.

Not sure why it's prefixed when scoper should skip it.

@ondrejmirtes
Copy link
Contributor

You'll have to apply the same fix as I do in PHPStan itself. Here's the explanation what happens: phpstan/phpstan#2948 (comment)

Here are the fixes for the normal run: https://github.com/phpstan/phpstan-src/blob/d1452fb3a6eead984070df6fa5fdec3a26b5ba4b/bin/phpstan#L58-L60 I think you have to do them in your bin/rector file too.

I have to come up with a fix to fix unit tests run, it will probably mean moving these lines to bootstrap.php but I'm not sure and will have to test it.

@TomasVotruba
Copy link
Member

I think the problem is that file itself is not scoped, but the class usage it.
It's just not accidently used in PHPStan tests, so it passes.

But _HumbugBoxebb6c51d1e3e\JetBrains\PHPStormStub\PhpStormStubsMap actually exists in code, e.g.

public function (\_HumbugBoxebb6c51d1e3e\JetBrains\PHPStormStub\PhpStormStubsMap $phpStormStubsMap)

It needs to be de-scoped in scoper.php.inc in a way similar to this:
https://github.com/phpstan/phpstan-src/blob/d1452fb3a6eead984070df6fa5fdec3a26b5ba4b/compiler/build/scoper.inc.php#L107-L110

@ondrejmirtes
Copy link
Contributor

That is not what is happening, see my comment above.

@TomasVotruba
Copy link
Member

I didn't see it before, just read it.

You'll have to apply the same fix as I do in PHPStan itself.

What exactly you mean? I've added include to bin/rector, but it didn't help

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 7, 2020

I've added exactly this line:

https://github.com/phpstan/phpstan-src/blob/d1452fb3a6eead984070df6fa5fdec3a26b5ba4b/bin/phpstan#L58

and it didn't work

See bin/rector

include_once 'phar://vendor/phpstan/phpstan/phpstan.phar/vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php';

What should I do to make it work?

@ondrejmirtes
Copy link
Contributor

I'll look into fixing this properly after the weekend.

@TomasVotruba
Copy link
Member

Thank you

@ondrejmirtes
Copy link
Contributor

Verifying the fixes in: #2816

@ondrejmirtes
Copy link
Contributor

Do you know about any other issues I could test in that PR?

@TomasVotruba
Copy link
Member

Basically this must be moved from inactive_workflows to workflows:
9e0ca0f#diff-c2ba69ed4d667444d40e5d2573d8bcb5

And this as well:
6ee4e7c

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 9, 2020

I just enabled those workflows, so you can just rebase on master

@TomasVotruba
Copy link
Member

@ondrejmirtes I rebased and merged it and it looks good. Both failing workflows now pass.

Thank you 👍

@ondrejmirtes
Copy link
Contributor

Cool, but beware, 0.12.10 isn’t released yet.

@TomasVotruba
Copy link
Member

Sure.

No rush, but any ETA on this so I can plan Rector release accordingly?

@ondrejmirtes
Copy link
Contributor

Some time during the next week, Wednesday or Thursday :)

@TomasVotruba
Copy link
Member

Purfect :) 👍

@TomasVotruba
Copy link
Member

Prefixed Rector is now build correctly as well 👍

https://github.com/rectorphp/rector-prefixed

@ondrejmirtes
Copy link
Contributor

Just released :) https://github.com/phpstan/phpstan/releases/tag/0.12.10

TomasVotruba added a commit that referenced this issue Aug 9, 2022
rectorphp/rector-src@93b63b0 [Php54][Php80] Handle no scope on LongArrayToShortArrayRector+AnnotationToAttributeRector (#2749)
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.

4 participants