Test Failed
Push — stable ( 994ca0...7d5c83 )
by Nuno
04:30
created

Installer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 5
eloc 27
dl 0
loc 56
ccs 21
cts 24
cp 0.875
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A install() 0 41 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\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 3
    public function install(): void
39
    {
40 3
        $this->require('vlucas/phpdotenv');
41
42 3
        $this->task(
43 3
            'Creating .env',
44
            function () {
45 3
                if (! File::exists(base_path('.env'))) {
46 3
                    return File::put(base_path('.env'), 'CONSUMER_KEY=');
47
                }
48
49
                return false;
50 3
            }
51
        );
52
53 3
        $this->task(
54 3
            'Creating .env.example',
55
            function () {
56 3
                if (! File::exists(base_path('.env.example'))) {
57 3
                    return File::put(base_path('.env.example'), 'CONSUMER_KEY=');
58
                }
59
60
                return false;
61 3
            }
62
        );
63
64 3
        $this->task(
65 3
            'Updating .gitignore',
66
            function () {
67 3
                $gitignorePath = base_path('.gitignore');
68 3
                if (File::exists($gitignorePath)) {
69 3
                    $contents = File::get($gitignorePath);
70 3
                    $neededLine = '.env';
71 3
                    if (! Str::contains($contents, $neededLine)) {
72 3
                        File::append($gitignorePath, $neededLine.PHP_EOL);
73
74 3
                        return true;
75
                    }
76
                }
77
78
                return false;
79 3
            }
80
        );
81 3
    }
82
}
83