Pagination   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 31
c 1
b 1
f 0
dl 0
loc 51
rs 10
wmc 15

2 Methods

Rating   Name   Duplication   Size   Complexity  
F render() 0 43 14
A getMetadata() 0 4 1
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