Skip to content

Commit 5a5336c

Browse files
committed
Added regression test
1 parent 45c1da6 commit 5a5336c

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,4 +1068,16 @@ public function testBug9666(): void
10681068
]);
10691069
}
10701070

1071+
public function testBug9445(): void
1072+
{
1073+
$this->treatPhpDocTypesAsCertain = true;
1074+
$this->analyse([__DIR__ . '/data/bug-9445.php'], []);
1075+
}
1076+
1077+
public function testBug7773(): void
1078+
{
1079+
$this->treatPhpDocTypesAsCertain = true;
1080+
$this->analyse([__DIR__ . '/data/bug-7773.php'], []);
1081+
}
1082+
10711083
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug7773;
4+
5+
class JSONEncodingException extends \Exception
6+
{
7+
}
8+
9+
class JSONDecodingException extends \Exception
10+
{
11+
}
12+
13+
class HelloWorld
14+
{
15+
/**
16+
* Encodes the data as JSON
17+
* @param array<mixed> $data json array
18+
* @return string json string
19+
* @throws JSONEncodingException
20+
*/
21+
public static function JSONEncode(array $data): string
22+
{
23+
if (!is_string($data = json_encode($data)))
24+
throw new JSONEncodingException();
25+
return $data;
26+
}
27+
28+
/**
29+
* Decodes the JSON data as an array
30+
* @param string $data json string
31+
* @return array<mixed> json array
32+
* @throws JSONDecodingException
33+
*/
34+
public static function JSONDecode(string $data): array
35+
{
36+
if (!is_array($data = json_decode($data, true)))
37+
throw new JSONDecodingException();
38+
return $data;
39+
}
40+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug9445;
4+
5+
class Foo
6+
{
7+
public int $id;
8+
public null|self $parent;
9+
10+
public function contains(self $foo): bool
11+
{
12+
do {
13+
if ($this->id === $foo->id) {
14+
return true;
15+
}
16+
} while (!is_null($foo = $foo->parent));
17+
18+
return false;
19+
}
20+
}

0 commit comments

Comments
 (0)