AliceContextInitializer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B initializeContext() 0 27 6
1
<?php
2
3
/*
4
 * This file is part of the Fidry\AliceBundleExtension package.
5
 *
6
 * (c) Théo FIDRY <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Fidry\AliceBundleExtension\Context\Initializer;
13
14
use Behat\Behat\Context\Context;
15
use Behat\Behat\Context\Initializer\ContextInitializer;
16
use Fidry\AliceBundleExtension\Context\AliceContextInterface;
17
use Fidry\AliceBundleExtension\Context\Doctrine\AliceODMContext;
18
use Fidry\AliceBundleExtension\Context\Doctrine\AliceORMContext;
19
use Fidry\AliceBundleExtension\Context\Doctrine\AlicePHPCRContext;
20
21
/**
22
 * @author Théo FIDRY <[email protected]>
23
 */
24
class AliceContextInitializer implements ContextInitializer
25
{
26
    /**
27
     * @var string
28
     */
29
    private $fixturesBasePath;
30
31
    /**
32
     * @param string $fixturesBasePath
33
     */
34
    public function __construct($fixturesBasePath)
35
    {
36
        $this->fixturesBasePath = $fixturesBasePath;
37
    }
38
39
    /**
40
     * Initializes provided context.
41
     *
42
     * @param Context $context
43
     */
44
    public function initializeContext(Context $context)
45
    {
46
        if (false === $context instanceof AliceContextInterface) {
47
            return;
48
        }
49
50
        /* @var AliceContextInterface $context */
51
        $fixturesBasePath = $this->fixturesBasePath;
52
        switch (true) {
53
54
            case $context instanceof AliceODMContext:
55
                $fixturesBasePath .= '/ODM';
56
                break;
57
58
            case $context instanceof AliceORMContext:
59
                $fixturesBasePath .= '/ORM';
60
                break;
61
62
            case $context instanceof AlicePHPCRContext:
63
                $fixturesBasePath .= '/PHPCR';
64
                break;
65
        }
66
67
        if (null === $context->getBasePath()) {
68
            $context->setBasePath($fixturesBasePath);
69
        }
70
    }
71
}
72