Completed
Push — dev ( 845ef5...8eacd8 )
by
unknown
02:50
created

PagerFactory::create()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 58
Code Lines 45

Duplication

Lines 32
Ratio 55.17 %

Code Coverage

Tests 38
CRAP Score 5

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 32
loc 58
ccs 38
cts 38
cp 1
rs 8.7274
cc 5
eloc 45
nc 16
nop 7
crap 5

How to fix   Long Method   

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
2
namespace eXpansion\Framework\Core\Model\Gui\Factory;
3
4
use FML\Controls\Control;
5
use FML\Controls\Frame;
6
use FML\Controls\Quads\Quad_Icons64x64_1;
7
8
/**
9
 * Class PagerFactory
10
 *
11
 * @package eXpansion\Framework\Core\Model\Gui\Factory;
12
 * @author  oliver de Cramer <[email protected]>
13
 */
14
class PagerFactory
15
{
16
    /** @var LabelFactory */
17
    protected $labelFactory;
18
19
    /**
20
     * PagerFactory constructor.
21
     *
22
     * @param LabelFactory $labelFactory
23
     */
24 6
    public function __construct(LabelFactory $labelFactory)
25
    {
26 6
        $this->labelFactory = $labelFactory;
27 6
    }
28
29
    /**
30
     * @param $width
31
     * @param $currentPageNumber
32
     * @param $lastPageNumber
33
     * @param $actionFirstPage
34
     * @param $actionPreviousPage
35
     * @param $actionNextPage
36
     * @param $actionLastPage
37
     *
38
     * @return Frame
39
     */
40 6
    public function create(
41
        $width,
42
        $currentPageNumber,
43
        $lastPageNumber,
44
        $actionFirstPage,
45
        $actionPreviousPage,
46
        $actionNextPage,
47
        $actionLastPage
48
    ) {
49 6
        $frame = new Frame();
50 6
        $frame->setSize($width, 7);
51
52 6
        $buttonSize = 7;
53
54
        // Show previous buttons
55 6 View Code Duplication
        if ($currentPageNumber > 2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56 2
            $button = Quad_Icons64x64_1::create();
57 2
            $button->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowFirst)
58 2
                ->setSize($buttonSize, $buttonSize)
59 2
                ->setPosition(1, 0)
60 2
                ->setAction($actionFirstPage);
61 2
            $frame->addChild($button);
62
        }
63 6 View Code Duplication
        if ($currentPageNumber > 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64 3
            $button = Quad_Icons64x64_1::create();
65 3
            $button->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev)
66 3
                ->setSize($buttonSize, $buttonSize)
67 3
                ->setPosition(2 + $buttonSize, 0)
68 3
                ->setAction($actionPreviousPage);
69 3
            $frame->addChild($button);
70
        }
71
72
        // Show current page.
73 6
        $label = $this->labelFactory->create("$currentPageNumber / $lastPageNumber");
74 6
        $label->setSize(10, 7);
75 6
        $label->setHorizontalAlign(Control::CENTER);
76 6
        $label->setPosition($frame->getWidth() / 2, 0);
77 6
        $frame->addChild($label);
78
79 6 View Code Duplication
        if ($currentPageNumber < $lastPageNumber) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80 4
            $button = Quad_Icons64x64_1::create();
81 4
            $button->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext)
82 4
                ->setSize($buttonSize, $buttonSize)
83 4
                ->setPosition($frame->getWidth() - 1 - (2 * $buttonSize), 0)
84 4
                ->setAction($actionNextPage);
85 4
            $frame->addChild($button);
86
        }
87 6 View Code Duplication
        if ($currentPageNumber < $lastPageNumber - 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88 4
            $button = Quad_Icons64x64_1::create();
89 4
            $button->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowLast)
90 4
                ->setSize($buttonSize, $buttonSize)
91 4
                ->setPosition($frame->getWidth() - 1 - $buttonSize, 0)
92 4
                ->setAction($actionLastPage);
93 4
            $frame->addChild($button);
94
        }
95
96 6
        return $frame;
97
    }
98
}
99