|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Validator\Helper; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Validator\PropagateOptionsInterface; |
|
8
|
|
|
use Yiisoft\Validator\RuleInterface; |
|
9
|
|
|
use Yiisoft\Validator\SkipOnEmptyInterface; |
|
10
|
|
|
use Yiisoft\Validator\SkipOnErrorInterface; |
|
11
|
|
|
use Yiisoft\Validator\WhenInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* A helper class used to propagate options' values from a single parent rule to its child rules at all nesting levels |
|
15
|
|
|
* recursively. |
|
16
|
|
|
*/ |
|
17
|
|
|
final class PropagateOptionsHelper |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Propagates options' values from a single parent rule to its all child rules at all nesting levels recursively. |
|
21
|
|
|
* The following options' values are propagated: |
|
22
|
|
|
* |
|
23
|
|
|
* - `$skipOnEmpty` (both rules must implement {@see SkipOnEmptyInterface}). |
|
24
|
|
|
* - `$skipOnError` (both rules must implement {@see SkipOnErrorInterface}). |
|
25
|
|
|
* - `$when` (both rules must implement {@see WhenInterface}). |
|
26
|
|
|
* |
|
27
|
|
|
* @param RuleInterface $parentRule A parent rule which options' values need to be propagated. |
|
28
|
|
|
* @param iterable<RuleInterface> $childRules Direct child rules for this particular parent rule which options' |
|
29
|
|
|
* values must be changed to be the same as in parent rule. |
|
30
|
|
|
* |
|
31
|
|
|
* @return list<RuleInterface> A list of child rules of the same nesting level with changed options' values or |
|
|
|
|
|
|
32
|
|
|
* unchanged if none of the required interfaces were implemented. The order is preserved. |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function propagate(RuleInterface $parentRule, iterable $childRules): array |
|
35
|
|
|
{ |
|
36
|
|
|
$rules = []; |
|
37
|
|
|
foreach ($childRules as $childRule) { |
|
38
|
|
|
$rules[] = self::propagateToRule($parentRule, $childRule); |
|
39
|
|
|
} |
|
40
|
|
|
return $rules; |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Performs propagation of options' values for a single pair of one parent rule and one of its direct child rules. |
|
45
|
|
|
* If the child rule also supports such propagation, it delegates the further propagation to |
|
46
|
|
|
* {@see PropagateOptionsInterface::propagateOptions()} implementation in this child rule. |
|
47
|
|
|
* |
|
48
|
|
|
* @param RuleInterface $parentRule A parent rule which options' values need to be propagated. |
|
49
|
|
|
* @param RuleInterface $childRule One of the direct child rules for this particular parent rule which options' |
|
50
|
|
|
* values must be changed to be the same as in parent rule. |
|
51
|
|
|
* |
|
52
|
|
|
* @return RuleInterface The same child rule instance with changed options' values or unchanged if none of the |
|
53
|
|
|
* required interfaces were implemented. |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function propagateToRule(RuleInterface $parentRule, RuleInterface $childRule): RuleInterface |
|
56
|
|
|
{ |
|
57
|
|
|
if ($parentRule instanceof SkipOnEmptyInterface && $childRule instanceof SkipOnEmptyInterface) { |
|
58
|
|
|
$childRule = $childRule->skipOnEmpty($parentRule->getSkipOnEmpty()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if ($parentRule instanceof SkipOnErrorInterface && $childRule instanceof SkipOnErrorInterface) { |
|
62
|
|
|
$childRule = $childRule->skipOnError($parentRule->shouldSkipOnError()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($parentRule instanceof WhenInterface && $childRule instanceof WhenInterface) { |
|
66
|
|
|
$childRule = $childRule->when($parentRule->getWhen()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ($childRule instanceof PropagateOptionsInterface) { |
|
70
|
|
|
$childRule->propagateOptions(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $childRule; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
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