Conditions | 1 |
Paths | 1 |
Total Lines | 276 |
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 | public function getTests() |
||
86 | { |
||
87 | $variable = new Node([new AssignNameExpression('article', 1)]); |
||
88 | $collectionType = new Node([new AssignNameExpression('articles', 1)]); |
||
89 | $collectionFilters = new FilterExpression( |
||
90 | new Node([$collectionType], [], 0), |
||
91 | new ConstantExpression('start', 0), |
||
92 | new Node([new ConstantExpression(0, 0)]), |
||
93 | 0 |
||
94 | ); |
||
95 | $collectionFiltersFull = new FilterExpression( |
||
96 | new Node([new FilterExpression( |
||
97 | new Node([ |
||
98 | new Node([new FilterExpression( |
||
99 | new Node([$collectionType], [], 0), |
||
100 | new ConstantExpression('order', 0), |
||
101 | new Node([new ArrayExpression([new ConstantExpression('id', 0), new ConstantExpression('desc', 0)], 0)]), |
||
102 | 0 |
||
103 | ), |
||
104 | ], [], 0), |
||
105 | ], [], 0), |
||
106 | new ConstantExpression('limit', 0), |
||
107 | new Node([new ConstantExpression(10, 0)]), |
||
108 | 0 |
||
109 | ), |
||
110 | ], [], 0), |
||
111 | new ConstantExpression('start', 0), |
||
112 | new Node([new ConstantExpression(0, 0)]), |
||
113 | 0 |
||
114 | ); |
||
115 | $parameters = new ArrayExpression([], 1); |
||
116 | $withoutParameters = new ArrayExpression([], 1); |
||
117 | $ignoreContext = new ArrayExpression([], 1); |
||
118 | $ifExpression = new EqualBinary(new GetAttrExpression(new NameExpression('article', 0), new ConstantExpression('title', 0), null, '', 0), |
||
119 | new ConstantExpression('New article', 0), |
||
120 | 0 |
||
121 | ); |
||
122 | $else = new TextNode('', 1); |
||
123 | $body = new TextNode('', 1); |
||
124 | |||
125 | $node1 = new GimmeListNode($variable, $collectionType, null, null, null, null, null, null, $body, 0, 'gimmelist'); |
||
126 | $node2 = new GimmeListNode($variable, $collectionType, $collectionFilters, $parameters, null, null, $ifExpression, $else, $body, 0, 'gimmelist'); |
||
127 | $node3 = new GimmeListNode($variable, $collectionType, $collectionFiltersFull, null, null, null, null, null, $body, 0, 'gimmelist'); |
||
128 | $node4 = new GimmeListNode($variable, $collectionType, $collectionFiltersFull, $parameters, $withoutParameters, null, null, null, $body, 0, 'gimmelist'); |
||
129 | $node5 = new GimmeListNode($variable, $collectionType, $collectionFiltersFull, $parameters, $withoutParameters, null, $ifExpression, null, $body, 0, 'gimmelist'); |
||
130 | $node6 = new GimmeListNode($variable, $collectionType, $collectionFiltersFull, $parameters, $withoutParameters, $ignoreContext, $ifExpression, null, $body, 0, 'gimmelist'); |
||
131 | |||
132 | return [ |
||
133 | [$node1, <<<EOF |
||
134 | \$withParameters = []; |
||
135 | \$withoutParameters = []; |
||
136 | \$swpCollectionMetaLoader1 = \$this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader(); |
||
137 | \$context["articles"] = twig_ensure_traversable(\$swpCollectionMetaLoader1->load("articles", \$withParameters, \$withoutParameters, \SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface::COLLECTION)); |
||
138 | \$context['_parent'] = (array) \$context; |
||
139 | \$context['loop'] = array( |
||
140 | 'parent' => \$context['_parent'], |
||
141 | 'index0' => 0, |
||
142 | 'index' => 1, |
||
143 | 'first' => true, |
||
144 | ); |
||
145 | if (is_array(\$context["articles"]) || (is_object(\$context["articles"]) && \$context["articles"] instanceof Countable)) { |
||
146 | \$length = count(\$context["articles"]); |
||
147 | \$context['loop']['revindex0'] = \$length - 1; |
||
148 | \$context['loop']['revindex'] = \$length; |
||
149 | \$context['loop']['length'] = \$length; |
||
150 | \$context['loop']['totalLength'] = \$length; |
||
151 | \$context['loop']['last'] = 1 === \$length; |
||
152 | } |
||
153 | if(is_object(\$context["articles"]) && \$context["articles"] instanceof \SWP\Component\TemplatesSystem\Gimme\Meta\MetaCollection) { |
||
154 | \$context['loop']['totalLength'] = \$context["articles"]->getTotalItemsCount(); |
||
155 | } |
||
156 | foreach (\$context["articles"] as \$_key => \$context["article"]) { |
||
157 | // line 1 |
||
158 | echo ""; |
||
159 | ++\$context['loop']['index0']; |
||
160 | ++\$context['loop']['index']; |
||
161 | \$context['loop']['first'] = false; |
||
162 | if (isset(\$context['loop']['length'])) { |
||
163 | --\$context['loop']['revindex0']; |
||
164 | --\$context['loop']['revindex']; |
||
165 | \$context['loop']['last'] = 0 === \$context['loop']['revindex0']; |
||
166 | } |
||
167 | } |
||
168 | \$_parent = \$context['_parent']; |
||
169 | unset(\$context['article'], \$context['_iterated'], \$context['articles'], \$context['_parent'], \$context['loop']); |
||
170 | \$context = array_intersect_key(\$context, \$_parent) + \$_parent; |
||
171 | EOF |
||
172 | ], |
||
173 | [$node2, <<<EOF |
||
174 | \$context['_collection_type_filters'] = []; |
||
175 | \$context['articles'] = null; |
||
176 | \$context['_collection_type_filters'] = call_user_func_array(\$this->env->getFilter('start')->getCallable(), [\$context["articles"], 0])['_collection_type_filters']; unset(\$context['articles']['_collection_type_filters']); |
||
177 | \$withParameters = array_merge([], \$context['_collection_type_filters']); |
||
178 | \$withoutParameters = []; |
||
179 | \$swpCollectionMetaLoader2 = \$this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader(); |
||
180 | \$context["articles"] = twig_ensure_traversable(\$swpCollectionMetaLoader2->load("articles", \$withParameters, \$withoutParameters, \SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface::COLLECTION)); |
||
181 | \$context['_parent'] = (array) \$context; |
||
182 | \$context['_iterated'] = false; |
||
183 | \$context['loop'] = array( |
||
184 | 'parent' => \$context['_parent'], |
||
185 | 'index0' => 0, |
||
186 | 'index' => 1, |
||
187 | 'first' => true, |
||
188 | ); |
||
189 | foreach (\$context["articles"] as \$_key => \$context["article"]) { |
||
190 | if ((twig_get_attribute(\$this->env, \$this->source, (\$context["article"] ?? null), "title", [], "", false, false, false, 0) == "New article")) { |
||
191 | // line 1 |
||
192 | echo ""; |
||
193 | \$context['_iterated'] = true; |
||
194 | ++\$context['loop']['index0']; |
||
195 | ++\$context['loop']['index']; |
||
196 | \$context['loop']['first'] = false; |
||
197 | } |
||
198 | } |
||
199 | if (!\$context['_iterated']) { |
||
200 | echo ""; |
||
201 | } |
||
202 | \$_parent = \$context['_parent']; |
||
203 | unset(\$context['article'], \$context['_iterated'], \$context['articles'], \$context['_parent'], \$context['loop']); |
||
204 | unset(\$context['_collection_type_filters']); |
||
205 | \$context = array_intersect_key(\$context, \$_parent) + \$_parent; |
||
206 | EOF |
||
207 | ], |
||
208 | [$node3, <<<EOF |
||
209 | \$context['_collection_type_filters'] = []; |
||
210 | \$context['articles'] = null; |
||
211 | \$context['_collection_type_filters'] = call_user_func_array(\$this->env->getFilter('start')->getCallable(), [call_user_func_array(\$this->env->getFilter('limit')->getCallable(), [call_user_func_array(\$this->env->getFilter('order')->getCallable(), [\$context["articles"], ["id" => "desc"]]), 10]), 0])['_collection_type_filters']; unset(\$context['articles']['_collection_type_filters']); |
||
212 | \$withParameters = \$context['_collection_type_filters']; |
||
213 | \$withoutParameters = []; |
||
214 | \$swpCollectionMetaLoader3 = \$this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader(); |
||
215 | \$context["articles"] = twig_ensure_traversable(\$swpCollectionMetaLoader3->load("articles", \$withParameters, \$withoutParameters, \SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface::COLLECTION)); |
||
216 | \$context['_parent'] = (array) \$context; |
||
217 | \$context['loop'] = array( |
||
218 | 'parent' => \$context['_parent'], |
||
219 | 'index0' => 0, |
||
220 | 'index' => 1, |
||
221 | 'first' => true, |
||
222 | ); |
||
223 | if (is_array(\$context["articles"]) || (is_object(\$context["articles"]) && \$context["articles"] instanceof Countable)) { |
||
224 | \$length = count(\$context["articles"]); |
||
225 | \$context['loop']['revindex0'] = \$length - 1; |
||
226 | \$context['loop']['revindex'] = \$length; |
||
227 | \$context['loop']['length'] = \$length; |
||
228 | \$context['loop']['totalLength'] = \$length; |
||
229 | \$context['loop']['last'] = 1 === \$length; |
||
230 | } |
||
231 | if(is_object(\$context["articles"]) && \$context["articles"] instanceof \SWP\Component\TemplatesSystem\Gimme\Meta\MetaCollection) { |
||
232 | \$context['loop']['totalLength'] = \$context["articles"]->getTotalItemsCount(); |
||
233 | } |
||
234 | foreach (\$context["articles"] as \$_key => \$context["article"]) { |
||
235 | // line 1 |
||
236 | echo ""; |
||
237 | ++\$context['loop']['index0']; |
||
238 | ++\$context['loop']['index']; |
||
239 | \$context['loop']['first'] = false; |
||
240 | if (isset(\$context['loop']['length'])) { |
||
241 | --\$context['loop']['revindex0']; |
||
242 | --\$context['loop']['revindex']; |
||
243 | \$context['loop']['last'] = 0 === \$context['loop']['revindex0']; |
||
244 | } |
||
245 | } |
||
246 | \$_parent = \$context['_parent']; |
||
247 | unset(\$context['article'], \$context['_iterated'], \$context['articles'], \$context['_parent'], \$context['loop']); |
||
248 | unset(\$context['_collection_type_filters']); |
||
249 | \$context = array_intersect_key(\$context, \$_parent) + \$_parent; |
||
250 | EOF |
||
251 | ], |
||
252 | [$node4, <<<EOF |
||
253 | \$context['_collection_type_filters'] = []; |
||
254 | \$context['articles'] = null; |
||
255 | \$context['_collection_type_filters'] = call_user_func_array(\$this->env->getFilter('start')->getCallable(), [call_user_func_array(\$this->env->getFilter('limit')->getCallable(), [call_user_func_array(\$this->env->getFilter('order')->getCallable(), [\$context["articles"], ["id" => "desc"]]), 10]), 0])['_collection_type_filters']; unset(\$context['articles']['_collection_type_filters']); |
||
256 | \$withParameters = array_merge([], \$context['_collection_type_filters']); |
||
257 | \$withoutParameters = []; |
||
258 | \$swpCollectionMetaLoader4 = \$this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader(); |
||
259 | \$context["articles"] = twig_ensure_traversable(\$swpCollectionMetaLoader4->load("articles", \$withParameters, \$withoutParameters, \SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface::COLLECTION)); |
||
260 | \$context['_parent'] = (array) \$context; |
||
261 | \$context['loop'] = array( |
||
262 | 'parent' => \$context['_parent'], |
||
263 | 'index0' => 0, |
||
264 | 'index' => 1, |
||
265 | 'first' => true, |
||
266 | ); |
||
267 | if (is_array(\$context["articles"]) || (is_object(\$context["articles"]) && \$context["articles"] instanceof Countable)) { |
||
268 | \$length = count(\$context["articles"]); |
||
269 | \$context['loop']['revindex0'] = \$length - 1; |
||
270 | \$context['loop']['revindex'] = \$length; |
||
271 | \$context['loop']['length'] = \$length; |
||
272 | \$context['loop']['totalLength'] = \$length; |
||
273 | \$context['loop']['last'] = 1 === \$length; |
||
274 | } |
||
275 | if(is_object(\$context["articles"]) && \$context["articles"] instanceof \SWP\Component\TemplatesSystem\Gimme\Meta\MetaCollection) { |
||
276 | \$context['loop']['totalLength'] = \$context["articles"]->getTotalItemsCount(); |
||
277 | } |
||
278 | foreach (\$context["articles"] as \$_key => \$context["article"]) { |
||
279 | // line 1 |
||
280 | echo ""; |
||
281 | ++\$context['loop']['index0']; |
||
282 | ++\$context['loop']['index']; |
||
283 | \$context['loop']['first'] = false; |
||
284 | if (isset(\$context['loop']['length'])) { |
||
285 | --\$context['loop']['revindex0']; |
||
286 | --\$context['loop']['revindex']; |
||
287 | \$context['loop']['last'] = 0 === \$context['loop']['revindex0']; |
||
288 | } |
||
289 | } |
||
290 | \$_parent = \$context['_parent']; |
||
291 | unset(\$context['article'], \$context['_iterated'], \$context['articles'], \$context['_parent'], \$context['loop']); |
||
292 | unset(\$context['_collection_type_filters']); |
||
293 | \$context = array_intersect_key(\$context, \$_parent) + \$_parent; |
||
294 | EOF |
||
295 | ], |
||
296 | [$node5, <<<EOF |
||
297 | \$context['_collection_type_filters'] = []; |
||
298 | \$context['articles'] = null; |
||
299 | \$context['_collection_type_filters'] = call_user_func_array(\$this->env->getFilter('start')->getCallable(), [call_user_func_array(\$this->env->getFilter('limit')->getCallable(), [call_user_func_array(\$this->env->getFilter('order')->getCallable(), [\$context["articles"], ["id" => "desc"]]), 10]), 0])['_collection_type_filters']; unset(\$context['articles']['_collection_type_filters']); |
||
300 | \$withParameters = array_merge([], \$context['_collection_type_filters']); |
||
301 | \$withoutParameters = []; |
||
302 | \$swpCollectionMetaLoader5 = \$this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader(); |
||
303 | \$context["articles"] = twig_ensure_traversable(\$swpCollectionMetaLoader5->load("articles", \$withParameters, \$withoutParameters, \SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface::COLLECTION)); |
||
304 | \$context['_parent'] = (array) \$context; |
||
305 | \$context['loop'] = array( |
||
306 | 'parent' => \$context['_parent'], |
||
307 | 'index0' => 0, |
||
308 | 'index' => 1, |
||
309 | 'first' => true, |
||
310 | ); |
||
311 | foreach (\$context["articles"] as \$_key => \$context["article"]) { |
||
312 | if ((twig_get_attribute(\$this->env, \$this->source, (\$context["article"] ?? null), "title", [], "", false, false, false, 0) == "New article")) { |
||
313 | // line 1 |
||
314 | echo ""; |
||
315 | ++\$context['loop']['index0']; |
||
316 | ++\$context['loop']['index']; |
||
317 | \$context['loop']['first'] = false; |
||
318 | } |
||
319 | } |
||
320 | \$_parent = \$context['_parent']; |
||
321 | unset(\$context['article'], \$context['_iterated'], \$context['articles'], \$context['_parent'], \$context['loop']); |
||
322 | unset(\$context['_collection_type_filters']); |
||
323 | \$context = array_intersect_key(\$context, \$_parent) + \$_parent; |
||
324 | EOF |
||
325 | ], |
||
326 | [$node6, <<<EOF |
||
327 | \$context['_collection_type_filters'] = []; |
||
328 | \$context['articles'] = null; |
||
329 | \$context['_collection_type_filters'] = call_user_func_array(\$this->env->getFilter('start')->getCallable(), [call_user_func_array(\$this->env->getFilter('limit')->getCallable(), [call_user_func_array(\$this->env->getFilter('order')->getCallable(), [\$context["articles"], ["id" => "desc"]]), 10]), 0])['_collection_type_filters']; unset(\$context['articles']['_collection_type_filters']); |
||
330 | \$withParameters = array_merge([], \$context['_collection_type_filters']); |
||
331 | \$withoutParameters = []; |
||
332 | \$swpCollectionMetaLoader6 = \$this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader(); |
||
333 | \$swpContext6GimmeList = \$this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getContext(); |
||
334 | \$swpIgnoreContext6GimmeList = \$swpContext6GimmeList->temporaryUnset([]); |
||
335 | \$context["articles"] = twig_ensure_traversable(\$swpCollectionMetaLoader6->load("articles", \$withParameters, \$withoutParameters, \SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface::COLLECTION)); |
||
336 | \$context['_parent'] = (array) \$context; |
||
337 | \$context['loop'] = array( |
||
338 | 'parent' => \$context['_parent'], |
||
339 | 'index0' => 0, |
||
340 | 'index' => 1, |
||
341 | 'first' => true, |
||
342 | ); |
||
343 | foreach (\$context["articles"] as \$_key => \$context["article"]) { |
||
344 | if ((twig_get_attribute(\$this->env, \$this->source, (\$context["article"] ?? null), "title", [], "", false, false, false, 0) == "New article")) { |
||
345 | // line 1 |
||
346 | echo ""; |
||
347 | ++\$context['loop']['index0']; |
||
348 | ++\$context['loop']['index']; |
||
349 | \$context['loop']['first'] = false; |
||
350 | } |
||
351 | } |
||
352 | \$swpContext6GimmeList->restoreTemporaryUnset(\$swpIgnoreContext6GimmeList); |
||
353 | \$_parent = \$context['_parent']; |
||
354 | unset(\$context['article'], \$context['_iterated'], \$context['articles'], \$context['_parent'], \$context['loop']); |
||
355 | unset(\$context['_collection_type_filters']); |
||
356 | \$context = array_intersect_key(\$context, \$_parent) + \$_parent; |
||
357 | EOF |
||
358 | ], |
||
359 | ]; |
||
360 | } |
||
361 | |||
373 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.