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

ConvertController::actionIndex()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
ccs 0
cts 20
cp 0
rs 8.439
cc 5
eloc 15
nc 5
nop 0
crap 30
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