Skip to content

Commit ba6e8f3

Browse files
phpstan-botclaude
andcommitted
Fix method_exists($this) false positives in traits and PHP 7.4 lint
Add early return for method_exists() with $this-dependent expressions in trait context, and add // lint >= 8.0 comment to bug-13023 test file for nullsafe operator compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5ac5e5f commit ba6e8f3

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,6 @@ public function testImpossibleCheckTypeFunctionCall(): void
183183
'Call to function method_exists() with CheckTypeFunctionCall\MethodExists and \'testWithNewObjectIn…\' will always evaluate to true.',
184184
635,
185185
],
186-
[
187-
'Call to function method_exists() with $this(CheckTypeFunctionCall\MethodExistsWithTrait) and \'method\' will always evaluate to true.',
188-
650,
189-
],
190-
[
191-
'Call to function method_exists() with $this(CheckTypeFunctionCall\MethodExistsWithTrait) and \'someAnother\' will always evaluate to true.',
192-
653,
193-
],
194-
[
195-
'Call to function method_exists() with $this(CheckTypeFunctionCall\MethodExistsWithTrait) and \'unknown\' will always evaluate to false.',
196-
656,
197-
],
198186
[
199187
'Call to function method_exists() with \'CheckTypeFunctionCall\\\\MethodExistsWithTrait\' and \'method\' will always evaluate to true.',
200188
659,
@@ -1213,4 +1201,37 @@ public function testBug13023(): void
12131201
$this->analyse([__DIR__ . '/data/bug-13023.php'], []);
12141202
}
12151203

1204+
public function testBug7599(): void
1205+
{
1206+
$this->treatPhpDocTypesAsCertain = true;
1207+
$this->analyse([__DIR__ . '/data/bug-7599.php'], [
1208+
[
1209+
'Call to function method_exists() with Bug7599\SecondEnum::Baz and \'barMethod\' will always evaluate to true.',
1210+
13,
1211+
],
1212+
[
1213+
'Call to function method_exists() with Bug7599\TestEnum::Bar|Bug7599\TestEnum::Foo and \'barMethod\' will always evaluate to false.',
1214+
13,
1215+
],
1216+
]);
1217+
}
1218+
1219+
public function testBug9095(): void
1220+
{
1221+
$this->treatPhpDocTypesAsCertain = true;
1222+
$this->analyse([__DIR__ . '/data/bug-9095.php'], []);
1223+
}
1224+
1225+
public function testBug13474(): void
1226+
{
1227+
$this->treatPhpDocTypesAsCertain = true;
1228+
$this->analyse([__DIR__ . '/data/bug-13474.php'], []);
1229+
}
1230+
1231+
public function testBug13687(): void
1232+
{
1233+
$this->treatPhpDocTypesAsCertain = true;
1234+
$this->analyse([__DIR__ . '/data/bug-13687.php'], []);
1235+
}
1236+
12161237
}

tests/PHPStan/Rules/Comparison/data/bug-13023.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types = 1);
1+
<?php declare(strict_types = 1); // lint >= 8.0
22

33
namespace Bug13023;
44

0 commit comments

Comments
 (0)