Completed
Push — master ( a9ea1a...62657b )
by Andrii
05:05
created

VersionController::actionSave()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Automation tool mixed with code generator for easier continuous development
5
 *
6
 * @link      https://github.com/hiqdev/hidev
7
 * @package   hidev
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\controllers;
13
14
/**
15
 * Goal for version file management.
16
 */
17
class VersionController extends FileController
18
{
19
    protected $_file = 'version';
20
21
    public $fileVersion;
22
23
    public $version;
24
    public $date;
25
    public $time;
26
    public $zone;
27
    public $hash;
28
    public $commit;
29
30
    public function init()
31
    {
32
        if ($this->exists()) {
33
            $line = trim($this->getFile()->read());
34
            list($this->version, $this->date, $this->time, $this->zone, $this->hash) = explode(' ', $line);
35
            $this->fileVersion = $this->version;
36
        }
37
    }
38
39
    public function actionMake($version = null)
40
    {
41
        $this->setVersion($version);
42
        $this->actionLoad();
43
        $this->actionSave();
44
    }
45
46
    public function actionLoad()
47
    {
48
        $line = trim($this->exec('git', ['log', '-n', '1', '--pretty=%ai %H %s'])[0]);
0 ignored issues
show
Documentation introduced by
array('log', '-n', '1', '--pretty=%ai %H %s') is of type array<integer,string,{"0..."string","3":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
        list($this->date, $this->time, $this->zone, $this->hash, $this->commit) = explode(' ', $line, 5);
50
    }
51
52
    public function actionSave()
53
    {
54
        $this->getFile()->write(implode(' ', [$this->version, $this->date, $this->time, $this->zone, $this->hash]) . "\n");
55
    }
56
57
    public function setVersion($version = null)
58
    {
59
        $this->version = $this->getVersion($version);
60
    }
61
62
    public function getVersion($version = null)
63
    {
64
        return $version ?: $this->version ?: 'dev';
65
    }
66
}
67