Passed
Push — develop ( 683c8d...07cc15 )
by Daniel
05:33
created

FileSystemLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 9
ccs 0
cts 3
cp 0
crap 2
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Imagine;
4
5
use Liip\ImagineBundle\Binary\Loader\FileSystemLoader as BaseFileSystemLoader;
6
use Liip\ImagineBundle\Binary\Locator\LocatorInterface;
7
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface;
8
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
9
10
class FileSystemLoader extends BaseFileSystemLoader
11
{
12
    /**
13
     * @var string[]
14
     */
15
    private $rootPaths;
16
17
    public function __construct(
18
        MimeTypeGuesserInterface $mimeGuesser,
19
        ExtensionGuesserInterface $extensionGuesser,
20
        LocatorInterface $locator,
21
        array $rootPaths = []
22
    )
23
    {
24
        parent::__construct($mimeGuesser, $extensionGuesser, $locator, $rootPaths);
25
        $this->rootPaths = $rootPaths;
26
    }
27
28
    /**
29
     * Strips root directory from the start of a file path
30
     * @param null|string $filePath
31
     * @return null|string
32
     */
33 1
    public function getImaginePath(?string $filePath = null): ?string
34
    {
35 1
        if (!$filePath) {
36
            return $filePath;
37
        }
38 1
        foreach ($this->rootPaths as $rootPath) {
39 1
            if (strpos($filePath, $rootPath) === 0) {
40 1
                return substr($filePath, \strlen($rootPath));
41
            }
42
        }
43
        return $filePath;
44
    }
45
}
46