CommitMessageHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 16
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A appendContent() 0 22 5
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright Andrea Heigl <[email protected]>
7
 *
8
 * Licenses under the MIT-license. For details see the included file LICENSE.md
9
 */
10
11
namespace Org_Heigl\CaptainHook\Hooks\AddTime\CommitMessage;
12
13
use SebastianFeldmann\Git\CommitMessage;
14
15
class CommitMessageHandler
16
{
17
    private $message;
18
19
    public function __construct(CommitMessage $message)
20
    {
21
        $this->message = $message;
22
    }
23
24
    public function appendContent(string $addedLine, $beforeFinalComment = true) : CommitMessage
25
    {
26
        $content = $this->message->getLines();
27
        $linecounter = count($content);
28
        if ($beforeFinalComment) {
29
            foreach (array_reverse($content) as $line) {
30
                if (strpos($line, $this->message->getCommentCharacter()) === 0) {
31
                    --$linecounter;
32
                    continue;
33
                }
34
                if (strlen(trim($line)) === 0) {
35
                    --$linecounter;
36
                    continue;
37
                }
38
39
                break;
40
            }
41
        }
42
43
        array_splice($content, $linecounter  + 1, 0, [$addedLine]);
44
45
        return new CommitMessage(implode("\n", $content), $this->message->getCommentCharacter());
46
    }
47
}