Passed
Push — master ( 69774c...de7969 )
by Sebastian
02:46
created

UseImperativeMood::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 9.7666
cc 2
nc 2
nop 1
crap 2
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/captainhookphp/captainhook
20
 * @since   Class available since Release 0.9.0
21
 */
22
class UseImperativeMood extends Blacklist
23
{
24
    /**
25
     * Constructor
26
     *
27 11
     * @param bool $checkOnlyBeginning
28
     */
29 11
    public function __construct(bool $checkOnlyBeginning = false)
30 11
    {
31 11
        parent::__construct(false);
32
        $this->hint = 'Subject should be written in imperative mood';
33 11
        $this->setSubjectBlacklist(
34
            [
35
                'added',
36
                'changed',
37
                'created',
38
                'deleted',
39
                'fixed',
40
                'reformatted',
41
                'removed',
42
                'updated',
43
                'uploaded'
44 11
            ]
45
        );
46
47 4
        if ($checkOnlyBeginning) {
48
            // overwrite the detection logic to only check the beginning og the string
49
            $this->stringDetection = function (string $content, string $term): bool {
50 11
                return strpos($content, $term) === 0;
51
            };
52
        }
53
    }
54
}
55