Passed
Push — master ( bd3c1c...f4ac9e )
by Enjoys
02:18
created

ManyFilesStrategy::getResult()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 39
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6.2488

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 6
eloc 21
c 3
b 1
f 0
nc 9
nop 0
dl 0
loc 39
ccs 17
cts 21
cp 0.8095
crap 6.2488
rs 8.9617
1
<?php
2
3
namespace Enjoys\AssetsCollector\CollectStrategy\Strategy;
4
5
use Enjoys\AssetsCollector\Asset;
6
use Enjoys\AssetsCollector\CollectStrategy\StrategyAbstract;
7
use Enjoys\AssetsCollector\Helpers;
8
9
class ManyFilesStrategy extends StrategyAbstract
10
{
11
    /**
12
     * @return array<string>
13
     */
14 5
    public function getResult(): array
15
    {
16 5
        $result = [];
17
18 5
        foreach ($this->assetsCollection as $asset) {
19 5
            if ($asset->getPath() === false) {
20
                continue;
21
            }
22
23 5
            if ($asset->isUrl()) {
24 5
                $result[] = $asset->getPath();
25 5
                continue;
26
            }
27
28 2
            $link = str_replace(
29
                [
30 2
                    $this->environment->getCompileDir(),
31 2
                    $this->environment->getProjectDir()
32
                ]
33
                ,
34 2
                '',
35 2
                $asset->getPath()
36
            );
37
38
            try {
39 2
                Helpers::createSymlink($this->environment->getCompileDir() . $link, $asset->getPath(), $this->logger);
40
41 2
                $optSymlinks = (array)$asset->getOption(Asset::CREATE_SYMLINK, []);
42 2
                foreach ($optSymlinks as $optLink => $optTarget) {
43
                    Helpers::createSymlink($optLink, $optTarget, $this->logger);
44
                }
45
            } catch (\Exception  $e) {
46
                $this->logger->error($e->getMessage());
47
            }
48
49
50 2
            $result[] = $this->environment->getBaseUrl() . str_replace(DIRECTORY_SEPARATOR, '/', $link);
51
        }
52 5
        return $result;
53
    }
54
}
55