MarkdownParser   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 43
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B parseLines() 0 41 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\lib\parsers;
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) {
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