Conditions | 32 |
Paths | 2880 |
Total Lines | 140 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
239 | public function render() |
||
240 | { |
||
241 | $output[] = $this->open(); |
||
242 | |||
243 | // Render header and image |
||
244 | if ($this->header->hasTextContent() || $this->header->hasChildNodes()) { |
||
245 | $output[] = $this->header; |
||
246 | if ($this->image instanceof Card\Image || |
||
247 | $this->image instanceof Card\Carousel |
||
248 | ) { |
||
249 | $this->image->attributes->removeAttributeClass('card-img-top'); |
||
250 | } |
||
251 | } elseif ($this->image instanceof Card\Image || |
||
252 | $this->image instanceof Card\Carousel |
||
253 | ) { |
||
254 | $this->image->attributes->addAttributeClass('card-img-top'); |
||
255 | } |
||
256 | |||
257 | // Render ribbons |
||
258 | if ($this->ribbons->count()) { |
||
259 | |||
260 | $ribbonsLeft = []; |
||
261 | $ribbonsRight = []; |
||
262 | |||
263 | foreach ($this->ribbons as $ribbon) { |
||
264 | if ($ribbon->position === Card\Ribbon::LEFT_RIBBON) { |
||
265 | $ribbonsLeft[] = $ribbon; |
||
266 | } elseif ($ribbon->position === Card\Ribbon::RIGHT_RIBBON) { |
||
267 | $ribbonsRight[] = $ribbon; |
||
268 | } |
||
269 | } |
||
270 | |||
271 | $ribbonContainer = new Element('div'); |
||
272 | $ribbonContainer->attributes->addAttributeClass('card-ribbon'); |
||
273 | |||
274 | if (count($ribbonsLeft)) { |
||
275 | $ribbonLeftContainer = new Element('div'); |
||
276 | $ribbonLeftContainer->attributes->addAttributeClass(['card-ribbon-container', 'left']); |
||
277 | |||
278 | foreach ($ribbonsLeft as $ribbonLeft) { |
||
279 | $ribbonLeftContainer->childNodes->push($ribbonLeft); |
||
280 | } |
||
281 | |||
282 | $ribbonContainer->childNodes->push($ribbonLeftContainer); |
||
283 | } |
||
284 | |||
285 | if (count($ribbonsRight)) { |
||
286 | $ribbonRightContainer = new Element('div'); |
||
287 | $ribbonRightContainer->attributes->addAttributeClass(['card-ribbon-container', 'right']); |
||
288 | |||
289 | foreach ($ribbonsRight as $ribbonRight) { |
||
290 | $ribbonRightContainer->childNodes->push($ribbonRight); |
||
291 | } |
||
292 | |||
293 | $ribbonContainer->childNodes->push($ribbonRightContainer); |
||
294 | } |
||
295 | |||
296 | $output[] = $ribbonContainer; |
||
297 | } |
||
298 | |||
299 | // Render images |
||
300 | if ($this->image instanceof Card\Image || |
||
301 | $this->image instanceof Card\Carousel |
||
302 | ) { |
||
303 | $output[] = $this->image; |
||
304 | } |
||
305 | |||
306 | // Render badges |
||
307 | if ($this->badges->count()) { |
||
308 | |||
309 | $badgesLeft = []; |
||
310 | $badgesRight = []; |
||
311 | $badgesInline = []; |
||
312 | |||
313 | foreach ($this->badges as $badge) { |
||
314 | if ($badge->position === Card\Badge::LEFT_BADGE) { |
||
315 | $badgesLeft[] = $badge; |
||
316 | } elseif ($badge->position === Card\Badge::RIGHT_BADGE) { |
||
317 | $badgesRight[] = $badge; |
||
318 | } elseif ($badge->position === Card\Badge::INLINE_BADGE) { |
||
319 | $badgesInline[] = $badge; |
||
320 | } |
||
321 | } |
||
322 | |||
323 | $badgeContainer = new Element('div'); |
||
324 | $badgeContainer->attributes->addAttributeClass('card-badge'); |
||
325 | |||
326 | if (count($badgesLeft)) { |
||
327 | $badgeLeftContainer = new Element('div'); |
||
328 | $badgeLeftContainer->attributes->addAttributeClass(['card-badge-container', 'left']); |
||
329 | |||
330 | foreach ($badgesLeft as $badgeLeft) { |
||
331 | $badgeLeftContainer->childNodes->push($badgeLeft); |
||
332 | } |
||
333 | |||
334 | $badgeContainer->childNodes->push($badgeLeftContainer); |
||
335 | } |
||
336 | |||
337 | if (count($badgesRight)) { |
||
338 | $badgeRightContainer = new Element('div'); |
||
339 | $badgeRightContainer->attributes->addAttributeClass(['card-badge-container', 'right']); |
||
340 | |||
341 | foreach ($badgesRight as $badgeRight) { |
||
342 | $badgeRightContainer->childNodes->push($badgeRight); |
||
343 | } |
||
344 | |||
345 | $badgeContainer->childNodes->push($badgeRightContainer); |
||
346 | } |
||
347 | |||
348 | if (count($badgesInline)) { |
||
349 | $badgeInlineContainer = new Element('div'); |
||
350 | $badgeInlineContainer->attributes->addAttributeClass(['card-badge-container', 'inline']); |
||
351 | |||
352 | foreach ($badgesInline as $badgeInline) { |
||
353 | $badgeInlineContainer->childNodes->push($badgeInline); |
||
354 | } |
||
355 | |||
356 | $badgeContainer->childNodes->push($badgeInlineContainer); |
||
357 | } |
||
358 | |||
359 | $output[] = $badgeContainer; |
||
360 | } |
||
361 | |||
362 | // Render body |
||
363 | if ($this->hasChildNodes()) { |
||
364 | $output[] = implode(PHP_EOL, $this->childNodes->getArrayCopy()); |
||
365 | } |
||
366 | |||
367 | if ($this->hasTextContent()) { |
||
368 | $output[] = implode(PHP_EOL, $this->textContent->getArrayCopy()); |
||
369 | } |
||
370 | |||
371 | // Render footer |
||
372 | if ($this->footer->hasTextContent() || $this->footer->hasChildNodes()) { |
||
373 | $output[] = $this->footer; |
||
374 | } |
||
375 | |||
376 | $output[] = $this->close(); |
||
377 | |||
378 | return implode(PHP_EOL, $output); |
||
379 | } |
||
380 | } |