Skip to content

Commit

Permalink
Merge pull request #574 from deguif/promoted-properties
Browse files Browse the repository at this point in the history
Handle properly promoted constructor properties default values
  • Loading branch information
goetas authored Jan 30, 2023
2 parents 619e880 + 6b69940 commit 9250ed8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Translation/Extractor/File/ValidationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private function extractFromConstraints(array $constraints)
foreach ($constraints as $constraint) {
$ref = new \ReflectionClass($constraint);
$defaultValues = $ref->getDefaultProperties();

$defaultParameters = null !== $ref->getConstructor() ? $ref->getConstructor()->getParameters() : [];
$properties = $ref->getProperties();

foreach ($properties as $property) {
Expand All @@ -177,9 +177,18 @@ private function extractFromConstraints(array $constraints)
// If the property ends with 'Message'
if (strtolower(substr($propName, -1 * strlen('Message'))) === 'message') {
// If it is different from the default value
if ($defaultValues[$propName] !== $constraint->{$propName}) {
if (array_key_exists($propName, $defaultValues) && $defaultValues[$propName] !== $constraint->{$propName}) {
$message = new Message($constraint->{$propName}, 'validators');
$this->catalogue->add($message);
} elseif (method_exists($property, 'isPromoted') && $property->isPromoted()) {
foreach ($defaultParameters as $defaultParameter) {
if ($defaultParameter->getName() === $propName && $defaultParameter->isDefaultValueAvailable() && $defaultParameter->getDefaultValue() !== $constraint->{$propName}) {
$message = new Message($constraint->{$propName}, 'validators');
$this->catalogue->add($message);

break;
}
}
}
}
}
Expand Down

0 comments on commit 9250ed8

Please sign in to comment.