Passed
Push — master ( fed342...00a718 )
by Bruno
09:40
created

Renderable_pagination::fix()   B

Complexity

Conditions 10
Paths 96

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 10
eloc 21
c 1
b 0
f 1
nc 96
nop 3
dl 0
loc 32
rs 7.6666

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\Renderable;
4
5
use Formularium\Field;
6
use Formularium\Renderable;
7
use Formularium\HTMLElement;
8
9
class Renderable_pagination extends Renderable_constant
10
{
11
    public function viewable($value, Field $field, HTMLElement $previous): HTMLElement
12
    {
13
        return $this->fix($value, $field, $previous);
14
    }
15
    
16
    public function editable($value, Field $field, HTMLElement $previous): HTMLElement
17
    {
18
        return $this->fix($value, $field, $previous);
19
    }
20
21
    protected function fix($value, Field $field, HTMLElement $previous): HTMLElement
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

21
    protected function fix(/** @scrutinizer ignore-unused */ $value, Field $field, HTMLElement $previous): HTMLElement

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    {
23
        foreach ($previous->get('.formularium-disabled') as $e) {
24
            $e->addAttribute('class', 'disabled');
25
        }
26
        foreach ($previous->get('.formularium-pagination-item') as $e) {
27
            $e->addAttribute('class', 'page-item');
28
        }
29
        foreach ($previous->get('.formularium-pagination-link') as $e) {
30
            $e->addAttribute('class', 'page-link');
31
        }
32
        foreach ($previous->get('.formularium-pagination-current') as $e) {
33
            $e->addAttribute('class', 'disabled');
34
        }
35
        foreach ($previous->get('.formularium-pagination') as $e) {
36
            $e->addAttribute('class', 'pagination');
37
        }
38
39
        $size = $field->getExtension(Renderable::SIZE, '');
40
        switch ($size) {
41
            case Renderable::SIZE_LARGE:
42
                foreach ($previous->get('.formularium-pagination') as $e) {
43
                    $e->addAttribute('class', 'pagination-lg');
44
                }
45
                break;
46
            case Renderable::SIZE_SMALL:
47
                foreach ($previous->get('.formularium-pagination') as $e) {
48
                    $e->addAttribute('class', 'pagination-sm');
49
                }
50
                break;
51
        }
52
        return $previous;
53
    }
54
}
55