Passed
Push — master ( 054509...a8959a )
by Enjoys
01:55
created

ManyFilesStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
eloc 22
c 4
b 2
f 0
dl 0
loc 47
ccs 16
cts 20
cp 0.8
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B getResult() 0 42 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 5
                '',
35
                $path
36
            );
37
38
            try {
39 5
                Helpers::createSymlink($this->environment->getCompileDir() . $link, $path, $this->logger);
40
41 5
                $optSymlinks = (array)$asset->getOption(Asset::CREATE_SYMLINK, []);
42
43
                /** @var array<string, string> $optSymlinks */
44 5
                foreach ($optSymlinks as $optLink => $optTarget) {
45
                    Helpers::createSymlink($optLink, $optTarget, $this->logger);
46
                }
47
            } catch (\Exception  $e) {
48
                $this->logger->error($e->getMessage());
49
            }
50
51
52 5
            $result[] = $this->environment->getBaseUrl() . str_replace(DIRECTORY_SEPARATOR, '/', $link);
53
        }
54
55 8
        return $result;
56
    }
57
}
58