Passed
Push — master ( b649b5...b34030 )
by Sebastian
04:07
created

UseImperativeMood   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 34
c 0
b 0
f 0
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A pass() 0 17 3
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace CaptainHook\Hook\Message\Validator\Rule;
11
12
use CaptainHook\Git\CommitMessage;
13
14
/**
15
 * Class UseImperativeMood
16
 *
17
 * @package CaptainHook
18
 * @author  Sebastian Feldmann <[email protected]>
19
 * @link    https://github.com/sebastianfeldmann/captainhook
20
 * @since   Class available since Release 0.9.0
21
 */
22
class UseImperativeMood extends Base
23
{
24
    /**
25
     * Constructor.
26
     */
27 5
    public function __construct()
28
    {
29 5
        $this->hint = 'Subject should be written in imperative mood';
30 5
    }
31
32
    /**
33
     * Check if commit message is written in imperative mood.
34
     *
35
     * @param  \CaptainHook\Git\CommitMessage $msg
36
     * @return bool
37
     */
38 4
    public function pass(CommitMessage $msg)
39
    {
40 4
        $lowerSubject = strtolower($msg->getSubject());
41
        $blackList    = [
42 4
            'uploaded',
43
            'updated',
44
            'added',
45
            'created',
46
        ];
47 4
        foreach ($blackList as $term) {
48 4
            if (strpos($lowerSubject, $term) !== false) {
49 1
                $this->hint .= PHP_EOL . 'Invalid use of \'' . $term . '\'';
50 4
                return false;
51
            }
52
        }
53 3
        return true;
54
    }
55
}
56