Version::run()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 9.2568
c 0
b 0
f 0
cc 5
nc 6
nop 1
crap 5
1
<?php
2
3
namespace Basis\Job\Module;
4
5
use Basis\Filesystem;
6
use Basis\Job;
7
8
class Version extends Job
9
{
10 3
    public function run(Filesystem $fs)
11
    {
12
        $version = [
13 3
            'service' => null,
14
            'php' => PHP_VERSION,
15
        ];
16 3
17 3
        if (file_exists($fs->getPath('version.php'))) {
18 1
            $git = include $fs->getPath('version.php');
19 1
            $version['service'] = $git['tag'] ?: $git['short_sha'];
20 1
        }
21
22
        $lock = $fs->getPath('composer.lock');
23
        if (is_file($lock)) {
24 3
            $info = json_decode(file_get_contents($lock));
25
            foreach ($info->packages as $package) {
26
                $version[$package->name] = $package->version;
27
            }
28
        }
29
30
        return compact('version');
31
    }
32
}
33