Skip to content

Commit

Permalink
feat: added groups to SymfonyValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
rasstislav authored and f3l1x committed Dec 15, 2024
1 parent e0f8101 commit 93c4807
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions .docs/mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ services:
- setConstraintValidatorFactory(Contributte\Validator\ContainerConstraintValidatorFactory())
- setTranslator(@Contributte\Translation\Translator)
- setTranslationDomain('validators')
- setGroups(['input'])
api:
plugins:
Apitte\Core\DI\Plugin\CoreMappingPlugin:
Expand Down
9 changes: 8 additions & 1 deletion src/Core/Mapping/Validator/SymfonyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class SymfonyValidator implements IEntityValidator

private ?string $translationDomain = null;

private ?array $groups = null;

Check failure on line 24 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

@var annotation of property \Apitte\Core\Mapping\Validator\SymfonyValidator::$groups does not specify type hint for its items.

Check failure on line 24 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.2)

Property Apitte\Core\Mapping\Validator\SymfonyValidator::$groups type has no value type specified in iterable type array.

Check failure on line 24 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

@var annotation of property \Apitte\Core\Mapping\Validator\SymfonyValidator::$groups does not specify type hint for its items.

Check failure on line 24 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.2)

Property Apitte\Core\Mapping\Validator\SymfonyValidator::$groups type has no value type specified in iterable type array.

Check failure on line 24 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

@var annotation of property \Apitte\Core\Mapping\Validator\SymfonyValidator::$groups does not specify type hint for its items.

public function __construct(?Reader $reader = null)
{
$this->reader = $reader;
Expand All @@ -42,6 +44,11 @@ public function setTranslationDomain(string $translationDomain): void
$this->translationDomain = $translationDomain;
}

public function setGroups(array $groups): void

Check failure on line 47 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

Method \Apitte\Core\Mapping\Validator\SymfonyValidator::setGroups() does not have @param annotation for its traversable parameter $groups.

Check failure on line 47 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.2)

Method Apitte\Core\Mapping\Validator\SymfonyValidator::setGroups() has parameter $groups with no value type specified in iterable type array.

Check failure on line 47 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

Method \Apitte\Core\Mapping\Validator\SymfonyValidator::setGroups() does not have @param annotation for its traversable parameter $groups.

Check failure on line 47 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.2)

Method Apitte\Core\Mapping\Validator\SymfonyValidator::setGroups() has parameter $groups with no value type specified in iterable type array.

Check failure on line 47 in src/Core/Mapping/Validator/SymfonyValidator.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

Method \Apitte\Core\Mapping\Validator\SymfonyValidator::setGroups() does not have @param annotation for its traversable parameter $groups.
{
$this->groups = $groups;
}

/**
* @throws ValidationException
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
Expand All @@ -67,7 +74,7 @@ public function validate(object $entity): void
$validator = $validatorBuilder->getValidator();

/** @var ConstraintViolationListInterface $violations */
$violations = $validator->validate($entity);
$violations = $validator->validate($entity, null, $this->groups);

if (count($violations) > 0) {
$fields = [];
Expand Down

0 comments on commit 93c4807

Please sign in to comment.