-
-
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
130c2e9
[DeadCode] Skip @template tag on RemoveUselessVarTagRector
samsonasik e3f340b
add fixutres
samsonasik 02b566a
Fix by get @template from ClassReflection
samsonasik 6864c5f
Fix
samsonasik cf3ca19
ensure scope exists
samsonasik 0ca294c
cs fix
samsonasik 9d019dc
Fix
samsonasik d61c756
[ci-review] Rector Rectify
actions-user File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...ts/DeadCode/Rector/Property/RemoveUselessVarTagRector/Fixture/non_existing_object.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Fixture; | ||
|
||
use Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Source\Properties; | ||
|
||
final class NonExistingObject | ||
{ | ||
/** @var SomeNonExistingObject */ | ||
private Properties|null $properties; | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Fixture; | ||
|
||
use Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Source\Properties; | ||
|
||
final class NonExistingObject | ||
{ | ||
private Properties|null $properties; | ||
} | ||
|
||
?> |
14 changes: 14 additions & 0 deletions
14
...ests/DeadCode/Rector/Property/RemoveUselessVarTagRector/Fixture/skip_template_tag.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Fixture; | ||
|
||
use Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Source\Properties; | ||
|
||
/** | ||
* @template TProperties of Properties|null | ||
*/ | ||
final class SkipTemplateTag | ||
{ | ||
/** @var TProperties */ | ||
private Properties|null $properties; | ||
} |
5 changes: 5 additions & 0 deletions
5
rules-tests/DeadCode/Rector/Property/RemoveUselessVarTagRector/Source/Properties.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\Property\RemoveUselessVarTagRector\Source; | ||
|
||
interface Properties{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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 templateNonExistingObjectType->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 asNonExistingObjectType
rector-src/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php
Lines 58 to 70 in d415260
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
fromClassReflection
02b566acurrent 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 :)