Completed
Push — master ( 808823...246322 )
by Andrii
02:33
created

MarkdownParser   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 43
ccs 21
cts 21
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D parseLines() 0 40 9
1
<?php
2
3
/*
4
 * Changelog keeper
5
 *
6
 * @link      https://github.com/hiqdev/chkipper
7
 * @package   chkipper
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\chkipper\history;
13
14
/**
15
 * Markdown history parser.
16
 *
17
 * @author Andrii Vasyliev <[email protected]>
18
 */
19
class MarkdownParser extends AbstractParser
20
{
21 2
    public function parseLines(array $lines)
22
    {
23 2
        $this->getHistory()->initTags();
24
25 2
        $no = 0;
26 2
        foreach ($lines as $str) {
27 2
            $str = rtrim($str);
28 2
            ++$no;
29
30
            /// skip empty lines
31 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...
32
33
            /// headers
34 2
            } elseif ($no <= 2 || preg_match('/^# /', $str)) {
35 2
                $this->addHeader($str);
36
37
            /// links
38 2
            } elseif (preg_match('/^\[(.*?)\]:\s*(.*)$/', $str, $m)) {
39 2
                $this->addLink($m[1], $m[2]);
40
41
            /// tags
42 2
            } elseif (preg_match('/^##\s+\[(.+)\]\s*-?\s*(.*)$/', $str, $m)) {
43 2
                $this->addTag($m[1], $m[2]);
44
45
            /// notes
46 2
            } elseif (preg_match('/^-\s+(.*)$/', $str, $m)) {
47 2
                $this->addNote($m[1]);
48
49
            /// commits
50 2
            } elseif (preg_match('/^\s+-\s+\[?([0-9a-fA-F]{7})\]?\s*(.*)$/', $str, $m)) {
51 2
                $this->addCommit($m[1], $m[2]);
52
53
            /// comments
54 2
            } else {
55 2
                $this->addComment($str);
56
            }
57 2
        }
58
59 2
        return $this->getHistory();
60
    }
61
}
62