Skip to content

Commit

Permalink
Conditionally register test extension for PHP 8.1+ only
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed May 29, 2022
1 parent aa97cab commit 3fbbfa2
Showing 1 changed file with 27 additions and 24 deletions.
Expand Up @@ -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),
);
}

Expand Down

0 comments on commit 3fbbfa2

Please sign in to comment.