| Conditions | 23 |
| Paths | 43 |
| Total Lines | 88 |
| Code Lines | 53 |
| 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 |
||
| 25 | public function saveGettextFunctions(Translations $translations, array $options) |
||
| 26 | { |
||
| 27 | $functions = $options['functions']; |
||
| 28 | $file = $options['file']; |
||
| 29 | |||
| 30 | foreach ($this->getFunctions($options['constants']) as $function) { |
||
| 31 | list($name, $line, $args) = $function; |
||
| 32 | |||
| 33 | if (!isset($functions[$name])) { |
||
| 34 | continue; |
||
| 35 | } |
||
| 36 | |||
| 37 | $domain = $context = $original = $plural = null; |
||
| 38 | |||
| 39 | switch ($functions[$name]) { |
||
| 40 | case 'noop': |
||
| 41 | case 'gettext': |
||
| 42 | if (!isset($args[0])) { |
||
| 43 | continue 2; |
||
| 44 | } |
||
| 45 | |||
| 46 | $original = $args[0]; |
||
| 47 | break; |
||
| 48 | |||
| 49 | case 'ngettext': |
||
| 50 | if (!isset($args[1])) { |
||
| 51 | continue 2; |
||
| 52 | } |
||
| 53 | |||
| 54 | list($original, $plural) = $args; |
||
| 55 | break; |
||
| 56 | |||
| 57 | case 'pgettext': |
||
| 58 | if (!isset($args[1])) { |
||
| 59 | continue 2; |
||
| 60 | } |
||
| 61 | |||
| 62 | list($context, $original) = $args; |
||
| 63 | break; |
||
| 64 | |||
| 65 | case 'dgettext': |
||
| 66 | if (!isset($args[1])) { |
||
| 67 | continue 2; |
||
| 68 | } |
||
| 69 | |||
| 70 | list($domain, $original) = $args; |
||
| 71 | break; |
||
| 72 | |||
| 73 | case 'dpgettext': |
||
| 74 | if (!isset($args[2])) { |
||
| 75 | continue 2; |
||
| 76 | } |
||
| 77 | |||
| 78 | list($domain, $context, $original) = $args; |
||
| 79 | break; |
||
| 80 | |||
| 81 | case 'npgettext': |
||
| 82 | if (!isset($args[2])) { |
||
| 83 | continue 2; |
||
| 84 | } |
||
| 85 | |||
| 86 | list($context, $original, $plural) = $args; |
||
| 87 | break; |
||
| 88 | |||
| 89 | case 'dnpgettext': |
||
| 90 | if (!isset($args[4])) { |
||
| 91 | continue 2; |
||
| 92 | } |
||
| 93 | |||
| 94 | list($domain, $context, $original, $plural) = $args; |
||
| 95 | break; |
||
| 96 | |||
| 97 | default: |
||
| 98 | throw new Exception(sprintf('Not valid function %s', $functions[$name])); |
||
| 99 | } |
||
| 100 | |||
| 101 | if ((string) $original !== '' && ($domain === null || $domain === $translations->getDomain())) { |
||
| 102 | $translation = $translations->insert($context, $original, $plural); |
||
| 103 | $translation->addReference($file, $line); |
||
| 104 | |||
| 105 | if (isset($function[3])) { |
||
| 106 | foreach ($function[3] as $extractedComment) { |
||
| 107 | $translation->addExtractedComment($extractedComment); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 |