Completed
Push — master ( a2db3f...116d3d )
by Andrii
03:06 queued 50s
created

CommitsController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 8
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 51
ccs 0
cts 33
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A actionBump() 0 6 2
B actionDoBump() 0 23 4
A getHistory() 0 4 1
A getHandler() 0 4 1
1
<?php
2
3
/*
4
 * Task runner, code generator and build tool for easier continuos integration
5
 *
6
 * @link      https://github.com/hiqdev/hidev
7
 * @package   hidev
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\controllers;
13
14
use yii\base\InvalidParamException;
15
16
/**
17
 * Controller for reading and writing commits history to build CHANGELOG.md.
18
 */
19
class CommitsController extends FileController
20
{
21
    protected $_before = ['git']; /// TODO must be 'vcs' or detected
22
23
    protected $_file = '.hidev/commits.md';
24
25
    public $fileType = 'commits';
26
27
    protected $_version;
28
29
    public function actionBump($version = null)
30
    {
31
        $this->_version = $version ?: $this->takeGoal('bump')->version;
32
33
        return $this->runActions(['load', 'do-bump', 'save']);
34
    }
35
36
    public function actionDoBump()
37
    {
38
        $history = $this->getHistory();
39
        $new = [];
40
        $first = true;
41
        foreach ($history as $tag => $value) {
42
            if (substr($tag, 0, strlen($this->_version)) === $this->_version) {
43
                throw new InvalidParamException('Version already there: ' . $this->_version);
44
            }
45
            if ($first) {
46
                $first = false;
47
                $new[$tag] = ['tag' => $tag];
48
                $tag = $this->_version . $this->getHandler()->renderDate('today');
49
                $value['tag'] = $tag;
50
            }
51
            $new[$tag] = $value;
52
        }
53
54
        $this->getHandler()->setHistory($new);
55
56
        /// TODO strange shouldn't be needed
57
        $this->actionSave();
58
    }
59
60
    public function getHistory()
61
    {
62
        return $this->getHandler()->getHistory();
63
    }
64
65
    public function getHandler()
66
    {
67
        return $this->getFile()->getHandler();
68
    }
69
}
70