SymfonyUrlGenerator::getUrlPathFromConfig()   B
last analyzed

Complexity

Conditions 6
Paths 38

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 29
rs 8.439
cc 6
eloc 16
nc 38
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Visithor package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * Feel free to edit as you please, and have fun.
10
 *
11
 * @author Marc Morera <[email protected]>
12
 */
13
14
namespace Visithor\Bundle\Generator;
15
16
use Symfony\Component\Routing\Exception\ExceptionInterface;
17
use Symfony\Component\Routing\RouterInterface;
18
19
use Visithor\Factory\UrlChainFactory;
20
use Visithor\Factory\UrlFactory;
21
use Visithor\Generator\UrlGenerator;
22
23
/**
24
 * Class SymfonyUrlGenerator
25
 */
26
class SymfonyUrlGenerator extends UrlGenerator
27
{
28
    /**
29
     * @var RouterInterface
30
     *
31
     * Router
32
     */
33
    protected $router;
34
35
    /**
36
     * Construct
37
     *
38
     * @param UrlFactory      $urlFactory      Url factory
39
     * @param UrlChainFactory $urlChainFactory UrlChain factory
40
     * @param RouterInterface $router          Router
41
     */
42
    public function __construct(
43
        UrlFactory $urlFactory,
44
        UrlChainFactory $urlChainFactory,
45
        RouterInterface $router
46
    ) {
47
        parent::__construct(
48
            $urlFactory,
49
            $urlChainFactory
50
        );
51
52
        $this->router = $router;
53
    }
54
55
    /**
56
     * Build the url given the configuration data
57
     *
58
     * @param mixed $urlConfig Url configuration
59
     *
60
     * @return string Route path
61
     */
62
    protected function getUrlPathFromConfig($urlConfig)
63
    {
64
        $urlPath = parent::getUrlPathFromConfig($urlConfig);
65
66
        try {
67
            $path = is_array($urlPath)
68
                ? $urlPath[0]
69
                : $urlPath;
70
71
            $arguments = (
72
                is_array($urlPath) &&
73
                isset($urlPath[1]) &&
74
                is_array($urlPath[1])
75
            )
76
                ? $urlPath[1]
77
                : [];
78
79
            $urlPath = $this
80
                ->router
81
                ->generate($path, $arguments);
82
        } catch (ExceptionInterface $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
83
84
            /**
85
             * Silent pass
86
             */
87
        }
88
89
        return $urlPath;
0 ignored issues
show
Bug Compatibility introduced by
The expression return $urlPath; of type array|string is incompatible with the return type of the parent method Visithor\Generator\UrlGe...r::getUrlPathFromConfig of type string as it can also be of type array which is not included in this return type.
Loading history...
90
    }
91
}
92