Passed
Pull Request — master (#24)
by Dmitriy
37:45 queued 22:43
created

EnvReader::readRaw()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Yiisoft\Composer\Config\Reader;
4
5
use Dotenv\Dotenv;
0 ignored issues
show
Bug introduced by
The type Dotenv\Dotenv was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Yiisoft\Composer\Config\Exception\UnsupportedFileTypeException;
7
8
/**
9
 * EnvReader - reads `.env` files.
10
 */
11
class EnvReader extends AbstractReader
12
{
13
    protected function readRaw($path)
14
    {
15
        if (!class_exists(Dotenv::class)) {
16
            throw new UnsupportedFileTypeException('for .env support require `vlucas/phpdotenv` in your composer.json');
17
        }
18
        $info = pathinfo($path);
19
        $this->loadDotenv($info['dirname'], $info['basename']);
20
21
        return $_ENV;
22
    }
23
24
    /**
25
     * Creates and loads Dotenv object.
26
     * Supports all 2, 3 and 4 version of `phpdotenv`
27
     * @param mixed $dir
28
     * @param mixed $file
29
     */
30
    private function loadDotenv($dir, $file)
31
    {
32
        if (method_exists(Dotenv::class, 'createMutable')) {
33
            Dotenv::createMutable($dir, $file)->load();
34
        } elseif (method_exists(Dotenv::class, 'create')) {
35
            Dotenv::create($dir, $file)->overload();
36
        } else {
37
            (new Dotenv($dir, $file))->overload();
38
        }
39
    }
40
}
41