Pagination::render()   C
last analyzed

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\Frontend\HTML\Element\Pagination as HTMLPagination;
8
use Formularium\HTMLNode;
9
use Formularium\Metadata;
10
11
class Pagination extends Element
12
{
13
    public function render(array $parameters, HTMLNode $previous): HTMLNode
14
    {
15
        foreach ($previous->get('.formularium-disabled') as $e) {
16
            $e->addAttribute('class', 'disabled');
17
        }
18
        foreach ($previous->get('.formularium-pagination-item') as $e) {
19
            $e->addAttribute('class', 'page-item');
20
        }
21
        foreach ($previous->get('.formularium-pagination-ellipsis') as $e) {
22
            $e->addAttribute('class', 'disabled');
23
        }
24
        foreach ($previous->get('.formularium-pagination-link') as $e) {
25
            $e->addAttribute('class', 'page-link');
26
        }
27
        foreach ($previous->get('.formularium-pagination-current') as $e) {
28
            $e->addAttribute('class', 'active');
29
        }
30
        foreach ($previous->get('.formularium-pagination') as $e) {
31
            $e->addAttribute('class', 'pagination');
32
        }
33
34
        $size = $parameters[self::SIZE] ?? '';
35
        switch ($size) {
36
            case self::SIZE_LARGE:
37
                foreach ($previous->get('.formularium-pagination') as $e) {
38
                    $e->addAttribute('class', 'pagination-lg');
39
                }
40
                break;
41
            case self::SIZE_SMALL:
42
                foreach ($previous->get('.formularium-pagination') as $e) {
43
                    $e->addAttribute('class', 'pagination-sm');
44
                }
45
                break;
46
        }
47
        return $previous;
48
    }
49
50
    public static function getMetadata(): Metadata
51
    {
52
        $metadata = HTMLPagination::getMetadata();
53
        return $metadata;
54
    }
55
}
56