-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
use PHPStan\Php\PhpVersion; | ||
use PHPStan\Rules\FunctionCallParametersCheck; | ||
use PHPStan\Rules\Methods\CallMethodsRule; | ||
use PHPStan\Rules\Methods\MethodCallCheck; | ||
use PHPStan\Rules\NullsafeCheck; | ||
use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; | ||
use PHPStan\Rules\Properties\PropertyReflectionFinder; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleLevelHelper; | ||
use PHPStan\Testing\RuleTestCase; | ||
use const PHP_VERSION_ID; | ||
|
||
class Bug9307CallMethodsRuleTest extends RuleTestCase | ||
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan with result cache (8.3)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan with result cache (8.2)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.2, ubuntu-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan with result cache (8.1)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.1, ubuntu-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.3, ubuntu-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.2, windows-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.1, windows-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.3, windows-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.2, windows-latest)
Check failure on line 17 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.4, windows-latest)
|
||
{ | ||
|
||
protected function getRule(): Rule | ||
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan with result cache (8.3)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan with result cache (8.2)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.2, ubuntu-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan with result cache (8.1)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.1, ubuntu-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.3, ubuntu-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.2, windows-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.1, windows-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.3, windows-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.2, windows-latest)
Check failure on line 20 in tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php GitHub Actions / PHPStan (7.4, windows-latest)
|
||
{ | ||
$reflectionProvider = $this->createReflectionProvider(); | ||
$ruleLevelHelper = new RuleLevelHelper($reflectionProvider, true, false, true, true, false, true, false); | ||
return new CallMethodsRule( | ||
new MethodCallCheck($reflectionProvider, $ruleLevelHelper, true, true), | ||
new FunctionCallParametersCheck($ruleLevelHelper, new NullsafeCheck(), new PhpVersion(PHP_VERSION_ID), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true, true), | ||
); | ||
} | ||
|
||
protected function shouldTreatPhpDocTypesAsCertain(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse([__DIR__ . '/data/bug-9307.php'], []); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
use PHPStan\Testing\TypeInferenceTestCase; | ||
|
||
class Bug9307Test extends TypeInferenceTestCase | ||
{ | ||
|
||
public function dataFileAsserts(): iterable | ||
{ | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9307.php'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
* @param mixed ...$args | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
...$args, | ||
): void | ||
{ | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/../../../conf/bleedingEdge.neon', | ||
__DIR__ . '/bug-9307.neon', | ||
]; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
treatPhpDocTypesAsCertain: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Bug9307; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Item { | ||
public int $id; | ||
} | ||
|
||
class Aaa | ||
{ | ||
public function test(): void | ||
{ | ||
$objects = []; | ||
$itemCache = []; | ||
|
||
foreach ($this->getIds() as $id) { | ||
if (! array_key_exists($id, $itemCache)) { | ||
$items = $this->getObjects(); | ||
$itemCache[$id] = $items; | ||
} else { | ||
$items = $itemCache[$id]; | ||
} | ||
|
||
// It works when the following line is uncommented. | ||
//$items = $this->getObjects(); | ||
|
||
foreach ($items as $item) { | ||
$objects[$item->id] = $item; | ||
} | ||
} | ||
|
||
assertType('array', $objects); | ||
|
||
$this->acceptObjects($objects); | ||
} | ||
|
||
/** @return array<int> */ | ||
public function getIds(): array | ||
{ | ||
return []; | ||
} | ||
|
||
/** @return array<int, Item> */ | ||
public function getObjects(): array | ||
{ | ||
return []; | ||
} | ||
|
||
/** @param array<int, Item> $objects */ | ||
public function acceptObjects(array $objects): void | ||
{ | ||
|
||
} | ||
} |