1 | <?php |
||
22 | class Blacklist extends Base |
||
23 | { |
||
24 | /** |
||
25 | * Case sensitivity |
||
26 | * |
||
27 | * @var bool |
||
28 | */ |
||
29 | protected $isCaseSensitive; |
||
30 | |||
31 | /** |
||
32 | * Blacklisted words |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $blacklist = [ |
||
37 | 'subject' => [], |
||
38 | 'body' => [], |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Constructor. |
||
43 | * |
||
44 | * @param bool $caseSensitive |
||
45 | */ |
||
46 | public function __construct(bool $caseSensitive = false) |
||
47 | { |
||
48 | $this->isCaseSensitive = $caseSensitive; |
||
49 | $this->hint = 'Commit message should not contain blacklisted words'; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Set body blacklist. |
||
54 | * |
||
55 | * @param array $list |
||
56 | */ |
||
57 | public function setBodyBlacklist(array $list) |
||
58 | { |
||
59 | $this->setBlacklist($list, 'body'); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Set subject blacklist. |
||
64 | * |
||
65 | * @param array $list |
||
66 | */ |
||
67 | 4 | public function setSubjectBlacklist(array $list) |
|
71 | |||
72 | /** |
||
73 | * Blacklist setter. |
||
74 | * |
||
75 | * @param array $list |
||
76 | * @param string $type |
||
77 | */ |
||
78 | 4 | protected function setBlacklist(array $list, string $type) |
|
82 | |||
83 | /** |
||
84 | * Check if the message contains blacklisted words. |
||
85 | * |
||
86 | * @param \SebastianFeldmann\Git\CommitMessage $msg |
||
87 | * @return bool |
||
88 | */ |
||
89 | 3 | public function pass(CommitMessage $msg) : bool |
|
93 | |||
94 | /** |
||
95 | * Check commit message subject for blacklisted words. |
||
96 | * |
||
97 | * @param \SebastianFeldmann\Git\CommitMessage $msg |
||
98 | * @return bool |
||
99 | */ |
||
100 | 3 | protected function isSubjectValid(CommitMessage $msg) : bool |
|
104 | |||
105 | /** |
||
106 | * Check commit message body for blacklisted words. |
||
107 | * |
||
108 | * @param \SebastianFeldmann\Git\CommitMessage $msg |
||
109 | * @return bool |
||
110 | */ |
||
111 | 2 | protected function isBodyValid(CommitMessage $msg) : bool |
|
115 | |||
116 | /** |
||
117 | * Contains blacklisted word. |
||
118 | * |
||
119 | * @param array $list |
||
120 | * @param string $content |
||
121 | * @return bool |
||
122 | */ |
||
123 | 3 | protected function containsBlacklistedWord(array $list, string $content) : bool |
|
137 | } |
||
138 |