Passed
Push — master ( 30b9f9...28ee83 )
by Magnar Ovedal
02:55
created

PolicyException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 44
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRuleExceptions() 0 3 1
A __construct() 0 11 2
A getPolicy() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice;
6
7
use RuntimeException;
8
use Stadly\PasswordPolice\Rule\RuleException;
9
use Symfony\Component\Translation\Translator;
10
use Throwable;
11
12
/**
13
 * Exception thrown when a policy could not be enforced.
14
 */
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
57
    {
58 1
        return $this->ruleExceptions;
59
    }
60
}
61