Completed
Push — master ( 6a82b8...7ded25 )
by Ryan
07:10
created

ReadEnvironmentFile::handle()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 23
rs 8.7972
cc 4
eloc 11
nc 4
nop 0
1
<?php namespace Anomaly\Streams\Platform\Application\Command;
2
3
use Illuminate\Contracts\Bus\SelfHandling;
4
5
/**
6
 * Class ReadEnvironmentFile
7
 *
8
 * @link          http://anomaly.is/streams-platform
9
 * @author        AnomalyLabs, Inc. <[email protected]>
10
 * @author        Ryan Thompson <[email protected]>
11
 * @package       Anomaly\Streams\Platform\Application\Command
12
 */
13
class ReadEnvironmentFile implements SelfHandling
14
{
15
16
    /**
17
     * Handle the command.
18
     *
19
     * @return array
20
     */
21
    public function handle()
22
    {
23
        $data = [];
24
25
        if (!file_exists($env = base_path('.env'))) {
26
            return $data;
27
        }
28
29
        foreach (file($env, FILE_IGNORE_NEW_LINES) as $line) {
30
31
            // Check for # comments.
32
            if (starts_with($line, '#')) {
33
                $data[] = $line;
34
            } else {
35
36
                list($key, $value) = explode('=', $line);
37
38
                $data[$key] = $value;
39
            }
40
        }
41
42
        return $data;
43
    }
44
}
45