|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Validator; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Validator\Rule\Callback; |
|
8
|
|
|
use Yiisoft\I18n\TranslatorInterface; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Rules represents multiple rules for a single value |
|
12
|
|
|
*/ |
|
13
|
|
|
class Rules |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var Rule[] |
|
17
|
|
|
*/ |
|
18
|
|
|
private array $rules = []; |
|
19
|
|
|
private ?TranslatorInterface $translator; |
|
20
|
|
|
private ?string $translationDomain; |
|
21
|
|
|
private ?string $translationLocale; |
|
22
|
|
|
|
|
23
|
7 |
|
public function __construct( |
|
24
|
|
|
iterable $rules = [], |
|
25
|
|
|
?TranslatorInterface $translator = null, |
|
26
|
|
|
?string $translationDomain = null, |
|
27
|
|
|
?string $translationLocale = null |
|
28
|
|
|
) { |
|
29
|
7 |
|
$this->translator = $translator; |
|
30
|
7 |
|
$this->translationDomain = $translationDomain; |
|
31
|
7 |
|
$this->translationLocale = $translationLocale; |
|
32
|
|
|
|
|
33
|
7 |
|
foreach ($rules as $rule) { |
|
34
|
4 |
|
$this->rules[] = $this->normalizeRule($rule); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
7 |
|
private function normalizeRule($rule): Rule |
|
39
|
|
|
{ |
|
40
|
7 |
|
if (is_callable($rule)) { |
|
41
|
1 |
|
$rule = new Callback($rule); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
7 |
|
if (!$rule instanceof Rule) { |
|
45
|
|
|
throw new \InvalidArgumentException('Rule should be either instance of Rule class or a callable'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
7 |
|
if ($this->translator !== null) { |
|
49
|
|
|
$rule->withTranslator($this->translator); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
7 |
|
if ($this->translationDomain !== null) { |
|
53
|
|
|
$rule->withTranslationDomain($this->translationDomain); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
7 |
|
if ($this->translationLocale !== null) { |
|
57
|
|
|
$rule->withTranslationLocale($this->translationLocale); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
7 |
|
return $rule; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
3 |
|
public function add(Rule $rule): void |
|
64
|
|
|
{ |
|
65
|
3 |
|
$this->rules[] = $this->normalizeRule($rule); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
7 |
|
public function validate($value, DataSetInterface $dataSet = null, bool $previousRulesErrored = false): Result |
|
69
|
|
|
{ |
|
70
|
7 |
|
$compoundResult = new Result(); |
|
71
|
|
|
/** |
|
72
|
|
|
* @var $rule Rule |
|
73
|
|
|
*/ |
|
74
|
7 |
|
foreach ($this->rules as $rule) { |
|
75
|
7 |
|
$ruleResult = $rule->validate($value, $dataSet, $previousRulesErrored); |
|
76
|
7 |
|
if ($ruleResult->isValid() === false) { |
|
77
|
7 |
|
$previousRulesErrored = true; |
|
78
|
7 |
|
foreach ($ruleResult->getErrors() as $message) { |
|
79
|
7 |
|
$compoundResult->addError($message); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
7 |
|
return $compoundResult; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
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