Conditions | 14 |
Paths | 0 |
Total Lines | 82 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
77 | public function handle() |
||
78 | { |
||
79 | $this->abortCommandExecution(); |
||
80 | $this->info("I'm going to install this project to production..."); |
||
81 | |||
82 | if ($this->confirm('Do you have ignored local files you want to add to production?')) { |
||
83 | $this->call('publish:ignored'); |
||
84 | } |
||
85 | |||
86 | if ($this->confirm('Do you have ignored local Github projects that do you want to add to production?')) { |
||
87 | $this->call('publish:git_dependencies'); |
||
88 | } |
||
89 | |||
90 | $this->call('publish:composer', [ |
||
91 | 'composer_command' => 'install' |
||
92 | ]); |
||
93 | |||
94 | $this->call('publish:npm', [ |
||
95 | 'npm_command' => 'install', |
||
96 | ]); |
||
97 | |||
98 | $this->call('publish:key_generate'); |
||
99 | |||
100 | check_env_production: |
||
101 | |||
102 | if (! File::exists($productionEnv = base_path('.env.production'))) { |
||
103 | $this->error("File $productionEnv not found!"); |
||
104 | $this->line("Be careful! Without $productionEnv file the default Laravel Forge .env will be applied."); |
||
105 | $this->line("For example default database forge will be used. This could affect other apps in production using the same database"); |
||
106 | if ($this->confirm('Do you want to create the File? please choose yes once you have been created the file!')) { |
||
107 | goto check_env_production; |
||
108 | } |
||
109 | } else { |
||
110 | if (! File::exists($gitIgnore = base_path('.gitignore'))) { |
||
111 | $this->error("Be careful! File $gitIgnore doesn't exists and you have a $productionEnv file. Be sure you are not publishing sensible data to your repo!"); |
||
112 | } else { |
||
113 | if (strpos(file_get_contents($gitIgnore), ".env.production") === false) { |
||
114 | $this->error("Be careful! File $gitIgnore doesn't have $productionEnv file. Be sure you are not publishing sensible data to your repo!"); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | if ($this->confirm('Do you wish to install .env.production file and overwrite .env in production?')) { |
||
119 | $this->call('publish:env-production'); |
||
120 | } |
||
121 | |||
122 | $mysql_data = $this->obtainMySQLDatabaseInfoFromEnv(base_path('.env.production')); |
||
123 | |||
124 | if (! $mysql_data) { |
||
125 | $this->error('Not all MYSQL info (DB_CONNECTION=mysql,DB_DATABASE,DB_USER,DB_PASSWORD,) found in .env production'); |
||
126 | } else { |
||
127 | $this->info("We have found a MYSQL database and user configuration in your .env.production file."); |
||
128 | $this->line("Database type: MySQL"); |
||
129 | $this->line("Database name: " . $mysql_data['name']); |
||
130 | $this->line("Database user: " . $mysql_data['user']); |
||
131 | if ($this->confirm('Do you want to create this database and user in production?')) { |
||
132 | $this->call('publish:mysql', array_merge($mysql_data, ['--wait' => true])); |
||
133 | } |
||
134 | $this->databaseAlreadyConfigured = true; |
||
135 | } |
||
136 | } |
||
137 | |||
138 | if (! $this->databaseAlreadyConfigured) { |
||
139 | if ($this->confirm('Do you want to create a database in production?')) { |
||
140 | $mysql_data['name'] = $this->ask('Database?'); |
||
|
|||
141 | $mysql_data['user'] = $this->ask('User?'); |
||
142 | $mysql_data['password'] = $this->secret('Password?'); |
||
143 | $this->call('publish:mysql', $mysql_data); |
||
144 | } |
||
145 | } |
||
146 | |||
147 | if ($this->confirm('Do you wish run migrations on production?')) { |
||
148 | $this->call('publish:artisan', [ |
||
149 | 'artisan_command' => 'migrate --force', |
||
150 | ]); |
||
151 | } |
||
152 | |||
153 | if ($this->confirm('Do you want to seed database on production?')) { |
||
154 | $this->call('publish:artisan', [ |
||
155 | 'artisan_command' => 'db:seed --force', |
||
156 | ]); |
||
157 | } |
||
158 | } |
||
159 | |||
198 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: