Completed
Push — master ( 0d4856...a5727b )
by Alexandr
02:34
created

LarrockUpdateEnvCommand::handle()   D

Complexity

Conditions 10
Paths 512

Size

Total Lines 60
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 60
rs 4.6818
cc 10
eloc 39
nc 512
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Larrock\Core\Commands;
4
5
use Illuminate\Console\Command;
6
7
class LarrockUpdateEnvCommand extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'larrock:updateEnv';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Update Laravel .env to Larrock';
22
23
    /**
24
     * Create a new command instance.
25
     *
26
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return mixed
37
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
38
     */
39
    public function handle()
40
    {
41
        $this->line('=== Check Laravel .env ===');
42
43
        if( !env('LARROCK VARS')){
44
            $this->info('=== Add LARROCK vars ===');
45
            $current_env = \File::get(base_path('.env'));
46
            \File::put(base_path('.env'), $current_env ."\n\nLARROCK VARS=PLACED");
47
        }
48
49
        if( !env('MAIL_TEMPLATE_ADDRESS')){
50
            $current_env = \File::get(base_path('.env'));
51
            \File::put(base_path('.env'), $current_env ."\nMAIL_TEMPLATE_ADDRESS='company address'");
52
            $this->info('MAIL_FROM_ADDRESS not found. Add "company address"');
53
        }
54
55
        if( !env('MAIL_TEMPLATE_PHONE')){
56
            $current_env = \File::get(base_path('.env'));
57
            \File::put(base_path('.env'), $current_env ."\nMAIL_TEMPLATE_PHONE=company phone");
58
            $this->info('MAIL_TEMPLATE_PHONE not found. Add "company phone"');
59
        }
60
61
        if( !env('MAIL_TEMPLATE_MAIL')){
62
            $current_env = \File::get(base_path('.env'));
63
            \File::put(base_path('.env'), $current_env ."\[email protected]");
64
            $this->info('MAIL_TEMPLATE_MAIL not found. Add "[email protected]"');
65
        }
66
67
        if( !env('MAIL_FROM_ADDRESS')){
68
            $current_env = \File::get(base_path('.env'));
69
            \File::put(base_path('.env'), $current_env ."\[email protected]");
70
            $this->info('MAIL_FROM_ADDRESS not found. Add "[email protected]"');
71
        }
72
73
        if( !env('MAIL_TO_ADMIN')){
74
            $current_env = \File::get(base_path('.env'));
75
            \File::put(base_path('.env'), $current_env ."\[email protected]");
76
            $this->info('MAIL_TO_ADMIN not found. Add "[email protected]"');
77
        }
78
79
        if( !env('MAIL_FROM_NAME')){
80
            $current_env = \File::get(base_path('.env'));
81
            \File::put(base_path('.env'), $current_env ."\nMAIL_FROM_NAME='LARROCK'");
82
            $this->info('MAIL_FROM_NAME not found. Add "LARROCK"');
83
        }
84
85
        if( !env('SITE_NAME')){
86
            $current_env = \File::get(base_path('.env'));
87
            \File::put(base_path('.env'), $current_env ."\nSITE_NAME='LARROCK'");
88
            $this->info('SITE_NAME not found. Add "LARROCK"');
89
        }
90
91
        if( !env('MAIL_STOP')){
92
            $current_env = \File::get(base_path('.env'));
93
            \File::put(base_path('.env'), $current_env ."\nMAIL_STOP=false");
94
            $this->info('MAIL_STOP not found. Add "false"');
95
        }
96
97
        $this->info('.env vars currently installed');
98
    }
99
}