Skip to content

Commit

Permalink
other approach
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed May 29, 2022
1 parent 128a619 commit ebf4b37
Showing 1 changed file with 25 additions and 27 deletions.
Expand Up @@ -17,39 +17,37 @@ class MissingReadOnlyPropertyAssignRuleTest extends RuleTestCase

protected function getRule(): Rule
{
$extensions = [];
if (PHP_VERSION_ID >= 80100) {
$extensions[] = new class() implements ReadWritePropertiesExtension {
return new MissingReadOnlyPropertyAssignRule(
new ConstructorsHelper([
'MissingReadOnlyPropertyAssign\\TestCase::setUp',
]),
new DirectReadWritePropertiesExtensionProvider([
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 PHP_VERSION_ID >= 80100
&&$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 ebf4b37

Please sign in to comment.