Test Setup Failed
Push — master ( 1a9491...b3bb4f )
by Pascal
09:30
created

ChainUrlGenerator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setContext() 0 7 2
A getContext() 0 4 1
A generate() 0 14 3
1
<?php
2
3
namespace Skalpa\Silex\Symfony\Routing;
4
5
use Symfony\Component\Routing\Exception\RouteNotFoundException;
6
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
7
use Symfony\Component\Routing\RequestContext;
8
9
10
/**
11
 * Generates URLs using other generators.
12
 */
13
class ChainUrlGenerator implements UrlGeneratorInterface
14
{
15
    private $context;
16
    private $generators;
17
18
    /**
19
     * @param UrlGeneratorInterface[] ...$generators
20
     */
21
    public function __construct(UrlGeneratorInterface ...$generators)
22
    {
23
        $this->generators = $generators;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function setContext(RequestContext $context)
30
    {
31
        foreach ($this->generators as $generator) {
32
            $generator->setContext($context);
0 ignored issues
show
Bug introduced by
The method setContext cannot be called on $generator (of type array<integer,object<Sym...UrlGeneratorInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
33
        }
34
        $this->context = $context;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getContext()
41
    {
42
        return $this->context;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
49
    {
50
        /** @var RouteNotFoundException $notFound */
51
        $notFound = null;
52
53
        foreach ($this->generators as $generator) {
54
            try {
55
                return $generator->generate($name, $parameters, $referenceType);
0 ignored issues
show
Bug introduced by
The method generate cannot be called on $generator (of type array<integer,object<Sym...UrlGeneratorInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
56
            } catch (RouteNotFoundException $e) {
57
                $notFound = $e;
58
            }
59
        }
60
        throw $notFound;
61
    }
62
}
63