1 | <?php |
||
23 | class RuleBook |
||
24 | { |
||
25 | /** |
||
26 | * List of rules to check |
||
27 | * |
||
28 | * @var \SebastianFeldmann\CaptainHook\Hook\Message\Rule[] |
||
29 | */ |
||
30 | private $rules = []; |
||
31 | |||
32 | /** |
||
33 | * Set rules to check. |
||
34 | * |
||
35 | * @param \SebastianFeldmann\CaptainHook\Hook\Message\Rule[] $rules |
||
36 | * @return \SebastianFeldmann\CaptainHook\Hook\Message\Rulebook |
||
37 | */ |
||
38 | 6 | public function setRules(array $rules) |
|
43 | |||
44 | /** |
||
45 | * Add a rule to the list. |
||
46 | * |
||
47 | * @param \SebastianFeldmann\CaptainHook\Hook\Message\Rule $rule |
||
48 | * @return \SebastianFeldmann\CaptainHook\Hook\Message\Rulebook |
||
49 | */ |
||
50 | 2 | public function addRule(Rule $rule) |
|
55 | |||
56 | /** |
||
57 | * Validates all rules. |
||
58 | * |
||
59 | * @param \SebastianFeldmann\Git\CommitMessage $msg |
||
60 | * @throws \SebastianFeldmann\CaptainHook\Exception\ActionFailed |
||
61 | */ |
||
62 | 9 | public function validate(CommitMessage $msg) |
|
77 | |||
78 | /** |
||
79 | * Format the error output. |
||
80 | * |
||
81 | * @param array $problems |
||
82 | * @return string |
||
83 | */ |
||
84 | 4 | private function getOutput(array $problems) : string |
|
99 | |||
100 | /** |
||
101 | * Indent multi line problems so the lines after the first one are indented for better readability. |
||
102 | * |
||
103 | * @param string $problem |
||
104 | * @return string |
||
105 | */ |
||
106 | 4 | private function formatProblem(string $problem) : string |
|
119 | } |
||
120 |