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

Generator/UrlGenerator.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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