-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make PhpDocINfo::removeByType() return bool to inform about changed n…
…ode (#4979)
- Loading branch information
1 parent
1593d00
commit 57ec646
Showing
3 changed files
with
32 additions
and
8 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
use PhpParser\Node\Stmt\ClassLike; | ||
use PhpParser\Node\Stmt\Property; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode; | ||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; | ||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; | ||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface; | ||
use Rector\Core\Rector\AbstractRector; | ||
|
@@ -69,22 +70,32 @@ public function getNodeTypes(): array | |
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
if ($this->annotationsToRemove === []) { | ||
Assert::notEmpty($this->annotationsToRemove); | ||
|
||
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node); | ||
if (! $phpDocInfo instanceof PhpDocInfo) { | ||
return null; | ||
} | ||
|
||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); | ||
$hasChanged = false; | ||
|
||
foreach ($this->annotationsToRemove as $annotationToRemove) { | ||
$this->phpDocTagRemover->removeByName($phpDocInfo, $annotationToRemove); | ||
$namedHasChanged = $this->phpDocTagRemover->removeByName($phpDocInfo, $annotationToRemove); | ||
if ($namedHasChanged) { | ||
$hasChanged = true; | ||
} | ||
|
||
if (! is_a($annotationToRemove, PhpDocTagValueNode::class, true)) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
TomasVotruba
Author
Member
|
||
continue; | ||
} | ||
|
||
$phpDocInfo->removeByType($annotationToRemove); | ||
$typedHasChanged = $phpDocInfo->removeByType($annotationToRemove); | ||
if ($typedHasChanged) { | ||
$hasChanged = true; | ||
} | ||
} | ||
|
||
if ($phpDocInfo->hasChanged()) { | ||
if ($hasChanged) { | ||
return $node; | ||
} | ||
|
||
|
should this be
instanceof
instead to get rid ofis_a
which works against the static reflection concept?