Skip to content

Commit 77b8552

Browse files
committed
more tests
1 parent 92c3b5f commit 77b8552

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,7 @@ public function testBug9172(): void
15931593
$this->assertNotEmpty($errors);
15941594
}
15951595

1596+
#[RequiresPhp('>= 8.1.0')]
15961597
public function testPr5880(): void
15971598
{
15981599
// endless loop

tests/PHPStan/Rules/Comparison/BooleanAndConstantConditionRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,15 @@ public function testSelfContradiction(): void
463463
[
464464
'Result of && is always false.',
465465
51,
466+
],
467+
[
468+
'Result of && is always false.',
469+
77,
470+
'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.',
471+
],
472+
[
473+
'Result of && is always false.',
474+
103,
466475
'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.',
467476
],
468477
]);

tests/PHPStan/Rules/Comparison/data/self-contradiction.php

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use PhpParser\Node\Expr\ConstFetch;
99
use PhpParser\Node\Scalar;
1010

11-
class Foo {
11+
class AssertStaticCall {
1212
/**
1313
* @phpstan-assert-if-true Scalar|ClassConstFetch|ConstFetch $node
1414
*/
@@ -34,7 +34,33 @@ private function getSubjectAndValue(Identical $comparison): ?array
3434
}
3535
}
3636

37-
class Bar {
37+
class AssertMethodCall {
38+
/**
39+
* @phpstan-assert-if-true Scalar|ClassConstFetch|ConstFetch $node
40+
*/
41+
private function isSubjectNode(Expr $node): bool
42+
{
43+
return $node instanceof Scalar || $node instanceof ClassConstFetch || $node instanceof ConstFetch;
44+
}
45+
46+
/**
47+
* @return array{subject: Expr, value: Scalar|ClassConstFetch|ConstFetch}|null
48+
*/
49+
private function getSubjectAndValue(Identical $comparison): ?array
50+
{
51+
if ($this->isSubjectNode($comparison->left) && !$this->isSubjectNode($comparison->left)) {
52+
return ['subject' => $comparison->right, 'value' => $comparison->left];
53+
}
54+
55+
if (!$this->isSubjectNode($comparison->left) && $this->isSubjectNode($comparison->right)) {
56+
return ['subject' => $comparison->left, 'value' => $comparison->right];
57+
}
58+
59+
return null;
60+
}
61+
}
62+
63+
class AssertStaticConditionalReturn {
3864
/**
3965
* @return ($node is Scalar|ClassConstFetch|ConstFetch ? true : false)
4066
*/
@@ -59,3 +85,29 @@ private function getSubjectAndValue(Identical $comparison): ?array
5985
return null;
6086
}
6187
}
88+
89+
class AssertInstanceConditionalReturn {
90+
/**
91+
* @return ($node is Scalar|ClassConstFetch|ConstFetch ? true : false)
92+
*/
93+
private function isSubjectNode(Expr $node): bool
94+
{
95+
return $node instanceof Scalar || $node instanceof ClassConstFetch || $node instanceof ConstFetch;
96+
}
97+
98+
/**
99+
* @return array{subject: Expr, value: Scalar|ClassConstFetch|ConstFetch}|null
100+
*/
101+
private function getSubjectAndValue(Identical $comparison): ?array
102+
{
103+
if ($this->isSubjectNode($comparison->left) && !$this->isSubjectNode($comparison->left)) {
104+
return ['subject' => $comparison->right, 'value' => $comparison->left];
105+
}
106+
107+
if (!$this->isSubjectNode($comparison->left) && $this->isSubjectNode($comparison->right)) {
108+
return ['subject' => $comparison->left, 'value' => $comparison->right];
109+
}
110+
111+
return null;
112+
}
113+
}

0 commit comments

Comments
 (0)