Passed
Push — dev ( c1a5f7...902aab )
by Enjoys
07:50
created

ManyFilesStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 78.95%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
eloc 22
dl 0
loc 46
ccs 15
cts 19
cp 0.7895
rs 10
c 4
b 2
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B getResult() 0 41 6
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