Skip to content

Commit 5c7135b

Browse files
committed
Parse @pure-unless-parameter-passed via phpdoc-parser 2.3.3
phpstan/phpdoc-parser#259 is merged and released, so replace the generic-tag stopgap with PhpDocNode::getPureUnlessParameterIsPassedTagValues() and bump the dependency.
1 parent cd93236 commit 5c7135b

1 file changed

Lines changed: 2 additions & 29 deletions

File tree

src/PhpDoc/PhpDocNodeResolver.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use PHPStan\PhpDoc\Tag\UsesTag;
2929
use PHPStan\PhpDoc\Tag\VarTag;
3030
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNullNode;
31-
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
3231
use PHPStan\PhpDocParser\Ast\PhpDoc\MixinTagValueNode;
3332
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
3433
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
@@ -48,10 +47,8 @@
4847
use function array_reverse;
4948
use function count;
5049
use function in_array;
51-
use function ltrim;
5250
use function method_exists;
5351
use function str_starts_with;
54-
use function strpos;
5552
use function substr;
5653

5754
#[AutowiredService]
@@ -412,33 +409,9 @@ public function resolveParamPureUnlessCallableIsImpure(PhpDocNode $phpDocNode):
412409
public function resolveParamPureUnlessParameterPassed(PhpDocNode $phpDocNode): array
413410
{
414411
$parameters = [];
415-
// TODO: replace this generic-tag parsing with
416-
// $phpDocNode->getPureUnlessParameterIsPassedTagValues() once
417-
// phpstan/phpdoc-parser#259 is merged and the parser understands the tag.
418412
foreach (['@pure-unless-parameter-passed', '@phpstan-pure-unless-parameter-passed'] as $tagName) {
419-
foreach ($phpDocNode->getTags() as $tag) {
420-
if ($tag->name !== $tagName) {
421-
continue;
422-
}
423-
if (!$tag->value instanceof GenericTagValueNode) {
424-
continue;
425-
}
426-
427-
$value = ltrim($tag->value->value);
428-
if ($value === '' || $value[0] !== '$') {
429-
continue;
430-
}
431-
432-
$parameterName = substr($value, 1);
433-
$spacePosition = strpos($parameterName, ' ');
434-
if ($spacePosition !== false) {
435-
$parameterName = substr($parameterName, 0, $spacePosition);
436-
}
437-
438-
if ($parameterName === '') {
439-
continue;
440-
}
441-
413+
foreach ($phpDocNode->getPureUnlessParameterIsPassedTagValues($tagName) as $tag) {
414+
$parameterName = substr($tag->parameterName, 1);
442415
$parameters[$parameterName] = true;
443416
}
444417
}

0 commit comments

Comments
 (0)