Completed
Push — master ( cefe8d...0ca202 )
by Andrii
03:36
created

MarkdownParser   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 45
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D parseLines() 0 42 10
1
<?php
2
/**
3
 * Changelog keeper
4
 *
5
 * @link      https://github.com/hiqdev/chkipper
6
 * @package   chkipper
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\chkipper\history;
12
13
/**
14
 * Markdown history parser.
15
 *
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class MarkdownParser extends AbstractParser
19
{
20 2
    public function parseLines(array $lines)
21
    {
22 2
        $this->getHistory()->initTags();
23
24 2
        $no = 0;
25 2
        foreach ($lines as $str) {
26 2
            $str = rtrim($str);
27 2
            ++$no;
28
29
            /// skip empty lines
30 2
            if (!$str) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
31
                /// headers
32 2
            } elseif ($no <= 2 || preg_match('/^# /', $str)) {
33 2
                $this->addHeader($str);
34
35
            /// links
36 2
            } elseif (preg_match('/^\[(.*?)\]:\s*(.*)$/', $str, $m)) {
37 2
                $this->addLink($m[1], $m[2]);
38
39
            /// tags
40 2
            } elseif (
41 2
                preg_match('/^##\s+\[(.+?)\]\s*-?\s*(.*)$/', $str, $m) ||
42 2
                preg_match('/^##\s+(\S+?)\s*-\s*(.*)$/', $str, $m)
43 2
            ) {
44 2
                $this->addTag($m[1], $m[2]);
45
46
            /// notes
47 2
            } elseif (preg_match('/^-\s+(.*)$/', $str, $m)) {
48 2
                $this->addNote($m[1]);
49
50
            /// commits
51 2
            } elseif (preg_match('/^\s+-\s+\[?([0-9a-fA-F]{7})\]?\s*(.*)$/', $str, $m)) {
52 2
                $this->addCommit($m[1], $m[2]);
53
54
            /// comments
55 2
            } else {
56 2
                $this->addComment($str);
57
            }
58 2
        }
59
60 2
        return $this->getHistory();
61
    }
62
}
63