Environment::_initialize()   B
last analyzed

Complexity

Conditions 10
Paths 128

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 18
rs 7.4333
c 0
b 0
f 0
cc 10
nc 128
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace PyzTest\Shared\Testify\Helper;
11
12
use Codeception\Module;
13
use Spryker\Shared\Kernel\CodeBucket\Config\CodeBucketConfig;
14
use Spryker\Shared\Kernel\CodeBucket\Config\CodeBucketConfigInterface;
15
16
class Environment extends Module
17
{
18
    /**
19
     * @var string
20
     */
21
    protected const TESTING_APPLICATION_ENV_NAME = 'devtest';
22
23
    /**
24
     * @return void
25
     */
26
    public function _initialize(): void
27
    {
28
        $rootDir = realpath(__DIR__ . '/../../../../../../');
29
        $applicationEnv = $this->getApplicationEnv();
30
31
        defined('APPLICATION_ENV') || define('APPLICATION_ENV', $applicationEnv);
32
33
        defined('APPLICATION_STORE') || define('APPLICATION_STORE', (isset($_SERVER['APPLICATION_STORE']) && $_SERVER['APPLICATION_STORE'] !== '') ? $_SERVER['APPLICATION_STORE'] : 'DE'); // phpcs:ignore SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable
34
        putenv('APPLICATION_STORE=' . APPLICATION_STORE);
35
36
        defined('APPLICATION') || define('APPLICATION', '');
37
38
        defined('APPLICATION_ROOT_DIR') || define('APPLICATION_ROOT_DIR', $rootDir);
39
        defined('APPLICATION_SOURCE_DIR') || define('APPLICATION_SOURCE_DIR', APPLICATION_ROOT_DIR . '/src');
40
        defined('APPLICATION_VENDOR_DIR') || define('APPLICATION_VENDOR_DIR', APPLICATION_ROOT_DIR . '/vendor');
41
42
        defined('APPLICATION_CODE_BUCKET') || define('APPLICATION_CODE_BUCKET', $this->createCodeBucketConfig()->getCurrentCodeBucket());
43
        putenv('APPLICATION_CODE_BUCKET=' . APPLICATION_CODE_BUCKET);
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    protected function getApplicationEnv(): string
50
    {
51
        if (getenv('SPRYKER_TESTING_ENABLED')) {
52
            return getenv('APPLICATION_ENV');
53
        }
54
55
        return static::TESTING_APPLICATION_ENV_NAME;
56
    }
57
58
    /**
59
     * @return \Spryker\Shared\Kernel\CodeBucket\Config\CodeBucketConfigInterface
60
     */
61
    protected function createCodeBucketConfig(): CodeBucketConfigInterface
62
    {
63
        return new CodeBucketConfig();
64
    }
65
}
66