Passed
Push — master ( 410e72...965759 )
by Kirill
04:34 queued 10s
created

DotenvBootloader::boot()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 13
rs 10
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
declare(strict_types=1);
9
10
namespace Spiral\DotEnv\Bootloader;
11
12
use Dotenv\Dotenv;
13
use Spiral\Boot\Bootloader\Bootloader;
14
use Spiral\Boot\DirectoriesInterface;
15
use Spiral\Boot\EnvironmentInterface;
16
17
final class DotenvBootloader extends Bootloader
18
{
19
    /**
20
     * @param DirectoriesInterface $dirs
21
     * @param EnvironmentInterface $env
22
     */
23
    public function boot(DirectoriesInterface $dirs, EnvironmentInterface $env)
24
    {
25
        $dotenvPath = $env->get('DOTENV_PATH', $dirs->get('root') . '.env');
26
27
        if (!file_exists($dotenvPath)) {
28
            return;
29
        }
30
31
        $path = dirname($dotenvPath);
32
        $file = basename($dotenvPath);
33
34
        foreach (Dotenv::create($path, $file)->load() as $key => $value) {
0 ignored issues
show
Bug introduced by
$path of type string is incompatible with the type Dotenv\Repository\RepositoryInterface expected by parameter $repository of Dotenv\Dotenv::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        foreach (Dotenv::create(/** @scrutinizer ignore-type */ $path, $file)->load() as $key => $value) {
Loading history...
35
            $env->set($key, $value);
36
        }
37
    }
38
}