| Conditions | 18 |
| Paths | 19 |
| Total Lines | 71 |
| 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 |
||
| 96 | private function deconstructArgs($function, $args) |
||
| 97 | { |
||
| 98 | $domain = null; |
||
| 99 | $context = null; |
||
| 100 | $original = null; |
||
| 101 | $plural = null; |
||
| 102 | |||
| 103 | switch ($function) { |
||
| 104 | case 'noop': |
||
| 105 | case 'gettext': |
||
| 106 | if (!isset($args[0])) { |
||
| 107 | return null; |
||
| 108 | } |
||
| 109 | |||
| 110 | $original = $args[0]; |
||
| 111 | break; |
||
| 112 | case 'ngettext': |
||
| 113 | if (!isset($args[1])) { |
||
| 114 | return null; |
||
| 115 | } |
||
| 116 | |||
| 117 | list($original, $plural) = $args; |
||
| 118 | break; |
||
| 119 | case 'pgettext': |
||
| 120 | if (!isset($args[1])) { |
||
| 121 | return null; |
||
| 122 | } |
||
| 123 | |||
| 124 | list($context, $original) = $args; |
||
| 125 | break; |
||
| 126 | case 'dgettext': |
||
| 127 | if (!isset($args[1])) { |
||
| 128 | return null; |
||
| 129 | } |
||
| 130 | |||
| 131 | list($domain, $original) = $args; |
||
| 132 | break; |
||
| 133 | case 'dpgettext': |
||
| 134 | if (!isset($args[2])) { |
||
| 135 | return null; |
||
| 136 | } |
||
| 137 | |||
| 138 | list($domain, $context, $original) = $args; |
||
| 139 | break; |
||
| 140 | case 'npgettext': |
||
| 141 | if (!isset($args[2])) { |
||
| 142 | return null; |
||
| 143 | } |
||
| 144 | |||
| 145 | list($context, $original, $plural) = $args; |
||
| 146 | break; |
||
| 147 | case 'dnpgettext': |
||
| 148 | if (!isset($args[3])) { |
||
| 149 | return null; |
||
| 150 | } |
||
| 151 | |||
| 152 | list($domain, $context, $original, $plural) = $args; |
||
| 153 | break; |
||
| 154 | case 'dngettext': |
||
| 155 | if (!isset($args[2])) { |
||
| 156 | return null; |
||
| 157 | } |
||
| 158 | |||
| 159 | list($domain, $original, $plural) = $args; |
||
| 160 | break; |
||
| 161 | default: |
||
| 162 | throw new Exception(sprintf('Not valid function %s', $function)); |
||
| 163 | } |
||
| 164 | |||
| 165 | return [$domain, $context, $original, $plural]; |
||
| 166 | } |
||
| 167 | } |
||
| 168 |