ConvertController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 26
ccs 0
cts 19
cp 0
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 24 5
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\console;
12
13
use Exception;
14
use hiqdev\chkipper\helpers\File;
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 commit 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::write($historyFile,  $history);
48
    }
49
}
50