EnvironmentDetection::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 15
ccs 0
cts 12
cp 0
crap 12
rs 9.4285
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Framework\Kernel\Bootstrap;
4
5
use Dotenv\Loader;
6
use Symfony\Component\Console\Input\ArgvInput;
7
use Venta\Framework\Kernel\AbstractKernelBootstrap;
8
9
/**
10
 * Class EnvironmentDetection
11
 *
12
 * @package Venta\Framework\Kernel\Bootstrap
13
 */
14
final class EnvironmentDetection extends AbstractKernelBootstrap
15
{
16
    /**
17
     * @inheritDoc
18
     */
19
    public function __invoke()
20
    {
21
        $filePath = rtrim($this->kernel()->rootPath(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.env';
22
23
        $envLoader = new Loader($filePath);
24
        $envLoader->load();
25
26
        if ($this->kernel()->isCli()) {
27
            // todo: Load different env fire for each environment.
28
            $env = (new ArgvInput)->getParameterOption(['--env', '-e']);
29
            if ($env) {
30
                $envLoader->setEnvironmentVariable('APP_ENV', $env);
31
            }
32
        }
33
    }
34
35
}