Completed
Pull Request — stable (#353)
by Matt
04:33
created

Installer::install()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 39
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 39
ccs 0
cts 23
cp 0
rs 9.2408
c 0
b 0
f 0
cc 5
nc 1
nop 0
crap 30
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\Str;
17
use Illuminate\Support\Facades\File;
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
    public function install(): void
39
    {
40
        $this->task(
41
            'Creating .env',
42
            function () {
43
                if (! File::exists(base_path('.env'))) {
44
                    return File::put(base_path('.env'), 'CONSUMER_KEY=');
45
                }
46
47
                return false;
48
            }
49
        );
50
51
        $this->task(
52
            'Creating .env.example',
53
            function () {
54
                if (! File::exists(base_path('.env.example'))) {
55
                    return File::put(base_path('.env.example'), 'CONSUMER_KEY=');
56
                }
57
58
                return false;
59
            }
60
        );
61
62
        $this->task(
63
            'Updating .gitignore',
64
            function () {
65
                $gitignorePath = base_path('.gitignore');
66
                if (File::exists($gitignorePath)) {
67
                    $contents = File::get($gitignorePath);
68
                    $neededLine = '.env';
69
                    if (! Str::contains($contents, $neededLine)) {
70
                        File::append($gitignorePath, $neededLine.PHP_EOL);
71
72
                        return true;
73
                    }
74
                }
75
76
                return false;
77
            }
78
        );
79
    }
80
}
81