Passed
Push — master ( d65579...d73657 )
by Magnar Ovedal
02:20
created

RuleException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 4
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice\Rule;
6
7
use RuntimeException;
8
use Throwable;
9
10
/**
11
 * Exception thrown when a rule could not be enforced.
12
 */
13
final class RuleException extends RuntimeException
14
{
15
    /**
16
     * @var RuleInterface Rule that could not be enforced.
17
     */
18
    private $rule;
19
20
    /**
21
     * @var int Weight of violated constraint.
22
     */
23
    private $weight;
24
25
    /**
26
     * @param RuleInterface $rule Rule that could not be enforced.
27
     * @param int $weight Weight of violated constraint.
28
     * @param string $message Exception message.
29
     * @param Throwable|null $previous Previous exception, used for exception chaining.
30
     */
31 1
    public function __construct(RuleInterface $rule, int $weight, string $message, ?Throwable $previous = null)
32
    {
33 1
        $this->rule = $rule;
34 1
        $this->weight = $weight;
35
36 1
        parent::__construct($message, /*code*/0, $previous);
37 1
    }
38
39
    /**
40
     * @return RuleInterface Rule that could not be enforced.
41
     */
42 1
    public function getRule(): RuleInterface
43
    {
44 1
        return $this->rule;
45
    }
46
47
    /**
48
     * @return int Weight of violated constraint.
49
     */
50 1
    public function getWeight(): int
51
    {
52 1
        return $this->weight;
53
    }
54
}
55