| Conditions | 5 |
| Paths | 9 |
| Total Lines | 54 |
| 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 |
||
| 29 | public function actionIndex() |
||
| 30 | { |
||
| 31 | $variables = $this->getPlugin()->getEditProvider()->getBaseVariables(); |
||
| 32 | $plugin = $this->getPlugin(); |
||
| 33 | $variables['myProvider'] = null; |
||
| 34 | $variables['spProviders'] = []; |
||
| 35 | $variables['idpProviders'] = []; |
||
| 36 | $variables['idpListInstructions'] = $this->getListInstructions(SettingsInterface::IDP); |
||
| 37 | $variables['spListInstructions'] = $this->getListInstructions(SettingsInterface::SP); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Breadcrumbs |
||
| 41 | */ |
||
| 42 | $variables['crumbs'] = [ |
||
| 43 | [ |
||
| 44 | 'url' => UrlHelper::cpUrl($this->getPlugin()->getHandle()), |
||
| 45 | 'label' => $this->getPlugin()->name, |
||
| 46 | ], |
||
| 47 | [ |
||
| 48 | 'url' => UrlHelper::cpUrl($this->getPlugin()->getHandle()) . '/metadata', |
||
| 49 | 'label' => 'Provider List', |
||
| 50 | ], |
||
| 51 | ]; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Get IDPs |
||
| 55 | */ |
||
| 56 | foreach ($plugin->getProvider()->findByIdp([ |
||
| 57 | 'enabled' => [true, false], |
||
| 58 | ])->all() as $provider) { |
||
| 59 | $variables['idpProviders'][] = $provider; |
||
| 60 | if ($provider->getEntityId() == $this->getPlugin()->getSettings()->getEntityId()) { |
||
| 61 | $variables['myProvider'] = $provider; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Get SPs |
||
| 67 | */ |
||
| 68 | foreach ($plugin->getProvider()->findBySp([ |
||
| 69 | 'enabled' => [true, false], |
||
| 70 | ])->all() as $provider) { |
||
| 71 | $variables['spProviders'][] = $provider; |
||
| 72 | if ($provider->getEntityId() == $this->getPlugin()->getSettings()->getEntityId()) { |
||
| 73 | $variables['myProvider'] = $provider; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | $variables['title'] = Craft::t($this->getPlugin()->getHandle(), $this->getPlugin()->name); |
||
| 78 | return $this->renderTemplate( |
||
| 79 | $this->getPlugin()->getEditProvider()->getTemplateIndex() . static::TEMPLATE_INDEX . DIRECTORY_SEPARATOR . 'list', |
||
| 80 | $variables |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 128 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.