From 3fbbfa29bbdcb3453de5d6dc644edda3c42981a1 Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Sun, 29 May 2022 10:59:08 +0200 Subject: [PATCH] Conditionally register test extension for PHP 8.1+ only --- .../MissingReadOnlyPropertyAssignRuleTest.php | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php b/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php index 391afc01d1d..3ff238edcf4 100644 --- a/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php +++ b/tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php @@ -17,36 +17,39 @@ class MissingReadOnlyPropertyAssignRuleTest extends RuleTestCase protected function getRule(): Rule { - return new MissingReadOnlyPropertyAssignRule( - new ConstructorsHelper([ - 'MissingReadOnlyPropertyAssign\\TestCase::setUp', - ]), - new DirectReadWritePropertiesExtensionProvider([ - new class() implements ReadWritePropertiesExtension { + $extensions = []; + if (PHP_VERSION_ID >= 80100) { + $extensions[] = new class() implements ReadWritePropertiesExtension { - public function isAlwaysRead(PropertyReflection $property, string $propertyName): bool - { - return $this->isEntityId($property, $propertyName); - } + public function isAlwaysRead(PropertyReflection $property, string $propertyName): bool + { + return $this->isEntityId($property, $propertyName); + } - public function isAlwaysWritten(PropertyReflection $property, string $propertyName): bool - { - return $this->isEntityId($property, $propertyName); - } + public function isAlwaysWritten(PropertyReflection $property, string $propertyName): bool + { + return $this->isEntityId($property, $propertyName); + } - public function isInitialized(PropertyReflection $property, string $propertyName): bool - { - return $this->isEntityId($property, $propertyName); - } + public function isInitialized(PropertyReflection $property, string $propertyName): bool + { + return $this->isEntityId($property, $propertyName); + } - private function isEntityId(PropertyReflection $property, string $propertyName): bool - { - return $property->getDeclaringClass()->getName() === 'MissingReadOnlyPropertyAssign\\Entity' - && in_array($propertyName, ['id'], true); - } + private function isEntityId(PropertyReflection $property, string $propertyName): bool + { + return $property->getDeclaringClass()->getName() === 'MissingReadOnlyPropertyAssign\\Entity' + && in_array($propertyName, ['id'], true); + } - }, + }; + } + + return new MissingReadOnlyPropertyAssignRule( + new ConstructorsHelper([ + 'MissingReadOnlyPropertyAssign\\TestCase::setUp', ]), + new DirectReadWritePropertiesExtensionProvider($extensions), ); }