Passed
Push — master ( 06ae89...bb4653 )
by Bruno
08:26
created

Pagination::render()   C

Complexity

Conditions 11
Paths 192

Size

Total Lines 35
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 23
nc 192
nop 2
dl 0
loc 35
rs 6.55
c 0
b 0
f 0

How to fix   Complexity   

Long Method

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:

1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Bootstrap\Element;
4
5
use Formularium\Element;
6
use Formularium\Field;
7
use Formularium\HTMLNode;
8
9
class Pagination extends Element
10
{
11
    public function render(array $parameters, HTMLNode $previous): HTMLNode
12
    {
13
        foreach ($previous->get('.formularium-disabled') as $e) {
14
            $e->addAttribute('class', 'disabled');
15
        }
16
        foreach ($previous->get('.formularium-pagination-item') as $e) {
17
            $e->addAttribute('class', 'page-item');
18
        }
19
        foreach ($previous->get('.formularium-pagination-ellipsis') as $e) {
20
            $e->addAttribute('class', 'disabled');
21
        }
22
        foreach ($previous->get('.formularium-pagination-link') as $e) {
23
            $e->addAttribute('class', 'page-link');
24
        }
25
        foreach ($previous->get('.formularium-pagination-current') as $e) {
26
            $e->addAttribute('class', 'disabled');
27
        }
28
        foreach ($previous->get('.formularium-pagination') as $e) {
29
            $e->addAttribute('class', 'pagination');
30
        }
31
32
        $size = $parameters[self::SIZE] ?? '';
33
        switch ($size) {
34
            case self::SIZE_LARGE:
35
                foreach ($previous->get('.formularium-pagination') as $e) {
36
                    $e->addAttribute('class', 'pagination-lg');
37
                }
38
                break;
39
            case self::SIZE_SMALL:
40
                foreach ($previous->get('.formularium-pagination') as $e) {
41
                    $e->addAttribute('class', 'pagination-sm');
42
                }
43
                break;
44
        }
45
        return $previous;
46
    }
47
}
48