| Conditions | 12 | 
| Paths | 20 | 
| Total Lines | 50 | 
| 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 | ||
| 11 | public static function createFromArray(array $entryArray) | ||
| 12 |     { | ||
| 13 | $entry = new Entry( | ||
| 14 | $entryArray['msgid'], | ||
| 15 | isset($entryArray['msgstr']) ? $entryArray['msgstr'] : null | ||
| 16 | ); | ||
| 17 | $plurals = array(); | ||
| 18 | |||
| 19 |         foreach ($entryArray as $key => $value) { | ||
| 20 |             switch (true) { | ||
| 21 | case $key === 'msgctxt': | ||
| 22 | $entry->setMsgCtxt($entryArray['msgctxt']); | ||
| 23 | break; | ||
| 24 | |||
| 25 | case $key === 'flags': | ||
| 26 | $entry->setFlags($entryArray['flags']); | ||
| 27 | break; | ||
| 28 | |||
| 29 | case $key === 'reference': | ||
| 30 | $entry->setReference($entryArray['reference']); | ||
| 31 | break; | ||
| 32 | |||
| 33 | case $key === 'previous': | ||
| 34 | $entry->setPreviousEntry(self::createFromArray($entryArray['previous'])); | ||
| 35 | break; | ||
| 36 | |||
| 37 | case $key === 'tcomment': | ||
| 38 | $entry->setTranslatorComments($value); | ||
| 39 | break; | ||
| 40 | |||
| 41 | case $key === 'ccomment': | ||
| 42 | $entry->setDeveloperComments($value); | ||
| 43 | break; | ||
| 44 | |||
| 45 | case $key === 'obsolete': | ||
| 46 | $entry->setObsolete(true); | ||
| 47 | break; | ||
| 48 | |||
| 49 | case 0 === strpos($key, 'msgstr['): | ||
| 50 | $plurals[] = $value; | ||
| 51 | break; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 |         if (count($plurals) > 0) { | ||
| 56 | $entry->setMsgStrPlurals($plurals); | ||
| 57 | } | ||
| 58 | |||
| 59 | return $entry; | ||
| 60 | } | ||
| 61 | } | ||
| 62 |