Installer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 86.96%

Importance

Changes 0
Metric Value
wmc 5
eloc 26
dl 0
loc 54
ccs 20
cts 23
cp 0.8696
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A install() 0 39 5
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Components\Dotenv;
15
16
use Illuminate\Support\Facades\File;
17
use Illuminate\Support\Str;
18
use LaravelZero\Framework\Components\AbstractInstaller;
19
20
/**
21
 * @internal
22
 */
23
final class Installer extends AbstractInstaller
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected $name = 'install:dotenv';
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected $description = 'Dotenv: Loads environment variables from ".env"';
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 2
    public function install(): void
39
    {
40 2
        $this->task(
41 2
            'Creating .env',
42
            function () {
43 2
                if (! File::exists(base_path('.env'))) {
44 2
                    return File::put(base_path('.env'), 'CONSUMER_KEY=');
45
                }
46
47
                return false;
48 2
            }
49
        );
50
51 2
        $this->task(
52 2
            'Creating .env.example',
53
            function () {
54 2
                if (! File::exists(base_path('.env.example'))) {
55 2
                    return File::put(base_path('.env.example'), 'CONSUMER_KEY=');
56
                }
57
58
                return false;
59 2
            }
60
        );
61
62 2
        $this->task(
63 2
            'Updating .gitignore',
64
            function () {
65 2
                $gitignorePath = base_path('.gitignore');
66 2
                if (File::exists($gitignorePath)) {
67 2
                    $contents = File::get($gitignorePath);
68 2
                    $neededLine = '.env';
69 2
                    if (! Str::contains($contents, $neededLine)) {
70 2
                        File::append($gitignorePath, $neededLine.PHP_EOL);
71
72 2
                        return true;
73
                    }
74
                }
75
76
                return false;
77 2
            }
78
        );
79 2
    }
80
}
81