TestBagResolver::resolve()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
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
use Yarhon\RouteGuardBundle\Exception\RuntimeException;
19
20
/**
21
 * @author Yaroslav Honcharuk <[email protected]>
22
 */
23
class TestBagResolver implements TestBagResolverInterface
24
{
25
    /**
26
     * @var RequestContextFactory
27
     */
28
    private $requestContextFactory;
29
30
    /**
31
     * @param RequestContextFactory $requestContextFactory
32
     */
33 21
    public function __construct(RequestContextFactory $requestContextFactory)
34
    {
35 21
        $this->requestContextFactory = $requestContextFactory;
36 21
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 17
    public function resolve(AbstractTestBagInterface $testBag, RouteContextInterface $routeContext)
42
    {
43 17
        if ($testBag instanceof TestBagInterface) {
44 11
            return $testBag->getTests();
45 6
        } elseif ($testBag instanceof RequestDependentTestBagInterface) {
46 5
            $requestContext = $this->requestContextFactory->createContext($routeContext);
47
48 5
            return $testBag->getTests($requestContext);
49
        }
50
51 1
        throw new RuntimeException(sprintf('No resolver exists for test bag instance of "%s".', get_class($testBag)));
52
    }
53
}
54