Completed
Pull Request — master (#1233)
by
unknown
01:32
created

PathResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 12.07 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 7
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getFilePath() 0 4 1
A getFileUrl() 0 4 1
A getCacheRoot() 0 4 1
A getFullPath() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Utility\Path;
13
14
use Liip\ImagineBundle\Imagine\Cache\Helper\PathHelper;
15
16
class PathResolver implements PathResolverInterface
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $webRoot;
22
23
    /**
24
     * @var string
25
     */
26
    protected $cachePrefix;
27
28
    /**
29
     * @var string
30
     */
31
    protected $cacheRoot;
32
33
    public function __construct(
34
        $webRootDir,
35
        $cachePrefix = 'media/cache'
36
    ) {
37
        $this->webRoot = rtrim(str_replace('//', '/', $webRootDir), '/');
38
        $this->cachePrefix = ltrim(str_replace('//', '/', $cachePrefix), '/');
39
        $this->cacheRoot = $this->webRoot.'/'.$this->cachePrefix;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getFilePath($path, $filter): string
46
    {
47
        return $this->webRoot.'/'.$this->getFullPath($path, $filter);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getFileUrl($path, $filter): string
54
    {
55
        return PathHelper::filePathToUrlPath($this->getFullPath($path, $filter));
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getCacheRoot(): string
62
    {
63
        return $this->cacheRoot;
64
    }
65
66 View Code Duplication
    private function getFullPath($path, $filter): string
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...
67
    {
68
        // crude way of sanitizing URL scheme ("protocol") part
69
        $path = str_replace('://', '---', $path);
70
71
        return $this->cachePrefix.'/'.$filter.'/'.ltrim($path, '/');
72
    }
73
}
74