ProviderAggregate::setLogger()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Security\TestProvider;
12
13
use Psr\Log\LoggerInterface;
14
use Psr\Log\LoggerAwareInterface;
15
use Symfony\Component\Routing\Route;
16
use Yarhon\RouteGuardBundle\Controller\ControllerMetadata;
17
use Yarhon\RouteGuardBundle\Security\Test\AbstractTestBagInterface;
18
use Yarhon\RouteGuardBundle\Security\Test\ProviderAwareInterface;
19
use Yarhon\RouteGuardBundle\Exception\ExceptionInterface;
20
21
/**
22
 * @author Yaroslav Honcharuk <[email protected]>
23
 */
24
class ProviderAggregate implements LoggerAwareInterface
25
{
26
    /**
27
     * @var ProviderInterface[]
28
     */
29
    private $testProviders;
30
31
    /**
32
     * @var LoggerInterface;
33
     */
34
    private $logger;
35
36
    /**
37
     * @param \Traversable|ProviderInterface[] $testProviders
38
     */
39 21
    public function __construct($testProviders = [])
40
    {
41 21
        $this->testProviders = $testProviders;
42 21
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 19
    public function setLogger(LoggerInterface $logger)
48
    {
49 19
        $this->logger = $logger;
50
51 19
        foreach ($this->testProviders as $provider) {
52 19
            if ($provider instanceof LoggerAwareInterface) {
53 19
                $provider->setLogger($this->logger);
54
            }
55
        }
56 19
    }
57
58
    /**
59
     * @param string                  $routeName
60
     * @param Route                   $route
61
     * @param ControllerMetadata|null $controllerMetadata
62
     *
63
     * @return AbstractTestBagInterface[]
64
     *
65
     * @throws ExceptionInterface
66
     */
67 20
    public function getTests($routeName, Route $route, ControllerMetadata $controllerMetadata = null)
68
    {
69 20
        $testBags = [];
70
71 20
        foreach ($this->testProviders as $provider) {
72 20
            $testBag = $provider->getTests($routeName, $route, $controllerMetadata);
73
74 20
            if (null !== $testBag) {
75 20
                if ($testBag instanceof ProviderAwareInterface) {
76 19
                    $testBag->setProviderClass(get_class($provider));
77
                }
78 20
                $testBags[] = $testBag;
79
            }
80
        }
81
82 20
        return $testBags;
83
    }
84
}
85