| Conditions | 8 |
| Paths | 66 |
| Total Lines | 51 |
| Code Lines | 34 |
| 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 |
||
| 133 | protected function addMissing($result, $group) { |
||
| 134 | foreach ($result as $item) { |
||
| 135 | try { |
||
| 136 | $identifier = trim($item['identifier']); |
||
| 137 | $this->found_identifier++; |
||
| 138 | |||
| 139 | $parameters = null; |
||
| 140 | |||
| 141 | if (isset($item['parameters'])) { |
||
| 142 | $parameter_string = $item['parameters']; |
||
| 143 | |||
| 144 | if (substr($parameter_string, 0, 1) === '[') { |
||
| 145 | $parameter_string = substr($parameter_string, 1, -1); |
||
| 146 | } |
||
| 147 | |||
| 148 | $parameter_array = explode(",", $parameter_string); |
||
| 149 | $parameters = array(); |
||
| 150 | |||
| 151 | foreach ($parameter_array as $parameter) { |
||
| 152 | $parameter = explode("=>", $parameter); |
||
| 153 | |||
| 154 | $key = str_replace([" ", "'"], "", $parameter[0]); |
||
| 155 | $value = str_replace([" ", "'"], "", $parameter[1]); |
||
| 156 | |||
| 157 | $parameters[$key] = $value; |
||
| 158 | } |
||
| 159 | |||
| 160 | $this->found_parameters++; |
||
| 161 | } |
||
| 162 | |||
| 163 | if (!isset($aTranslations[$identifier])) { |
||
| 164 | $aTranslations[$identifier] = TranslatorFacade::hasIdentifier($identifier); |
||
| 165 | |||
| 166 | if (!$aTranslations[$identifier]) { |
||
| 167 | TranslatorFacade::addMissingIdentifier($identifier, $parameters, $group); |
||
| 168 | $this->bar->clear(); |
||
| 169 | $this->info('Adding: "' . $identifier . '" to database'); |
||
| 170 | $this->bar->display(); |
||
| 171 | $this->new_identifier++; |
||
| 172 | } |
||
| 173 | } else { |
||
| 174 | $this->dupl_identifier++; |
||
| 175 | } |
||
| 176 | |||
| 177 | } catch (\Exception $e) { |
||
| 178 | $this->bar->clear(); |
||
| 179 | $this->info($identifier . ' ' . strlen($identifier)); |
||
| 180 | $this->info($e->getMessage()); |
||
| 181 | $this->line(''); |
||
| 182 | $this->bar->display(); |
||
| 183 | $this->found_invalid++; |
||
| 184 | } |
||
| 187 | } |