Total Complexity | 4 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
15 | final class PolicyException extends RuntimeException |
||
16 | { |
||
17 | /** |
||
18 | * @var Policy Policy that could not be enforced. |
||
19 | */ |
||
20 | private $policy; |
||
21 | |||
22 | /** |
||
23 | * @var RuleException[] Exceptions thrown by rules that could not be enforced. |
||
24 | */ |
||
25 | private $ruleExceptions = []; |
||
26 | |||
27 | /** |
||
28 | * @param Policy $policy Policy that could not be enforced. |
||
29 | * @param RuleException[] $ruleExceptions Exceptions thrown by rules that could not be enforced. |
||
30 | * @param Throwable $previous Previous exception, used for exception chaining. |
||
31 | */ |
||
32 | 1 | public function __construct(Policy $policy, array $ruleExceptions, ?Throwable $previous = null) |
|
33 | { |
||
34 | 1 | $this->policy = $policy; |
|
35 | 1 | $this->ruleExceptions = $ruleExceptions; |
|
36 | |||
37 | 1 | $messages = []; |
|
38 | 1 | foreach ($ruleExceptions as $ruleException) { |
|
39 | 1 | $messages[] = $ruleException->getMessage(); |
|
40 | } |
||
41 | |||
42 | 1 | parent::__construct(implode(' ', $messages), /*code*/0, $previous); |
|
43 | 1 | } |
|
44 | |||
45 | /** |
||
46 | * @return Policy Policy that could not be enforced. |
||
47 | */ |
||
48 | 1 | public function getPolicy(): Policy |
|
49 | { |
||
50 | 1 | return $this->policy; |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * @return RuleException[] Exceptions thrown by rules in the policy that could not be enforced. |
||
55 | */ |
||
56 | 1 | public function getRuleExceptions(): array |
|
59 | } |
||
60 | } |
||
61 |