Completed
Push — master ( 69f712...a96098 )
by Andrii
02:39
created

ConvertController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 28
ccs 0
cts 20
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B actionIndex() 0 25 5
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\console;
13
14
use Exception;
15
use Yii;
16
17
/**
18
 * Convert Controller.
19
 *
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class ConvertController extends \yii\console\Controller
23
{
24
    public function actionIndex()
25
    {
26
        $commitsFile = '.hidev/commits.md';
27
        $historyFile = Yii::$app->config->historyFile;
28
29
        if (!file_exists($commitsFile)) {
30
            throw new Exception("no $commitsFile found");
31
        }
32
33
        $history = '';
34
        $commits = file($commitsFile);
35
        foreach ($commits as $line) {
36
            if (preg_match('/^## (\S+) (\S+)$/', $line, $m)) {
37
                $history .= "## [$m[1]] - $m[2]\n";
38
39
            # - ebeece6 2016-06-10 ommit message ([email protected])
40
            } elseif (preg_match('/^    - (\S{7}) (\S+) (.*?) \((\S+)\)$/', $line, $m)) {
41
                $history .= "    - [$m[1]] $m[2] $m[3] [$m[4]]\n";
42
            } else {
43
                $history .= $line;
44
            }
45
        }
46
47
        file_put_contents($historyFile,  $history);
48
    }
49
}
50