LimitSubjectLength   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A pass() 0 8 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
use SebastianFeldmann\Git\CommitMessage;
15
16
/**
17
 * Class LimitSubjectLength
18
 *
19
 * @package CaptainHook
20
 * @author  Sebastian Feldmann <[email protected]>
21
 * @link    https://github.com/captainhook-git/captainhook
22
 * @since   Class available since Release 0.9.0
23
 */
24
class LimitSubjectLength extends Base
25
{
26
    /**
27
     * Length limit
28
     *
29
     * @var int
30
     */
31
    protected $maxLength;
32
33
    /**
34
     * Constructor
35
     *
36
     * @param int $length
37
     */
38 8
    public function __construct(int $length = 50)
39
    {
40 8
        $this->hint      = 'Subject line should not exceed ' . $length . ' characters';
41 8
        $this->maxLength = $length;
42
    }
43
44
    /**
45
     * Check if commit message doesn't exceeed the max length
46
     *
47
     * @param  \SebastianFeldmann\Git\CommitMessage $msg
48
     * @return bool
49
     */
50 8
    public function pass(CommitMessage $msg): bool
51
    {
52 8
        $subjectLength = mb_strlen($msg->getSubject());
53 8
        if ($subjectLength > $this->maxLength) {
54 2
            $this->hint .= ' (' . $subjectLength . ')';
55 2
            return false;
56
        }
57 6
        return true;
58
    }
59
}
60