Assets::map()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.7666
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 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