| Conditions | 10 |
| Paths | 9 |
| Total Lines | 47 |
| Code Lines | 27 |
| 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 |
||
| 26 | public function run($request) |
||
| 27 | { |
||
| 28 | $vars = $request->getVars(); |
||
| 29 | |||
| 30 | // Check for args |
||
| 31 | $args = $this->processArgs($request->getVar('args') ?: []); |
||
| 32 | $isReplace = in_array('r', $args); |
||
| 33 | $isForce = in_array('f', $args); |
||
| 34 | |||
| 35 | unset($vars['url']); |
||
| 36 | if (empty($vars) && !$isReplace) { |
||
| 37 | $this->outputHelp(); |
||
| 38 | return; |
||
| 39 | } |
||
| 40 | |||
| 41 | $addons = $request->getVar('addons'); |
||
| 42 | |||
| 43 | if ($isReplace) { |
||
| 44 | // Catch a mistake of replacing addons but providing no addons to replace it with |
||
| 45 | if (empty($addons) && !$isForce) { |
||
| 46 | $this->output('Providing no addons when using -r will unsupport all addons. Use -f to force.'); |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | // Mark all addons as unsupported |
||
| 51 | $this->output('All addons have been marked unsupported'); |
||
| 52 | SQLUpdate::create('Addon', ['Supported' => false])->execute(); |
||
| 53 | |||
| 54 | // If there are no addons to replace with, say as such and return |
||
| 55 | if (empty($addons)) { |
||
| 56 | return; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | $addons = explode(',', $addons); |
||
| 61 | $addonList = Addon::get()->filter('Name', $addons); |
||
| 62 | |||
| 63 | foreach ($addons as $addon) { |
||
| 64 | if ($addonObject = $addonList->find('Name', $addon)) { |
||
| 65 | $addonObject->Supported = true; |
||
| 66 | $addonObject->write(); |
||
| 67 | $this->output($addon . ' marked as supported'); |
||
| 68 | } else { |
||
| 69 | $this->output($addon . ' did not match a known addon'); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 113 |