-
-
Notifications
You must be signed in to change notification settings - Fork 687
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
Make use of static reflection from PHPStan #5665
Conversation
3f80faa
to
c3c3084
Compare
packages/better-php-doc-parser/src/AnnotationReader/NodeAnnotationReader.php
Outdated
Show resolved
Hide resolved
packages/node-type-resolver/src/DependencyInjection/PHPStanServicesFactory.php
Outdated
Show resolved
Hide resolved
packages/better-php-doc-parser/src/AnnotationReader/NodeAnnotationReader.php
Show resolved
Hide resolved
2f3a909
to
93672f4
Compare
f036a30
to
d8bd4e3
Compare
packages/better-php-doc-parser/src/AnnotationReader/NodeAnnotationReader.php
Outdated
Show resolved
Hide resolved
4c9a89e
to
0885286
Compare
packages/node-type-resolver/config/phpstan/static-reflection.neon
Outdated
Show resolved
Hide resolved
ad3c3dc
to
b9cddc0
Compare
It depends on how the ReflectionProvider instance looks like in Rector. In PHPStan by default it's a chain of various ReflectionProvider implementations. In layman's terms, if a class is reachable through a correctly configured Composer autoloader, a runtime reflection will be used. Otherwise static reflection is used. |
Rector is using the same ReflectionProvider service, and adding files and directories from |
(How) can I run Rector with a version of PHPStan that is not packed up as a Phar? |
Nope, PHPStan is only distributed as PHAR. What are your needs? |
Debug into Rector, see when/how it uses (To understand when/why scoping Rector is needed, and to understand when/why Rector needs to run with the same PHP version as the project it analyzes.) |
Xdebug works even with PHARs. |
... but changing code (commenting out things etc) does not. |
But I'll take this as "there is no easy way to install a non-Phar source version of PHPStan" and deal with it 😉 |
You can always clone phpstan-src alongside a project and run plain PHPStan using ../phpstan-src/phpstan analyse ... on a codebase, but not in combination with Rector. |
Since rectorphp#5665, we might get away with the PHP 8.0 image variant only, and also no longer need to scope the Rector source code.
rectorphp/rector-src@58abec4 [automated] Apply Coding Standard (#5665)
rectorphp/rector-src@58abec4 [automated] Apply Coding Standard (#5665)
rectorphp/rector-src@58abec4 [automated] Apply Coding Standard (#5665)
Closes #3490
Now Rector autoloads all the code that analyses. That means all your projects has to be loaded with composer, custom autoload or included. That can lead to side-effects like these:
↓
Fatal error: canont connect to mysql
The only way to avoid this is to use static reflections. That means the code is parsed, so Rector knows about
mysql_connect
function call, but it is not included and does not produce side effects. Win win 🎉Todo
ClassExistenceStaticHelper::doesClassLikeExists()
withReflectionProvider->hasClass()
class_exists()
withReflectionProvider->hasClass()
SourceLocatorFactory
phpstan.neon
for Rector internalls - here 9071f1b#diff-d4ecbf7aff4875121457666bba3371091eb5009fda360c3c51068e135075bf7cphpstan.neon
config - Taking advantage of static reflection #3490 (comment)Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocator
, e.g.vendor/bin/rector process <src>
Tests
is_a()
,instanceof
,$objectType->hasMethod()
,$objectType->hasProperty()
withClassReflection
API