Assets   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 35
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 11 1
A map() 0 15 4
1
<?php
2
3
namespace Basis\Job\Module;
4
5
use Basis\Filesystem;
6
use Basis\Job;
7
8
class Assets extends Job
9
{
10
    private $fs;
11 3
    public function __construct(Filesystem $fs)
12
    {
13 3
        $this->fs = $fs;
14 3
    }
15 3
    public function run()
16
    {
17
        $artifacts = [
18 3
            'js' => $this->map('js'),
19 3
            'php' => $this->map('php'),
20 3
            'styl' => $this->map('styl'),
21
        ];
22
23 3
        $artifacts['hash'] = md5(json_encode($artifacts));
24 3
        return $artifacts;
25
    }
26
27 3
    public function map($type)
28
    {
29 3
        $mapping = [];
30 3
        if (is_dir($type)) {
31 3
            exec('find '.$type.' -name "*.'.$type.'" -exec md5sum {} \; | sort', $contents);
32 3
            if ($contents !== null) {
33 3
                foreach ($contents as $i => $row) {
34 3
                    list($hash, $file) = explode("  ", $row);
35 3
                    $file = substr($file, strlen($type) + 1);
36 3
                    $mapping[$file] = $hash;
37
                }
38
            }
39
        }
40 3
        return $mapping;
41
    }
42
}
43