| Conditions | 8 |
| Paths | 40 |
| Total Lines | 55 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 62 | public function activation(?Domain $domain, Module $module, Request $request) |
||
| 63 | { |
||
| 64 | // Pre-process |
||
| 65 | $this->preProcess($domain, $module, $request); |
||
| 66 | |||
| 67 | // Activate or deactivate a module on the current domain |
||
| 68 | $success = false; |
||
| 69 | $error = ''; |
||
| 70 | if (request('src_module')) { |
||
| 71 | $sourceModule = ucmodule(request('src_module')); |
||
| 72 | $isActive = request('active') == 1; |
||
| 73 | |||
| 74 | if ($sourceModule) { |
||
| 75 | // Activate the module on the current domain |
||
| 76 | if ($isActive === true) { |
||
| 77 | $domain->modules()->attach($sourceModule); |
||
| 78 | $success = true; |
||
| 79 | $message = 'message.module_activated'; |
||
| 80 | } |
||
| 81 | // Deactivate the module on the current domain only if it is not mandatory |
||
| 82 | elseif (!$sourceModule->isMandatory()) { |
||
| 83 | $domain->modules()->detach($sourceModule); |
||
| 84 | $success = true; |
||
| 85 | $message = 'message.module_deactivated'; |
||
| 86 | } |
||
| 87 | // Impossible to deactivate a mandatory module |
||
| 88 | else { |
||
| 89 | $error = 'error.module_is_mandatory'; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 | // Module name is not defined |
||
| 94 | else { |
||
| 95 | $error = 'error.module_not_defined'; |
||
| 96 | } |
||
| 97 | |||
| 98 | $result = [ |
||
| 99 | 'success' => $success |
||
| 100 | ]; |
||
| 101 | |||
| 102 | // Add message if defined |
||
| 103 | if (!empty($message)) { |
||
| 104 | $result[ 'message' ] = uctrans($message, $module); |
||
| 105 | } |
||
| 106 | |||
| 107 | // Add error if defined |
||
| 108 | if (!empty($error)) { |
||
| 109 | $result[ 'error' ] = uctrans($error, $module); |
||
| 110 | } |
||
| 111 | |||
| 112 | if ($success) { |
||
| 113 | Artisan::call('cache:clear'); |
||
| 114 | } |
||
| 115 | |||
| 116 | return $result; |
||
| 117 | } |
||
| 118 | } |