EnvironmentDetection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
ccs 0
cts 12
cp 0
rs 10
wmc 3
lcom 0
cbo 4

1 Method

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