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

BumpController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 5
c 5
b 0
f 3
lcom 0
cbo 4
dl 0
loc 37
ccs 0
cts 31
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actionParse() 0 9 2
B actionIndex() 0 24 3
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