Completed
Push — master ( 586166...fecb59 )
by Paweł
47:58
created

MetaRouter::generate()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 10
cts 10
cp 1
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 11
nc 4
nop 3
crap 7
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Core Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\CoreBundle\Routing;
16
17
use SWP\Bundle\ContentBundle\Model\ArticleInterface;
18
use SWP\Bundle\ContentBundle\Model\RouteInterface;
19
use Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter;
20
use SWP\Component\TemplatesSystem\Gimme\Meta\Meta;
21
22
class MetaRouter extends DynamicRouter
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 66
    public function generate($name, $parameters = [], $referenceType = false)
28
    {
29 66
        $route = $name;
30 66
        if (is_object($name) && $name->getValues() instanceof ArticleInterface) {
31 4
            $parameters['slug'] = $name->getValues()->getSlug();
32 4
            $route = $name->getValues()->getRoute();
33
34 4
            if (null === $route && $name->getContext()->getCurrentPage()) {
35 1
                $parameters['slug'] = null;
36 4
                $route = $name->getContext()->getCurrentPage()->getValues();
37
            }
38 62
        } elseif (is_object($name) && $name->getValues() instanceof RouteInterface) {
39
            $route = $name->getValues();
40
        }
41
42 66
        return parent::generate($route, $parameters, $referenceType);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 66
    public function supports($name)
49
    {
50 66
        return $name instanceof Meta && (
51 3
            $name->getValues() instanceof ArticleInterface ||
52 3
            $name->getValues() instanceof RouteInterface
53 66
        ) || is_string($name);
54
    }
55
}
56