Passed
Push — master ( b9addd...bd3c1c )
by Enjoys
01:53
created

ManyFilesStrategy::getResult()   B

Complexity

Conditions 6
Paths 11

Size

Total Lines 42
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 6.0702

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 6
eloc 24
c 3
b 1
f 0
nc 11
nop 0
dl 0
loc 42
ccs 21
cts 24
cp 0.875
crap 6.0702
rs 8.9137
1
<?php
2
3
namespace Enjoys\AssetsCollector\CollectStrategy\Strategy;
4
5
use Enjoys\AssetsCollector\CollectStrategy\StrategyAbstract;
6
use Enjoys\AssetsCollector\Helpers;
7
8
class ManyFilesStrategy extends StrategyAbstract
9
{
10
    /**
11
     * @return array<string>
12
     */
13 5
    public function getResult(): array
14
    {
15 5
        $result = [];
16
17 5
        foreach ($this->assetsCollection as $asset) {
18 5
            if ($asset->getPath() === false) {
19
                continue;
20
            }
21
22 5
            if ($asset->isUrl()) {
23 5
                $result[] = $asset->getPath();
24 5
                continue;
25
            }
26
27 2
            $link = str_replace(
28
                [
29 2
                    $this->environment->getCompileDir(),
30 2
                    $this->environment->getProjectDir()
31
                ]
32
                ,
33 2
                '',
34 2
                $asset->getPath()
35
            );
36
37 2
            $symlink = $this->environment->getCompileDir() . $link;
38
39
            try {
40 2
                if (!file_exists($symlink)) {
41 2
                    $path = pathinfo($symlink, PATHINFO_DIRNAME);
42 2
                    Helpers::createDirectory($path);
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type array; however, parameter $path of Enjoys\AssetsCollector\Helpers::createDirectory() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
                    Helpers::createDirectory(/** @scrutinizer ignore-type */ $path);
Loading history...
43 2
                    $this->logger->info(sprintf('Create directory %s', $path));
44
45 2
                    symlink($asset->getPath(), $symlink);
46 2
                    $this->logger->info(sprintf('Create symlink: %s', $symlink));
47
                }
48
            } catch (\Exception  $e) {
49
                $this->logger->error($e->getMessage());
50
            }
51
52 2
            $result[] = $this->environment->getBaseUrl() . str_replace(DIRECTORY_SEPARATOR, '/', $link);
53
        }
54 5
        return $result;
55
    }
56
}
57