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