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

PagerFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 37.65 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 3
dl 32
loc 85
ccs 41
cts 41
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B create() 32 58 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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