| Conditions | 12 |
| Paths | 83 |
| Total Lines | 93 |
| 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 |
||
| 105 | public function extract() |
||
| 106 | { |
||
| 107 | if ($this->catalogue) { |
||
| 108 | throw new \RuntimeException('Invalid state'); |
||
| 109 | } |
||
| 110 | |||
| 111 | $this->catalogue = new MessageCatalogue(); |
||
| 112 | |||
| 113 | foreach ($this->adminPool->getAdminGroups() as $name => $group) { |
||
| 114 | $this->trans($name, [], $group['label_catalogue']); |
||
| 115 | } |
||
| 116 | |||
| 117 | foreach ($this->adminPool->getAdminServiceIds() as $id) { |
||
| 118 | $admin = $this->getAdmin($id); |
||
| 119 | |||
| 120 | $label = $admin->getLabel(); |
||
| 121 | if (!empty($label)) { |
||
| 122 | $this->trans($label, [], $admin->getTranslationDomain()); |
||
| 123 | } |
||
| 124 | |||
| 125 | $this->labelStrategy = $admin->getLabelTranslatorStrategy(); |
||
| 126 | $this->domain = $admin->getTranslationDomain(); |
||
| 127 | |||
| 128 | $admin->setTranslator($this); |
||
| 129 | $admin->setSecurityHandler($this); |
||
| 130 | $admin->setLabelTranslatorStrategy($this); |
||
| 131 | |||
| 132 | // call the different public method |
||
| 133 | $methods = [ |
||
| 134 | 'getShow', |
||
| 135 | 'getDatagrid', |
||
| 136 | 'getList', |
||
| 137 | 'getForm', |
||
| 138 | ]; |
||
| 139 | |||
| 140 | $actions = [ |
||
| 141 | 'list', |
||
| 142 | 'edit', |
||
| 143 | 'create', |
||
| 144 | 'update', |
||
| 145 | 'batch', |
||
| 146 | 'delete', |
||
| 147 | ]; |
||
| 148 | |||
| 149 | if ($this->logger) { |
||
| 150 | $this->logger->info(sprintf( |
||
| 151 | 'Retrieving message from admin:%s - class: %s', |
||
| 152 | $admin->getCode(), |
||
| 153 | \get_class($admin) |
||
| 154 | )); |
||
| 155 | } |
||
| 156 | |||
| 157 | foreach ($methods as $method) { |
||
| 158 | try { |
||
| 159 | $admin->$method(); |
||
| 160 | } catch (\Exception $e) { |
||
| 161 | if ($this->logger) { |
||
| 162 | $this->logger->error(sprintf( |
||
| 163 | 'ERROR : admin:%s - Raise an exception : %s', |
||
| 164 | $admin->getCode(), |
||
| 165 | $e->getMessage() |
||
| 166 | )); |
||
| 167 | } |
||
| 168 | |||
| 169 | throw $e; |
||
| 170 | } |
||
| 171 | } |
||
| 172 | |||
| 173 | foreach ($actions as $action) { |
||
| 174 | try { |
||
| 175 | $this->breadcrumbsBuilder->getBreadcrumbs($admin, $action); |
||
| 176 | } catch (\Exception $e) { |
||
| 177 | if ($this->logger) { |
||
| 178 | $this->logger->error( |
||
| 179 | sprintf( |
||
| 180 | 'ERROR : admin:%s - Raises an exception : %s', |
||
| 181 | $admin->getCode(), |
||
| 182 | $e->getMessage() |
||
| 183 | ), |
||
| 184 | ['exception' => $e] |
||
| 185 | ); |
||
| 186 | } |
||
| 187 | |||
| 188 | throw $e; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | $catalogue = $this->catalogue; |
||
| 194 | $this->catalogue = false; |
||
| 195 | |||
| 196 | return $catalogue; |
||
| 197 | } |
||
| 198 | |||
| 263 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.