Skip to content

Commit ae85d4b

Browse files
rvanvelzenondrejmirtes
authored andcommitted
Fix __toString() for negated asserts
1 parent 5f13698 commit ae85d4b

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/Ast/PhpDoc/AssertTagMethodValueNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(TypeNode $type, string $parameter, string $method, b
3939
public function __toString(): string
4040
{
4141
$isNegated = $this->isNegated ? '!' : '';
42-
return trim("{$this->type} {$isNegated}{$this->parameter}->{$this->method}() {$this->description}");
42+
return trim("{$isNegated}{$this->type} {$this->parameter}->{$this->method}() {$this->description}");
4343
}
4444

4545
}

src/Ast/PhpDoc/AssertTagPropertyValueNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(TypeNode $type, string $parameter, string $property,
3939
public function __toString(): string
4040
{
4141
$isNegated = $this->isNegated ? '!' : '';
42-
return trim("{$this->type} {$isNegated}{$this->parameter}->{$this->property} {$this->description}");
42+
return trim("{$isNegated}{$this->type} {$this->parameter}->{$this->property} {$this->description}");
4343
}
4444

4545
}

src/Ast/PhpDoc/AssertTagValueNode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(TypeNode $type, string $parameter, bool $isNegated,
3535
public function __toString(): string
3636
{
3737
$isNegated = $this->isNegated ? '!' : '';
38-
return trim("{$this->type} {$isNegated}{$this->parameter} {$this->description}");
38+
return trim("{$isNegated}{$this->type} {$this->parameter} {$this->description}");
3939
}
4040

4141
}

tests/PHPStan/Parser/PhpDocParserTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -4855,4 +4855,16 @@ public function testBug132(): void
48554855
$this->assertSame('\Symplify\SymfonyStaticDumper\Tests\Application\SymfonyStaticDumperApplicationTest', $seeNode->value->__toString());
48564856
}
48574857

4858+
public function testNegatedAssertionToString(): void
4859+
{
4860+
$tokens = new TokenIterator($this->lexer->tokenize('/** @phpstan-assert !Type $param */'));
4861+
$phpDocNode = $this->phpDocParser->parse($tokens);
4862+
4863+
$assertNode = $phpDocNode->children[0];
4864+
$this->assertInstanceOf(PhpDocTagNode::class, $assertNode);
4865+
$this->assertInstanceOf(AssertTagValueNode::class, $assertNode->value);
4866+
4867+
$this->assertSame('@phpstan-assert !Type $param', $assertNode->__toString());
4868+
}
4869+
48584870
}

0 commit comments

Comments
 (0)