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

EnvironmentDetection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 20
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 3
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
}