Completed
Push — master ( 000445...c8f0e6 )
by
unknown
04:21
created

UrlGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 30.19 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 16
loc 53
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A generate() 16 16 2

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
namespace MediaMonks\SonataMediaBundle\Generator;
4
5
use MediaMonks\SonataMediaBundle\Model\MediaInterface;
6
use MediaMonks\SonataMediaBundle\Handler\ParameterHandlerInterface;
7
use Symfony\Bundle\FrameworkBundle\Routing\Router;
8
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
9
10
class UrlGenerator
11
{
12
    /**
13
     * @var Router
14
     */
15
    private $router;
16
17
    /**
18
     * @var ParameterHandlerInterface
19
     */
20
    private $parameterHandler;
21
22
    /**
23
     * @var string
24
     */
25
    private $defaultRouteName;
26
27
    /**
28
     * @param Router $router
29
     * @param ParameterHandlerInterface $parameterHandler
30
     * @param $defaultRouteName
31
     */
32
    public function __construct(Router $router, ParameterHandlerInterface $parameterHandler, $defaultRouteName)
33
    {
34
        $this->router = $router;
35
        $this->parameterHandler = $parameterHandler;
36
        $this->defaultRouteName = $defaultRouteName;
37
    }
38
39
    /**
40
     * @param MediaInterface $media
41
     * @param array $parameters
42
     * @param null $routeName
43
     * @param int $referenceType
44
     * @return string
45
     */
46 View Code Duplication
    public function generate(
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...
47
        MediaInterface $media,
48
        array $parameters,
49
        $routeName = null,
50
        $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH
51
    ) {
52
        if (empty($routeName)) {
53
            $routeName = $this->defaultRouteName;
54
        }
55
56
        return $this->router->generate(
57
            $routeName,
58
            $this->parameterHandler->getQueryString($media, $parameters),
59
            $referenceType
60
        );
61
    }
62
}
63