UseImperativeMood::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 16
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 25
ccs 20
cts 20
cp 1
crap 2
rs 9.7333
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Hook\Message\Rule;
13
14
/**
15
 * Class UseImperativeMood
16
 *
17
 * @package CaptainHook
18
 * @author  Sebastian Feldmann <[email protected]>
19
 * @link    https://github.com/captainhook-git/captainhook
20
 * @since   Class available since Release 0.9.0
21
 */
22
class UseImperativeMood extends Blacklist
23
{
24
    /**
25
     * Constructor
26
     *
27
     * @param bool $checkOnlyBeginning
28
     */
29 11
    public function __construct(bool $checkOnlyBeginning = false)
30
    {
31 11
        parent::__construct();
32
33 11
        $this->hint = 'A commit message subject should always complete the following sentence.'  . PHP_EOL .
34 11
                      'This commit will [YOUR COMMIT MESSAGE].';
35
36 11
        $this->setSubjectBlacklist(
37 11
            [
38 11
                'added',
39 11
                'changed',
40 11
                'created',
41 11
                'deleted',
42 11
                'fixed',
43 11
                'reformatted',
44 11
                'removed',
45 11
                'updated',
46 11
                'uploaded'
47 11
            ]
48 11
        );
49
50 11
        if ($checkOnlyBeginning) {
51
            // overwrite the detection logic to only check the beginning og the string
52 4
            $this->stringDetection = function (string $content, string $term): bool {
53 4
                return strpos($content, $term) === 0;
54 4
            };
55
        }
56
    }
57
}
58