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

TestBagResolver::resolve()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
cc 3
nc 3
nop 2
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\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