Passed
Push — master ( 8a12fc...8bc538 )
by Vsevolods
10:30
created

EnvironmentDetection::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 0
crap 12
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
class EnvironmentDetection extends AbstractKernelBootstrap
15
{
16
    /**
17
     * @inheritDoc
18
     */
19
    public function __invoke()
20
    {
21
        $filePath = rtrim($this->kernel->getRootPath(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.env';
22
23
        $envLoader = new Loader($filePath);
24
        if ($this->kernel->isCli()) {
25
            // todo: Load different env fire for each environment.
26
            $env = (new ArgvInput)->getParameterOption(['--env', '-e']);
27
            if ($env) {
28
                $envLoader->setEnvironmentVariable('APP_ENV', $env);
29
            }
30
        }
31
    }
32
33
}