Completed
Pull Request — 2.0 (#1059)
by Nick
02:24
created

PathResolver::getFileUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Liip\ImagineBundle\Utility\Path;
4
5
class PathResolver implements PathResolverInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $webRoot;
11
    
12
    /**
13
     * @var string
14
     */
15
    protected $cachePrefix;
16
    
17
    /**
18
     * @var string
19
     */
20
    protected $cacheRoot;
21
    
22
    public function __construct(
23
        $webRootDir,
24
        $cachePrefix = 'media/cache'
25
    ) {
26
        $this->webRoot = rtrim(str_replace('//', '/', $webRootDir), '/');
27
        $this->cachePrefix = ltrim(str_replace('//', '/', $cachePrefix), '/');
28
        $this->cacheRoot = $this->webRoot.'/'.$this->cachePrefix;
29
    }
30
    
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getFilePath($path, $filter)
35
    {
36
        return $this->webRoot.'/'.$this->getFileUrl($path, $filter);
37
    }
38
    
39
    /**
40
     * {@inheritdoc}
41
     */
42 View Code Duplication
    public function getFileUrl($path, $filter)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        // crude way of sanitizing URL scheme ("protocol") part
45
        $path = str_replace('://', '---', $path);
46
    
47
        return $this->cachePrefix.'/'.$filter.'/'.ltrim($path, '/');
48
    }
49
    
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getCacheRoot()
54
    {
55
        return $this->cacheRoot;
56
    }
57
}
58