Completed
Push — master ( a0f8dd...4bb285 )
by Andrii
13:40
created

Version   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 57
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 9 2
A load() 0 8 2
A save() 0 4 1
A setRelease() 0 4 1
A getRelease() 0 4 3
A pretty() 0 4 1
A getAbspath() 0 4 1
1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\components;
12
13
/**
14
 * `version` file component.
15
 */
16
class Version extends \hidev\base\ConfigFile
17
{
18
    protected $_file = 'version';
19
20
    protected $fileRelease;
21
    protected $fileHash;
22
    protected $release;
23
    protected $date;
24
    protected $time;
25
    protected $zone;
26
    protected $hash;
27
    protected $commit;
28
29
    public function init()
30
    {
31
        if ($this->exists()) {
32
            $line = trim($this->getFile()->read());
33
            list($this->release, $this->date, $this->time, $this->zone, $this->hash) = explode(' ', $line);
34
            $this->fileRelease = $this->release;
35
            $this->fileHash = $this->hash;
36
        }
37
    }
38
39
    public function load()
40
    {
41
        $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...
42
        list($this->date, $this->time, $this->zone, $this->hash, $this->commit) = explode(' ', $line, 5);
43
        if ($this->hash !== $this->fileHash) {
44
            $this->release = implode('-', ['dev', $this->release, substr($this->hash, 0, 7)]);
45
        }
46
    }
47
48
    public function save()
49
    {
50
        $this->getFile()->write(implode(' ', [$this->release, $this->date, $this->time, $this->zone, $this->hash]) . "\n");
51
    }
52
53
    public function setRelease($release = null)
54
    {
55
        $this->release = $this->getRelease($release);
56
    }
57
58
    public function getRelease($release = null)
59
    {
60
        return $release ?: $this->release ?: 'dev';
61
    }
62
63
    public function pretty()
64
    {
65
        return implode(' ', [$this->release, $this->date, $this->time, $this->hash]);
66
    }
67
68
    public function getAbspath()
69
    {
70
        return $this->getFile()->getAbspath();
71
    }
72
}
73