1 | <?php declare(strict_types=1); |
||
19 | class DbEntityDataValidator |
||
20 | { |
||
21 | /** |
||
22 | * @var ValidatorTranslatorInterface|SymfonyTranslatorInterface|null |
||
23 | */ |
||
24 | protected $translator; |
||
25 | |||
26 | 3 | public function __construct($translator = null) |
|
30 | |||
31 | /** |
||
32 | * Create a data validator for database entity. |
||
33 | * |
||
34 | * @param AbstractDbEntity $dbEntity |
||
35 | * @return Validator |
||
36 | */ |
||
37 | 3 | public function createValidator(AbstractDbEntity $dbEntity, ...$params): Validator |
|
38 | { |
||
39 | 3 | $fieldsRuleProperties = $this->getDbEntityFieldsRuleProperties($dbEntity); |
|
40 | 3 | $validator = new Validator($fieldsRuleProperties, $this->translator); |
|
41 | |||
42 | 3 | if (($additionalFieldsRuleProperties = $this->getAdditionalFieldsRuleProperties($dbEntity, ...$params))) { |
|
|
|||
43 | 1 | $validator->addFieldsRuleProperties($additionalFieldsRuleProperties); |
|
44 | } |
||
45 | |||
46 | 3 | return $validator; |
|
47 | } |
||
48 | |||
49 | 3 | protected function getDbEntityFieldsRuleProperties(AbstractDbEntity $dbEntity): array |
|
67 | |||
68 | 2 | protected function getAdditionalFieldsRuleProperties(AbstractDbEntity $dbEntity): array |
|
72 | |||
73 | /** |
||
74 | * Validate and (if no error messages) set database data. |
||
75 | * |
||
76 | * @param array $data The data (e.g. from a form post) to be validated and set |
||
77 | * @return array An array with all (if any) of error messages |
||
78 | */ |
||
79 | 2 | public function validateAndSet(AbstractDbEntity $dbEntity, array $data): array |
|
94 | |||
95 | 2 | protected function preProcessValidationDbData(AbstractDbEntity $dbEntity, array $data): array |
|
99 | |||
100 | 1 | protected function setValidatedDbData(AbstractDbEntity $dbEntity, array $validatedData) |
|
111 | } |
||
112 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.