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::generate()   D
last analyzed

Complexity

Conditions 9
Paths 6

Size

Total Lines 35
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 9

Importance

Changes 5
Bugs 1 Features 2
Metric Value
c 5
b 1
f 2
dl 0
loc 35
ccs 22
cts 22
cp 1
rs 4.9091
cc 9
eloc 20
nc 6
nop 0
crap 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