Completed
Push — master ( 003c1a...870291 )
by Tomáš
06:24
created

ControllerRoutingTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 30
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setRouter() 0 4 1
A generateUrl() 0 7 1
A redirect() 0 4 1
A redirectToRoute() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\ControllerAutowire\Controller\Routing;
11
12
use Symfony\Component\HttpFoundation\RedirectResponse;
13
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
14
use Symfony\Component\Routing\RouterInterface;
15
16
trait ControllerRoutingTrait
17
{
18
    /**
19
     * @var RouterInterface
20
     */
21
    private $router;
22
23
    public function setRouter(RouterInterface $router)
24
    {
25
        $this->router = $router;
26
    }
27
28
    protected function generateUrl(
29
        string $route,
30
        array $parameters = [],
31
        int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH
32
    ) : string {
33
        return $this->router->generate($route, $parameters, $referenceType);
34
    }
35
36
    protected function redirect(string $url, int $status = 302) : RedirectResponse
37
    {
38
        return new RedirectResponse($url, $status);
39
    }
40
41
    protected function redirectToRoute(string $route, array $parameters = [], int $status = 302) : RedirectResponse
42
    {
43
        return $this->redirect($this->generateUrl($route, $parameters), $status);
44
    }
45
}
46