Completed
Push — master ( 7b4929...cefe8d )
by Andrii
01:50
created

BumpController::actionParse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
cc 2
eloc 6
nc 2
nop 1
crap 6
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, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\chkipper\console;
12
13
use Exception;
14
use hiqdev\chkipper\changelog\MarkdownRenderer as ChangelogMarkdownRenderer;
15
use hiqdev\chkipper\helpers\File;
16
use hiqdev\chkipper\history\GitLogParser;
17
use hiqdev\chkipper\history\MarkdownParser;
18
use hiqdev\chkipper\history\MarkdownRenderer;
19
use Yii;
20
21
/**
22
 * Bump Controller.
23
 *
24
 * @author Andrii Vasyliev <[email protected]>
25
 */
26
class BumpController extends \yii\console\Controller
27
{
28
    public function actionIndex($version = null)
29
    {
30
        $config = Yii::$app->config;
31
        $historyFile = $config->historyFile;
32
        $changelogFile = $config->changelogFile;
33
        $parser = Yii::createObject(MarkdownParser::class);
34
        $history = $parser->parsePath($historyFile);
35
        $gitlog = Yii::createObject(GitLogParser::class);
36
        $gitlog->parseGitLog();
37
        $history->merge($gitlog->getHistory(), true);
38
        $history->normalize();
39
40
        if ($version) {
41
            if ($version === 'dev') {
42
                $version = $history->lastTag;
43
            }
44
            $history->setFirstTag($version);
45
        }
46
47
        $historyRenderer = Yii::createObject(MarkdownRenderer::class);
48
        $changelogRenderer = Yii::createObject(ChangelogMarkdownRenderer::class);
49
        File::write($historyFile,  $historyRenderer->render($history));
50
        File::write($changelogFile,  $changelogRenderer->render($history));
51
    }
52
53
    public function actionParse($path)
54
    {
55
        if (!file_exists($path)) {
56
            throw new Exception('wrong path: ' . $path);
57
        }
58
        $parser = new MarkdownParser();
0 ignored issues
show
Bug introduced by
The call to MarkdownParser::__construct() misses a required argument $config.

This check looks for function calls that miss required arguments.

Loading history...
59
        $history = $parser->parsePath($path);
60
        var_dump($history->getTags());
0 ignored issues
show
Security Debugging Code introduced by
var_dump($history->getTags()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
61
    }
62
}
63