Open asdrenxhafa opened 1 year ago
Thanks for your pull request, @asdrenxhafa ! Unfortunately, there seems to be an issue running the Actions on your branch, sorry about that.
In Validation/DataObject/Attributes/FieldCollectionAttribute.php
we use array_merge_recursive
to add new violations to the property in question. This doesn't work when the type is ConstraintViolationList
as compared to array
.
Additionally, PHPStan reports the following errors:
$ composer run phpstan
------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line Validation/DataObject/Attributes/AbstractAttribute.php
------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Ignored error pattern #^Property Valantic\\DataQualityBundle\\Validation\\DataObject\\Attributes\\AbstractAttribute\:\:\$violations \(array<Symfony\\Component\\Validator\\ConstraintViolationListInterface>\) does not accept
Symfony\\Component\\Validator\\ConstraintViolationListInterface\.$# in path /Users/linus/git/valantic/pimcore-data-quality-bundle/src/Validation/DataObject/Attributes/AbstractAttribute.php was not matched in reported errors.
44 Property Valantic\DataQualityBundle\Validation\DataObject\Attributes\AbstractAttribute::$violations (Symfony\Component\Validator\ConstraintViolationListInterface) does not accept default value of type array.
121 Parameter #4 $violations of class Valantic\DataQualityBundle\Event\ConstraintFailureEvent constructor expects array, Symfony\Component\Validator\ConstraintViolationListInterface given.
------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line Validation/DataObject/Attributes/FieldCollectionAttribute.php
------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
20 Parameter #1 ...$arrays of function array_merge_recursive expects array, Symfony\Component\Validator\ConstraintViolationListInterface given.
20 Property Valantic\DataQualityBundle\Validation\DataObject\Attributes\AbstractAttribute::$violations (Symfony\Component\Validator\ConstraintViolationListInterface) does not accept array.
23 Parameter #4 $violations of class Valantic\DataQualityBundle\Event\ConstraintFailureEvent constructor expects array, Symfony\Component\Validator\ConstraintViolationListInterface given.
------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line Validation/DataObject/Attributes/LocalizedAttribute.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
26 Symfony\Component\Validator\ConstraintViolationListInterface does not accept Symfony\Component\Validator\ConstraintViolationListInterface.
29 Parameter #4 $violations of class Valantic\DataQualityBundle\Event\ConstraintFailureEvent constructor expects array, Symfony\Component\Validator\ConstraintViolationListInterface given.
51 Parameter #2 $array of function array_key_exists expects array, Symfony\Component\Validator\ConstraintViolationListInterface given.
52 Parameter #1 $value of function count expects array|Countable, Symfony\Component\Validator\ConstraintViolationInterface given.
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Can you please make the necessary changes?
In the Valantic\DataQualityBundle\Validation\DataObject\Attributes\AbstractAttribute class wich is called from the showAction() method from ScoreController:87 calls the validate() function ->
{ $this->violations = $this->getValidator()->validate($this->value(), $this->getConstraints(), $this->groups); } catch (\Throwable $e)
{ $this->eventDispatcher->dispatch(new ConstraintFailureEvent($e, $this->obj->getId(), $this->attribute, $this->violations)); } }
$this->getValidator()>validate($this>value(), $this->getConstraints(), $this->groups);, this method returns a object ConstraintViolationList but expects an array, so when trying to assign the protected array $violations = []; it will throw this error: "Cannot assign Symfony\Component\Validator\ConstraintViolationList to property Valantic\DataQualityBundle\Validation\DataObject\Attributes\AbstractAttribute::$violations of type array"
So the fix here is to change the protected array $violations = []; to this:
protected ConstraintViolationList $violations;