Passed
Push — develop ( 28c299...928e2a )
by Mathias
12:40
created

InstallContext   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 82
Duplicated Lines 24.39 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 1
dl 20
loc 82
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * YAWIK
5
 *
6
 * @filesource
7
 * @license MIT
8
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
9
 */
10
11
namespace Yawik\Behat;
12
13
use Behat\Behat\Context\Context;
14
use Behat\Behat\Hook\Scope\AfterScenarioScope;
15
16
/**
17
 * Class InstallContext
18
 *
19
 * @package Yawik\Behat
20
 * @author Anthonius Munthi <[email protected]>
21
 */
22
class InstallContext implements Context
23
{
24
    use CommonContextTrait;
25
26
    private static $yawikGlobalConfig;
27
28
    private static $yawikBackupConfig;
29
30
    public function __construct()
31
    {
32
        static::$yawikGlobalConfig = getcwd() . '/config/autoload/yawik.config.global.php';
33
        static::$yawikBackupConfig = str_replace('yawik.config.global.php', 'yawik.backup', static::$yawikGlobalConfig);
34
    }
35
36
    /**
37
     * @Given I have install module activated
38
     */
39
    public function iHaveInstallModuleActivated()
40
    {
41
        // backup existing file
42
        $yawikBackupConfig = static::$yawikBackupConfig;
43
        $yawikGlobalConfig = static::$yawikGlobalConfig;
44
45
        if (is_file($yawikGlobalConfig)) {
46
            rename($yawikGlobalConfig, $yawikBackupConfig);
47
        }
48
    }
49
50
    /**
51
     * @Given I go to the install page
52
     */
53
    public function iGoToInstallPage()
54
    {
55
        $url = $this->minkContext->locatePath('/');
56
        $this->visit($url);
57
    }
58
59
    /**
60
     * @AfterSuite
61
     */
62
    public static function tearDown()
63
    {
64
        static::restoreConfig();
65
    }
66
67
    /**
68
     * @AfterScenario
69
     */
70
    public function afterScenario()
71
    {
72
        static::restoreConfig();
73
    }
74
75
    /**
76
     * @BeforeSuite
77
     */
78
    public static function setUp()
79
    {
80
        static::restoreConfig();
81
    }
82
83
    public static function restoreConfig()
84
    {
85
        // restore backup
86
        $yawikBackupConfig = static::$yawikBackupConfig;
87
        $yawikGlobalConfig = static::$yawikGlobalConfig;
88
89
        if (is_file($yawikBackupConfig)) {
90
            rename($yawikBackupConfig, $yawikGlobalConfig);
91
        }
92
    }
93
94
    /**
95
     * @Given I fill database connection with an active connection
96
     */
97
    public function iFillActiveConnectionString()
98
    {
99
        $config = $this->getService('config');
100
        $connection = $config['doctrine']['connection']['odm_default']['connectionString'];
101
        $this->minkContext->fillField('db_conn', $connection);
102
    }
103
}
104