Passed
Pull Request — master (#15)
by Enjoys
02:34
created

ManyFilesStrategy::getResult()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 48
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 6.027

Importance

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