Passed
Push — master ( 6ed31c...3efa89 )
by Enjoys
08:45
created

ManyFilesStrategy::getResult()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 41
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 6.3357

Importance

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