Completed
Branch master (c0d8ef)
by Yaroslav
06:36
created

TestBagResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 26
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolve() 0 8 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\TestBagResolver;
12
13
use Yarhon\RouteGuardBundle\Security\Test\AbstractTestBagInterface;
14
use Yarhon\RouteGuardBundle\Security\Test\TestBagInterface;
15
use Yarhon\RouteGuardBundle\Routing\RouteContextInterface;
16
use Yarhon\RouteGuardBundle\Security\Http\RequestContextFactory;
17
use Yarhon\RouteGuardBundle\Security\Http\RequestDependentTestBagInterface;
18
19
/**
20
 * @author Yaroslav Honcharuk <[email protected]>
21
 */
22
class TestBagResolver implements TestBagResolverInterface
23
{
24
    /**
25
     * @var RequestContextFactory
26
     */
27
    private $requestContextFactory;
28
29
    /**
30
     * @param RequestContextFactory $requestContextFactory
31
     */
32 8
    public function __construct(RequestContextFactory $requestContextFactory)
33
    {
34 8
        $this->requestContextFactory = $requestContextFactory;
35 8
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 6
    public function resolve(AbstractTestBagInterface $testBag, RouteContextInterface $routeContext)
41
    {
42 6
        if ($testBag instanceof TestBagInterface) {
43 5
            return $testBag->getTests();
44 1
        } elseif ($testBag instanceof RequestDependentTestBagInterface) {
45 1
            $requestContext = $this->requestContextFactory->createContext($routeContext);
46
47 1
            return $testBag->getTests($requestContext);
48
        }
49
50
        // TODO: throw exception if not supported $testBag passed
51
    }
52
}
53