Completed
Push — master ( aa9657...bb9832 )
by Sebastian
05:21
created

CapitalizeSubject::pass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
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 SebastianFeldmann\CaptainHook\Hook\Message\Rule;
11
12
use SebastianFeldmann\Git\CommitMessage;
13
14
/**
15
 * Class CapitdalizeSubject
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 CapitalizeSubject extends Base
23
{
24
    /**
25
     * Constructor.
26
     */
27 7
    public function __construct()
28
    {
29 7
        $this->hint = 'Subject line has to start with an upper case letter';
30 7
    }
31
32
    /**
33
     * Check if commit message starts with upper case letter.
34
     *
35
     * @param  \SebastianFeldmann\Git\CommitMessage $msg
36
     * @return bool
37
     */
38 7
    public function pass(CommitMessage $msg) : bool
39
    {
40 7
        if (!$msg->isEmpty()) {
41 6
            $firstLetter = substr($msg->getSubject(), 0, 1);
42 6
            return $firstLetter === strtoupper($firstLetter);
43
        }
44 1
        return false;
45
    }
46
}
47