| Conditions | 26 |
| Paths | > 20000 |
| Total Lines | 121 |
| Code Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 145 | public function setupEnv() { |
||
| 146 | $env = base_path('.env'); |
||
| 147 | $filesystem = new Filesystem; |
||
| 148 | $env_contents = $filesystem->get($env); |
||
| 149 | |||
| 150 | $learning_locker_url = getEnv(strtoupper(LearningLockerConstants::URL)); |
||
| 151 | $learning_locker_key = getEnv(strtoupper(LearningLockerConstants::KEY)); |
||
| 152 | $learning_locker_secret = getEnv(strtoupper(LearningLockerConstants::SECRET)); |
||
| 153 | |||
| 154 | // Has variable and value |
||
| 155 | $url_has_variable_and_value = isset($learning_locker_url) && !empty($learning_locker_url); |
||
| 156 | $key_has_variable_and_value = isset($learning_locker_key) && !empty($learning_locker_key); |
||
| 157 | $secret_has_variable_and_value = isset($learning_locker_secret) && !empty($learning_locker_secret); |
||
| 158 | |||
| 159 | // Has variable with no value |
||
| 160 | $url_has_variable_with_no_value = false !== strpos($env_contents, strtoupper(LearningLockerConstants::URL)) && empty($learning_locker_url); |
||
| 161 | $key_has_variable_with_no_value = false !== strpos($env_contents, strtoupper(LearningLockerConstants::KEY)) && empty($learning_locker_key); |
||
| 162 | $secret_has_variable_with_no_value = false !== strpos($env_contents, strtoupper(LearningLockerConstants::SECRET)) && empty($learning_locker_secret); |
||
| 163 | |||
| 164 | // Has no variable and no value |
||
| 165 | $url_has_no_variable_and_no_value = true !== strpos($env_contents, strtoupper(LearningLockerConstants::URL)); |
||
| 166 | $key_has_no_variable_and_no_value = true !== strpos($env_contents, strtoupper(LearningLockerConstants::KEY)); |
||
| 167 | $secret_has_no_variable_and_no_value = true !== strpos($env_contents, strtoupper(LearningLockerConstants::SECRET)); |
||
| 168 | |||
| 169 | // Do the env smarts |
||
| 170 | if ($url_has_variable_and_value && $key_has_variable_and_value && $secret_has_variable_and_value) { |
||
| 171 | |||
| 172 | if ($this->confirm('Update Learning Locker® api connection?')) { |
||
| 173 | $domain = $this->anticipate("What's the new Learning Locker® url?", [ |
||
| 174 | 'https://saas.learninglocker.net', 'http://saas.learninglocker.net' |
||
| 175 | ]); |
||
| 176 | $this->setEnv([strtoupper(LearningLockerConstants::URL) => $domain]); |
||
| 177 | |||
| 178 | $key = $this->ask("What's the new Learning Locker® client key?"); |
||
| 179 | $this->setEnv([strtoupper(LearningLockerConstants::KEY) => $key]); |
||
| 180 | |||
| 181 | $secret = $this->secret("What's the new Learning Locker® client secret"); |
||
| 182 | $this->setEnv([strtoupper(LearningLockerConstants::SECRET) => $secret]); |
||
| 183 | } |
||
| 184 | |||
| 185 | } else { |
||
| 186 | try { |
||
| 187 | |||
| 188 | // Check .env for Learning Locker® url status |
||
| 189 | switch (file_exists($env)) { |
||
| 190 | case $url_has_variable_and_value: |
||
| 191 | if ($this->confirm('Update Learning Locker® domain?')) { |
||
| 192 | $domain = $this->anticipate("What's the new Learning Locker® domain?", [ |
||
| 193 | 'https://saas.learninglocker.net', 'http://saas.learninglocker.net' |
||
| 194 | ]); |
||
| 195 | $this->setEnv([strtoupper(LearningLockerConstants::URL) => $domain]); |
||
| 196 | } |
||
| 197 | break; |
||
| 198 | case $url_has_variable_with_no_value: |
||
| 199 | $domain = $this->anticipate("What's your Learning Locker® url?", [ |
||
| 200 | 'https://saas.learninglocker.net', 'http://saas.learninglocker.net' |
||
| 201 | ]); |
||
| 202 | $this->setEnv([strtoupper(LearningLockerConstants::URL) => $domain]); |
||
| 203 | break; |
||
| 204 | case $url_has_no_variable_and_no_value: |
||
| 205 | $domain = $this->anticipate("What's your Learning Locker® url?", [ |
||
| 206 | 'https://saas.learninglocker.net', 'http://saas.learninglocker.net' |
||
| 207 | ]); |
||
| 208 | $this->createEnv(strtoupper(LearningLockerConstants::URL), $domain); |
||
| 209 | break; |
||
| 210 | } |
||
| 211 | |||
| 212 | // Check .env for Learning Locker® client key status |
||
| 213 | switch (file_exists($env)) { |
||
| 214 | case $key_has_variable_and_value: |
||
| 215 | if ($this->confirm('Update Learning Locker® client key?')) { |
||
| 216 | $key = $this->ask("What's the new Learning Locker® client key?"); |
||
| 217 | $this->setEnv([strtoupper(LearningLockerConstants::KEY) => $key]); |
||
| 218 | } |
||
| 219 | break; |
||
| 220 | case $key_has_variable_with_no_value: |
||
| 221 | $key = $this->ask("What's your Learning Locker® client key?"); |
||
| 222 | $this->setEnv([strtoupper(LearningLockerConstants::KEY) => $key]); |
||
| 223 | break; |
||
| 224 | case $key_has_no_variable_and_no_value: |
||
| 225 | $key = $this->ask("What's your Learning Locker® client key?"); |
||
| 226 | $this->createEnv(strtoupper(LearningLockerConstants::KEY), $key); |
||
| 227 | break; |
||
| 228 | } |
||
| 229 | |||
| 230 | // Check .env for Learning Locker® client secret status |
||
| 231 | switch (file_exists($env)) { |
||
| 232 | case $secret_has_variable_and_value: |
||
| 233 | if ($this->confirm('Update Learning Locker® client secret?')) { |
||
| 234 | $secret = $this->secret("What's the new Learning Locker® client secret"); |
||
| 235 | $this->setEnv([strtoupper(LearningLockerConstants::KEY) => $key]); |
||
| 236 | } |
||
| 237 | break; |
||
| 238 | case $secret_has_variable_with_no_value: |
||
| 239 | $secret = $this->secret("What's your Learning Locker® client secret"); |
||
| 240 | $this->setEnv([strtoupper(LearningLockerConstants::KEY) => $secret]); |
||
| 241 | break; |
||
| 242 | case $secret_has_no_variable_and_no_value: |
||
| 243 | $secret = $this->secret("What's your Learning Locker® client secret"); |
||
| 244 | $this->createEnv(strtoupper(LearningLockerConstants::SECRET), $secret); |
||
| 245 | break; |
||
| 246 | } |
||
| 247 | |||
| 248 | } catch (Exception $e) { |
||
| 249 | return $e->getMessage(); |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 253 | return $this->info(" << Connecting to Learning Locker®..."); |
||
| 254 | |||
| 255 | $connectionCheck = \LearningLocker::connection()->check(env(strtoupper(LearningLockerConstants::URL))); |
||
| 256 | |||
| 257 | if ($connectionCheck) { |
||
| 258 | return $this->info(" << Connected to Learning Locker® Succussfully"); |
||
| 259 | } |
||
| 260 | |||
| 261 | if ($this->confirm('Try updating Learning Locker® details again?')) { |
||
| 262 | return $this->setupEnv(); |
||
| 263 | } |
||
| 264 | |||
| 265 | return $this->error("Unable to connection with Learning Locker®"); |
||
| 266 | } |
||
| 375 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths