Pagination::render()   F
last analyzed

Complexity

Conditions 14
Paths 576

Size

Total Lines 43
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 14
eloc 28
c 1
b 1
f 0
nc 576
nop 2
dl 0
loc 43
rs 2.6888

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\Bulma\Element;
4
5
use Formularium\Element;
6
use Formularium\HTMLNode;
7
use Formularium\Frontend\HTML\Element\Pagination as HTMLPagination;
8
use Formularium\Metadata;
9
use PHP_CodeSniffer\Generators\HTML;
10
11
class Pagination extends Element
12
{
13
    public function render(array $parameters, HTMLNode $previous): HTMLNode
14
    {
15
        foreach ($previous->get('.formularium-pagination-wrapper') as $e) {
16
            $e->addAttribute('class', 'pagination');
17
        }
18
        foreach ($previous->get('.formularium-disabled') as $e) {
19
            $e->addAttribute('class', 'disabled');
20
        }
21
        foreach ($previous->get('.formularium-ellipsis') as $e) {
22
            foreach ($e->getContent() as $e2) {
23
                $e2->setAttribute('class', 'pagination-ellipsis')
24
                    ->setTag('span');
25
            }
26
        }
27
        foreach ($previous->get('.formularium-pagination-link') as $e) {
28
            $e->addAttribute('class', 'pagination-link');
29
        }
30
        foreach ($previous->get('.formularium-pagination-current') as $e) {
31
            $e->addAttribute('class', 'is-current');
32
            foreach ($e->getContent() as $e2) {
33
                if ($e2 instanceof HTMLNode) {
34
                    $e2->addAttribute('class', 'is-current');
35
                }
36
            }
37
        }
38
        foreach ($previous->get('.formularium-pagination') as $e) {
39
            $e->addAttribute('class', 'pagination-list');
40
        }
41
42
        $size = $parameters[self::SIZE] ?? '';
43
        switch ($size) {
44
            case self::SIZE_LARGE:
45
                foreach ($previous->get('.formularium-pagination') as $e) {
46
                    $e->addAttribute('class', 'is-large');
47
                }
48
                break;
49
            case self::SIZE_SMALL:
50
                foreach ($previous->get('.formularium-pagination') as $e) {
51
                    $e->addAttribute('class', 'is-small');
52
                }
53
                break;
54
        }
55
        return $previous;
56
    }
57
58
    public static function getMetadata(): Metadata
59
    {
60
        $metadata = HTMLPagination::getMetadata();
61
        return $metadata;
62
    }
63
}
64