1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Knp\DictionaryBundle\Validator\Constraints\DictionaryValidator; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Form\Exception\UnexpectedTypeException; |
8
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
9
|
|
|
use Symfony\Component\Validator\Constraint; |
10
|
|
|
|
11
|
|
|
switch (Kernel::MAJOR_VERSION) { |
12
|
|
|
case 6: |
13
|
|
|
trait SymfonyCompatibilityTrait |
14
|
|
|
{ |
15
|
|
|
public function validate(mixed $value, Constraint $constraint): void |
16
|
|
|
{ |
17
|
|
|
if (!$constraint instanceof Dictionary) { |
|
|
|
|
18
|
|
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Dictionary'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
if (null === $value || '' === $value) { |
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$dictionary = $this->dictionaries[$constraint->name]; |
26
|
|
|
$values = $dictionary->getKeys(); |
27
|
|
|
|
28
|
|
|
if (!\in_array($value, $values, true)) { |
29
|
|
|
$this->context->addViolation( |
30
|
|
|
$constraint->message, |
31
|
|
|
[ |
32
|
|
|
'{{ key }}' => $this->varToString($value), |
|
|
|
|
33
|
|
|
'{{ keys }}' => implode(', ', array_map([$this, 'varToString'], $values)), |
34
|
|
|
] |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
break; |
41
|
|
|
|
42
|
|
|
case 5: |
43
|
|
|
trait SymfonyCompatibilityTrait |
44
|
|
|
{ |
45
|
|
|
public function validate($value, Constraint $constraint): void |
46
|
|
|
{ |
47
|
|
|
if (!$constraint instanceof Dictionary) { |
48
|
|
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Dictionary'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (null === $value || '' === $value) { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$dictionary = $this->dictionaries[$constraint->name]; |
56
|
|
|
$values = $dictionary->getKeys(); |
57
|
|
|
|
58
|
|
|
if (!\in_array($value, $values, true)) { |
59
|
|
|
$this->context->addViolation( |
60
|
|
|
$constraint->message, |
61
|
|
|
[ |
62
|
|
|
'{{ key }}' => $this->varToString($value), |
63
|
|
|
'{{ keys }}' => implode(', ', array_map([$this, 'varToString'], $values)), |
64
|
|
|
] |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
break; |
71
|
|
|
} |
72
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths