Skip to content

Commit 44b8b73

Browse files
committed
Regression tests
Closes phpstan/phpstan#6299
1 parent a9bf7f1 commit 44b8b73

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

tests/PHPStan/Rules/PhpDoc/InvalidPhpDocTagValueRuleTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,24 @@ public function testIgnoreWithinPhpDoc(): void
124124
$this->analyse([__DIR__ . '/data/ignore-line-within-phpdoc.php'], []);
125125
}
126126

127+
public function testBug6299(): void
128+
{
129+
$this->analyse([__DIR__ . '/data/bug-6299.php'], [
130+
[
131+
"PHPDoc tag @phpstan-return has invalid value (array{'numeric': stdClass[], 'branches': array{'names': string[], 'exclude': bool}}}|int): Unexpected token \"}\", expected TOKEN_HORIZONTAL_WS at offset 107 on line 2",
132+
10,
133+
],
134+
]);
135+
}
136+
137+
public function testBug6692(): void
138+
{
139+
$this->analyse([__DIR__ . '/data/bug-6692.php'], [
140+
[
141+
'PHPDoc tag @return has invalid value ($this<string>): Unexpected token "<", expected TOKEN_HORIZONTAL_WS at offset 21 on line 2',
142+
11,
143+
],
144+
]);
145+
}
146+
127147
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Bug6299;
4+
5+
use stdClass;
6+
7+
class HelloWorld
8+
{
9+
/**
10+
* @phpstan-return array{'numeric': stdClass[], 'branches': array{'names': string[], 'exclude': bool}}}|int
11+
*/
12+
public function sayHello(): array
13+
{
14+
if(rand(0,1)){
15+
return ['numeric' => [], 'branches' => ['names' => [], 'exclude' => false]];
16+
}
17+
else {
18+
return 0;
19+
}
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Bug6692;
4+
5+
/**
6+
* @template T
7+
*/
8+
class Wrapper
9+
{
10+
/**
11+
* @return $this<string>
12+
*/
13+
public function change(): static
14+
{
15+
return $this;
16+
}
17+
}
18+
19+
/**
20+
* @template T
21+
* @extends Wrapper<T>
22+
*
23+
* @method self<string> change()
24+
*/
25+
class SubWrapper extends Wrapper
26+
{
27+
}

0 commit comments

Comments
 (0)