VersionAction::get()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace api\actions;
4
5
use yrc\rest\Action;
6
use yii\helpers\Json;
7
8
/**
9
 * @class VersionAction
10
 * Returns the version string for the correct environment
11
 */
12
class VersionAction extends Action
13
{
14
    /**
15
     * @param array $params
16
     */
17
    public function get(array $params = [])
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
        $data = [];
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
20
        $versionFile = ROOT . '/VERSION';
21
        $gitHead = ROOT . '/.git/HEAD';
22
        if (\file_exists($versionFile)) {
23
            $data = Json::decode(\file_get_contents(ROOT . '/VERSION'));
24
        } elseif (\file_exists($gitHead)) {
25
            $gitRevision = \file_get_contents($gitHead);
26
            $path = \explode('/', $gitRevision);
27
            $data = [
28
                'build' => \str_replace("\n", '', 'dev-' . $path[2]),
29
                'date' => date('D M d h:i:s T Y', \filemtime($gitHead))
30
            ];
31
        } else {
32
            $data = [
33
                'build' => 'unknown',
34
                'date' => date('D M d h:i:s T Y')
35
            ];
36
        }
37
38
        return $data;
39
    }
40
}
41