Completed
Push — master ( 27ccb2...cf0928 )
by Andrii
02:46
created

VersionController::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

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 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
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
/**
15
 * Goal for version file management.
16
 */
17
class VersionController extends FileController
18
{
19
    protected $_file = 'version';
20
21
    public $version;
22
    public $date;
23
    public $time;
24
    public $zone;
25
    public $hash;
26
27
    public function init()
28
    {
29
        $v = trim($this->getFile()->read());
30
        list($this->version, $this->date, $this->time, $this->zone, $this->hash) = explode(' ', $v);
31
    }
32
33
    public function actionMake($version = null)
34
    {
35
        list($date, $time, $zone, $hash) = explode(' ', trim(reset($this->exec('git', ['log', '-n', 1, '--pretty=%ai %H']))));
0 ignored issues
show
Bug introduced by
$this->exec('git', array... 1, '--pretty=%ai %H')) cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
Documentation introduced by
array('log', '-n', 1, '--pretty=%ai %H') is of type array<integer,string|int...integer","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...
36
        if ($hash !== $this->hash) {
37
            $this->version = 'dev';
38
        }
39
        $version = $version ?: $this->takeGoal('bump')->version ?: $this->version ?: 'dev';
40
        $this->getFile()->write(implode(' ', [$version, $date, $time, $zone, $hash]) . "\n");
41
    }
42
}
43