Skip to content

Commit a4e2bfe

Browse files
committed
1 parent a849f06 commit a4e2bfe

10 files changed

Lines changed: 135 additions & 0 deletions

File tree

‎tests/PHPStan/Analyser/NodeScopeResolverTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@ public function dataFileAsserts(): iterable
11861186

11871187
if (PHP_VERSION_ID >= 80000) {
11881188
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10071.php');
1189+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9394.php');
11891190
}
11901191

11911192
yield from $this->gatherAssertTypes(__DIR__ . '/data/allowed-subtypes-datetime.php');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bug9394;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Order
8+
{
9+
public bool $is_pre_order;
10+
}
11+
12+
function (?Order $order): void {
13+
if ($order?->is_pre_order === false) {
14+
return;
15+
}
16+
17+
assertType(Order::class . '|null', $order);
18+
};

‎tests/PHPStan/Rules/Methods/NullsafeMethodCallRuleTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,13 @@ public function testBug9293(): void
4646
$this->analyse([__DIR__ . '/../../Analyser/data/bug-9293.php'], []);
4747
}
4848

49+
public function testBug6922b(): void
50+
{
51+
if (PHP_VERSION_ID < 80000) {
52+
$this->markTestSkipped('Test requires PHP 8.0.');
53+
}
54+
55+
$this->analyse([__DIR__ . '/data/bug-6922b.php'], []);
56+
}
57+
4958
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Bug6922b;
4+
5+
final class Configuration
6+
{
7+
public function isFirstOptionActive(): bool
8+
{
9+
return true;
10+
}
11+
12+
public function isSecondOptionActive(): bool
13+
{
14+
return true;
15+
}
16+
}
17+
18+
function run(?Configuration $configuration): void
19+
{
20+
if (
21+
$configuration?->isFirstOptionActive() === false ||
22+
$configuration?->isSecondOptionActive() === false)
23+
{
24+
// ....
25+
}
26+
}

‎tests/PHPStan/Rules/Missing/MissingReturnRuleTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,10 @@ public function testBug7384(): void
303303
$this->analyse([__DIR__ . '/data/bug-7384.php'], []);
304304
}
305305

306+
public function testBug9309(): void
307+
{
308+
$this->checkExplicitMixedMissingReturn = true;
309+
$this->analyse([__DIR__ . '/data/bug-9309.php'], []);
310+
}
311+
306312
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Bug9309;
4+
5+
function a(): int {
6+
declare(ticks=1) {
7+
return 1;
8+
}
9+
}

‎tests/PHPStan/Rules/Properties/NullsafePropertyFetchRuleTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,13 @@ public function testBug9105(): void
6969
$this->analyse([__DIR__ . '/../../Analyser/data/bug-9105.php'], []);
7070
}
7171

72+
public function testBug6922(): void
73+
{
74+
if (PHP_VERSION_ID < 80000) {
75+
$this->markTestSkipped('Test requires PHP 8.0.');
76+
}
77+
78+
$this->analyse([__DIR__ . '/data/bug-6922.php'], []);
79+
}
80+
7281
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php // lint >= 8.0
2+
3+
namespace Bug6922;
4+
5+
class Person {
6+
7+
public function __construct(
8+
public readonly string $name,
9+
public readonly bool $isDeveloper,
10+
public readonly bool $isAdmin
11+
) {
12+
13+
}
14+
}
15+
16+
class Proof
17+
{
18+
public function test(?Person $person): void
19+
{
20+
if ($person?->isDeveloper === FALSE ||
21+
$person?->isAdmin === FALSE) {
22+
echo "Bug";
23+
}
24+
}
25+
}

‎tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,4 +1015,13 @@ public function testIsStringNarrowsCertainty(): void
10151015
]);
10161016
}
10171017

1018+
public function testBug5266(): void
1019+
{
1020+
$this->cliArgumentsVariablesRegistered = true;
1021+
$this->polluteScopeWithLoopInitialAssignments = true;
1022+
$this->checkMaybeUndefinedVariables = true;
1023+
$this->polluteScopeWithAlwaysIterableForeach = true;
1024+
$this->analyse([__DIR__ . '/data/bug-5266.php'], []);
1025+
}
1026+
10181027
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Bug5266;
4+
5+
class TestEnums
6+
{
7+
const SORT_ASC = 'sort_asc';
8+
const SORT_DESC = 'sort_desc';
9+
10+
/**
11+
* @param self::SORT_ASC|self::SORT_DESC $sortType
12+
*/
13+
public function sort(string $sortType): void
14+
{
15+
if ($sortType === self::SORT_ASC) {
16+
$message = 'Sorting ASC';
17+
} elseif ($sortType === self::SORT_DESC) {
18+
$message = 'Sorting DESC';
19+
}
20+
21+
echo $message . '\n';
22+
}
23+
}

0 commit comments

Comments
 (0)