GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RouteOptionGenerator   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 2 Features 2
Metric Value
wmc 10
c 6
b 2
f 2
lcom 1
cbo 4
dl 0
loc 56
ccs 25
cts 25
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
D generate() 0 35 9
1
<?php
2
3
/**
4
 * This file is part of the DpnXmlSitemapBundle package.
5
 *
6
 * (c) Björn Fromme <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the Resources/meta/LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Dpn\XmlSitemapBundle\Sitemap;
13
14
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
15
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
16
use Symfony\Component\Routing\RouterInterface;
17
18
/**
19
 * @author Kevin Bond <[email protected]>
20
 */
21
class RouteOptionGenerator implements GeneratorInterface
22
{
23
    /**
24
     * @var \Symfony\Component\Routing\RouterInterface
25
     */
26
    protected $router;
27
28
    /**
29
     * @param \Symfony\Component\Routing\RouterInterface $router
30
     */
31 9
    public function __construct(RouterInterface $router)
32
    {
33 9
        $this->router = $router;
34 9
    }
35
36
    /**
37
     * @return Entry[]
38
     *
39
     * @throws \InvalidArgumentException
40
     */
41 9
    public function generate()
42
    {
43 9
        $entries = array();
44 9
        $collection = $this->router->getRouteCollection();
45
46 9
        foreach ($collection->all() as $name => $route) {
47
            /** @var \Symfony\Component\Routing\Route $route */
48 9
            $option = $route->getOption('sitemap');
49
50 9
            if (true !== $option && true !== is_array($option)) {
51 8
                continue;
52
            }
53
54 9
            $options = array();
55
56 9
            if (true === is_array($option)) {
57 1
                $options = $option;
58 1
            }
59
60
            try {
61 9
                $url = $this->router->generate($name, array(), UrlGeneratorInterface::ABSOLUTE_URL);
62 9
            } catch (MissingMandatoryParametersException $e) {
63 1
                throw new \InvalidArgumentException(sprintf('The route "%s" cannot have the sitemap option because it requires parameters', $name));
64
            }
65
66 8
            $entries[] = new Entry(
67 8
                $url,
68 8
                true === isset($options['lastmod']) ? $options['lastmod'] : null,
69 8
                true === isset($options['changefreq']) ? $options['changefreq'] : null,
70 8
                true === isset($options['priority']) ? $options['priority'] : null
71 8
            );
72 8
        }
73
74 8
        return $entries;
75
    }
76
}
77