Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/score-calculation #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

asdrenxhafa
Copy link

In the Valantic\DataQualityBundle\Validation\DataObject\Attributes\AbstractAttribute class wich is called from the
showAction() method from ScoreController:87 calls the validate() function ->

protected array $violations = []; , line:45

public function validate(): void
{
    try

{ $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;

@limenet
Copy link
Member

limenet commented Jun 14, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants