Passed
Push — develop ( 772557...f81375 )
by Daniel
06:11
created

FileSystemLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getImaginePath() 0 11 4
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 1
    public function __construct(
18
        MimeTypeGuesserInterface $mimeGuesser,
19
        ExtensionGuesserInterface $extensionGuesser,
20
        LocatorInterface $locator,
21
        array $rootPaths = []
22
    )
23
    {
24 1
        parent::__construct($mimeGuesser, $extensionGuesser, $locator, $rootPaths);
25 1
        $this->rootPaths = $rootPaths;
26 1
    }
27
28
    /**
29
     * Strips root directory from the start of a file path
30
     * @param null|string $filePath
31
     * @return null|string
32
     */
33 2
    public function getImaginePath(?string $filePath = null): ?string
34
    {
35 2
        if (!$filePath) {
36
            return $filePath;
37
        }
38 2
        foreach ($this->rootPaths as $rootPath) {
39 2
            if (strpos($filePath, $rootPath) === 0) {
40 2
                return substr($filePath, \strlen($rootPath));
41
            }
42
        }
43 1
        return $filePath;
44
    }
45
}
46