Passed
Branch develop (893064)
by Nuno
02:09
created

Installer::install()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 5.0488

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 21
cts 24
cp 0.875
rs 8.9528
c 0
b 0
f 0
cc 5
nc 1
nop 0
crap 5.0488
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
final class Installer extends AbstractInstaller
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected $name = 'install:dotenv';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected $description = 'Installs vlucas/phpdotenv';
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 3
    public function install(): void
36
    {
37 3
        $this->require('vlucas/phpdotenv');
38
39 3
        $this->task(
0 ignored issues
show
Bug introduced by
The method task() does not exist on LaravelZero\Framework\Components\Dotenv\Installer. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $this->/** @scrutinizer ignore-call */ 
40
               task(
Loading history...
40 3
            'Creating .env',
41
            function () {
42 3
                if (! File::exists(base_path('.env'))) {
43 3
                    return File::put(base_path('.env'), 'CONSUMER_KEY=');
44
                }
45
46
                return false;
47 3
            }
48
        );
49
50 3
        $this->task(
51 3
            'Creating .env.example',
52
            function () {
53 3
                if (! File::exists(base_path('.env.example'))) {
54 3
                    return File::put(base_path('.env.example'), 'CONSUMER_KEY=');
55
                }
56
57
                return false;
58 3
            }
59
        );
60
61 3
        $this->task(
62 3
            'Updating .gitignore',
63
            function () {
64 3
                $gitignorePath = base_path('.gitignore');
65 3
                if (File::exists($gitignorePath)) {
66 3
                    $contents = File::get($gitignorePath);
67 3
                    $neededLine = '.env';
68 3
                    if (! Str::contains($contents, $neededLine)) {
69 3
                        File::append($gitignorePath, $neededLine . PHP_EOL);
70
71 3
                        return true;
72
                    }
73
                }
74
75
                return false;
76 3
            }
77
        );
78 3
    }
79
}
80