Completed
Pull Request — 2.x (#1376)
by
unknown
01:41
created

FilterRuntime   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 27
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A filter() 4 4 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\Templating;
13
14
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
15
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
16
use Twig\Extension\RuntimeExtensionInterface;
17
18 View Code Duplication
class FilterRuntime implements RuntimeExtensionInterface
0 ignored issues
show
Duplication introduced by
This class 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...
19
{
20
    /**
21
     * @var CacheManager
22
     */
23
    private $cache;
24
25
    public function __construct(CacheManager $cache)
26
    {
27
        $this->cache = $cache;
28
    }
29
30
    /**
31
     * Gets the browser path for the image and filter to apply.
32
     *
33
     * @param string      $path
34
     * @param string      $filter
35
     * @param string|null $resolver
36
     * @param int         $referenceType
37
     *
38
     * @return string
39
     */
40
    public function filter($path, $filter, array $config = [], $resolver = null, $referenceType = UrlGeneratorInterface::ABSOLUTE_URL)
41
    {
42
        return $this->cache->getBrowserPath(parse_url($path, PHP_URL_PATH), $filter, $config, $resolver, $referenceType);
0 ignored issues
show
Security Bug introduced by
It seems like parse_url($path, PHP_URL_PATH) targeting parse_url() can also be of type false; however, Liip\ImagineBundle\Imagi...nager::getBrowserPath() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
43
    }
44
}
45