diff --git a/src/Rules/Classes/NewStaticRule.php b/src/Rules/Classes/NewStaticRule.php index d1034093933..81b3d080521 100644 --- a/src/Rules/Classes/NewStaticRule.php +++ b/src/Rules/Classes/NewStaticRule.php @@ -69,7 +69,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - foreach ($classReflection->getImmediateInterfaces() as $interface) { + foreach ($classReflection->getInterfaces() as $interface) { if ($interface->hasConstructor()) { return []; } diff --git a/tests/PHPStan/Rules/Classes/NewStaticRuleTest.php b/tests/PHPStan/Rules/Classes/NewStaticRuleTest.php index b096e8119bd..ae83e15fbaa 100644 --- a/tests/PHPStan/Rules/Classes/NewStaticRuleTest.php +++ b/tests/PHPStan/Rules/Classes/NewStaticRuleTest.php @@ -73,4 +73,9 @@ public function testBug10722(): void $this->analyse([__DIR__ . '/data/bug-10722.php'], []); } + public function testBug10274(): void + { + $this->analyse([__DIR__ . '/data/bug-10274.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Classes/data/bug-10274.php b/tests/PHPStan/Rules/Classes/data/bug-10274.php new file mode 100644 index 00000000000..733ab75606d --- /dev/null +++ b/tests/PHPStan/Rules/Classes/data/bug-10274.php @@ -0,0 +1,69 @@ += 8.0 + +namespace Bug10274; + +/** + * @template T + */ +class AbstractArray { + /** + * @var array + */ + public array $data; + + /** + * @param array $data + */ + public function __construct(array $data = []) + { + $this->data = $data; + } +} + +interface BaseCollectionInterface {} + + +/** + * @template T + * @extends AbstractArray + */ +abstract class AbstractCollection extends AbstractArray implements BaseCollectionInterface {} + +/** + * @template T + */ +interface ConstructorDefiningInterface extends BaseCollectionInterface { + /** + * @param array $data + */ + public function __construct(array $data = []); +} + +/** + * @template T + * @extends AbstractCollection + * @implements ConstructorDefiningInterface + */ +abstract class IntermediateCollection extends AbstractCollection implements ConstructorDefiningInterface {} + +/** + * @template T + * @extends IntermediateCollection + */ +class SpecificCollection extends IntermediateCollection { + public static function create(): static + { + return new static(); + } +} + +/** + * @template T + * @extends SpecificCollection + */ +class DeeplyNestedCollection extends SpecificCollection { + public static function create(): static + { + return new static(); + } +}