-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
[DeadCode] Skip @template tag on RemoveUselessVarTagRector #6396
Conversation
// NonExistingObjectType may refer to @template tag defined in class | ||
if ($docType instanceof NonExistingObjectType && ! str_contains($docType->getClassName(), '\\')) { | ||
dump($docType); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dragosprotung this can be tweak solution, but it will cause invalid skipped real non existing object type, see fixture /~https://github.com/rectorphp/rector-src/pull/6396/files#diff-d9d0d07e6a9125b667f68974544d4c6567c6b31da986c9644d725c188257f378
There was 1 failure:
1) Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\RemoveUselessVarTagRectorTest::test with data set #3 ('/home/runner/work/rector-src/...hp.inc')
Failed on fixture file "non_existing_object.php.inc"
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
final class NonExistingObject
{
+ /** @var SomeNonExistingObject */
private Properties|null $properties;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is something that is acceptable. If the referenced type is somehow not discoverable by Rector, is the job of DeadVarTagValueNodeAnalyzer
to remove the tag ?
Also, could we not check if $docType
is a template NonExistingObjectType->getClassName()
= TType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch seems needs to be in ObjectTypeSpecifier
to locate @template
if exists before marking as NonExistingObjectType
rector-src/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php
Lines 58 to 70 in d415260
// probably in same namespace | |
if ($scope instanceof Scope) { | |
$namespaceName = $scope->getNamespace(); | |
if ($namespaceName !== null) { | |
$newClassName = $namespaceName . '\\' . $className; | |
if ($this->reflectionProvider->hasClass($newClassName)) { | |
return new FullyQualifiedObjectType($newClassName); | |
} | |
} | |
} | |
// invalid type | |
return new NonExistingObjectType($className); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you might be right. Unfortunatly I do not have enought knowlage of PHPStan to find out if the type is a template or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be a problem if the unknown type is not removed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@template
tag should be detected, unknown type can be just typo missing FQCN on class name, which should be removed as pointed to invalid class target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by get @template
from ClassReflection
02b566a
current limitation is currently only detect single @template
that can be improved in separate PR when possible :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems cause invalid rectify 366194b , I will check more :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be fixed now :)
// NonExistingObjectType may refer to @template tag defined in class | ||
if ($docType instanceof NonExistingObjectType && ! str_contains($docType->getClassName(), '\\')) { | ||
dump($docType); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is something that is acceptable. If the referenced type is somehow not discoverable by Rector, is the job of DeadVarTagValueNodeAnalyzer
to remove the tag ?
Also, could we not check if $docType
is a template NonExistingObjectType->getClassName()
= TType
?
366194b
to
337c5f6
Compare
337c5f6
to
6864c5f
Compare
6638e10
to
cf3ca19
Compare
7e9aa74
to
9d019dc
Compare
All checks have passed 🎉 @TomasVotruba I am merging it to have faster feedback to test ;) |
Fixes rectorphp/rector#8870