Completed
Pull Request — master (#99)
by De Cramer
02:46
created

uiTextbox   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 148
Duplicated Lines 4.73 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 59.26%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 11
lcom 1
cbo 4
dl 7
loc 148
ccs 32
cts 54
cp 0.5926
rs 10
c 1
b 1
f 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
B render() 0 32 1
A getName() 0 4 1
A setName() 0 6 1
A getDefault() 0 4 1
A setDefault() 0 6 1
A getWidth() 0 4 1
A setWidth() 0 6 1
A prepare() 0 4 1
A getLines() 0 4 1
A setLines() 0 6 1

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
3
namespace eXpansion\Framework\Gui\Components;
4
5
use FML\Controls\Entry;
6
use FML\Controls\Frame;
7
use FML\Controls\Quad;
8
use FML\Controls\TextEdit;
9
use FML\Script\Script;
10
use FML\Types\Renderable;
11
12
class uiTextbox extends abstractUiElement implements Renderable
13
{
14
15
    /**
16
     * @var string
17
     */
18
    protected $name;
19
    /**
20
     * @var string
21
     */
22
    protected $default;
23
24
    /**
25
     * @var int
26
     */
27
    protected $lines;
28
29
30 1 View Code Duplication
    public function __construct($name, $default = "", $lines = 1, $width = 30)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
31
    {
32 1
        $this->name = $name;
33 1
        $this->default = $default;
34 1
        $this->lines = $lines;
35 1
        $this->setSize($width, ($lines * 5)+2);
36 1
    }
37
38
    /**
39
     * Render the XML element
40
     *
41
     * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered
42
     * @return \DOMElement
43
     */
44 1
    public function render(\DOMDocument $domDocument)
45
    {
46 1
        $frame = new Frame();
47 1
        $frame->setPosition($this->posX, $this->posY, $this->posZ)
48 1
            ->setSize($this->width, $this->height)
49 1
            ->addClasses(["uiContainer", "uiTextbox"]);
50
51 1
        $quad = new Quad();
52 1
        $quad->setSize(($this->width * 2), ($this->height * 2))
53 1
            ->setScale(0.5)
54 1
            ->setPosition(0, 0)
55 1
            ->setStyles('Bgs1', 'BgColorContour')
56 1
            ->setAlign("left", "top")
57 1
            ->setBackgroundColor('FFFA');
58
59 1
        $input = new TextEdit();
60 1
        $input->setSize($this->width, $this->height-2)
61 1
            ->setPosition(1, -1)
62 1
            ->setDefault($this->default)
63 1
            ->setScriptEvents(true)
64 1
            ->setAlign("left", "top")
65 1
            ->addClass("uiInput")
66 1
            ->setAreaColor("0000")
67 1
            ->setAreaFocusColor('0005')
68 1
            ->setTextFormat('Basic');
69 1
        $input->setId($this->name);
70
71 1
        $frame->addChild($quad);
72 1
        $frame->addChild($input);
73
74 1
        return $frame->render($domDocument);
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getName()
81
    {
82
        return $this->name;
83
    }
84
85
    /**
86
     * @param string $name
87
     */
88
    public function setName($name)
89
    {
90
        $this->name = $name;
91
92
        return $this;
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function getDefault()
99
    {
100
        return $this->default;
101
    }
102
103
    /**
104
     * @param string $default
105
     */
106
    public function setDefault($default)
107
    {
108
        $this->default = $default;
109
110
        return $this;
111
    }
112
113
    /**
114
     * @return float
115
     */
116
    public function getWidth()
117
    {
118
        return $this->width;
119
    }
120
121
    /**
122
     * @param float $width
123
     */
124
    public function setWidth($width)
125
    {
126
        $this->width = $width;
127
128
        return $this;
129
    }
130
131
    /**
132
     * Prepare the given Script for rendering by adding the needed Labels, etc.
133
     *
134
     * @param Script $script Script to prepare
135
     * @return static
136
     */
137
    public function prepare(Script $script)
138
    {
139
        // do nothing
140
    }
141
142
    /**
143
     * @return int
144
     */
145
    public function getLines()
146
    {
147
        return $this->lines;
148
    }
149
150
    /**
151
     * @param int $lines
152
     */
153
    public function setLines($lines)
154
    {
155
        $this->lines = $lines;
156
157
        return $this;
158
    }
159
}
160