Code Duplication    Length = 164-169 lines in 2 locations

src/eXpansion/Framework/Gui/Layouts/layoutLine.php 1 location

@@ 12-175 (lines=164) @@
9
use FML\Types\Renderable;
10
use FML\Types\ScriptFeatureable;
11
12
class layoutLine implements Renderable, ScriptFeatureable
13
{
14
    private $frameClasses = [];
15
16
    /** @var float */
17
    private $width = 0.;
18
19
    /** @var float */
20
    private $height = 0.;
21
22
    /** @var Control[] */
23
    private $elements = [];
24
25
    /** @var float */
26
    private $margin = 2.;
27
    /**
28
     * @var float
29
     */
30
    private $startX = 0.;
31
    /**
32
     * @var float
33
     */
34
    private $startY = 0.;
35
36
    /**
37
     * layoutLine constructor.
38
     * @param float $startX
39
     * @param float $startY
40
     * @param object[] $elements
41
     * @param float $margin
42
     * @throws \Exception
43
     */
44
    public function __construct($startX, $startY, $elements = [], $margin = 0.)
45
    {
46
        if (!is_array($elements)) {
47
            throw new \Exception('not an array');
48
        }
49
        $this->margin = $margin;
50
        $this->elements = $elements;
51
        $this->startX = $startX;
52
        $this->startY = $startY;
53
        foreach ($this->elements as $idx => $element) {
54
            $this->width += $element->getWidth() + $this->margin;
55
            $this->height += $element->getHeight();
56
        }
57
58
    }
59
60
    /**
61
     * Render the XML element
62
     *
63
     * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered
64
     * @return \DOMElement
65
     */
66
    public function render(\DOMDocument $domDocument)
67
    {
68
        $frame = new Frame();
69
        $frame->setPosition($this->startX, $this->startY);
70
        $frame->addClasses($this->frameClasses);
71
72
        $startX = 0;
73
        foreach ($this->elements as $idx => $element) {
74
            $element->setX($startX);
75
            $startX += $element->getWidth() + $this->margin;
76
            $frame->addChild($element);
77
        }
78
79
        return $frame->render($domDocument);
80
    }
81
82
    /**
83
     * Get the Script Features
84
     *
85
     * @return ScriptFeature[]
86
     */
87
    public function getScriptFeatures()
88
    {
89
        $features = [];
90
        foreach ($this->elements as $element) {
91
            if ($element instanceof ScriptFeatureable) {
92
                $features[] = $element->getScriptFeatures();
93
            }
94
        }
95
96
        return ScriptFeature::collect($features);
97
    }
98
99
    /**
100
     * @param mixed $startX
101
     * @return layoutLine
102
     */
103
    public function setX($startX)
104
    {
105
        $this->startX = $startX;
106
107
        return $this;
108
    }
109
110
    /**
111
     * @param mixed $startY
112
     * @return layoutLine
113
     */
114
    public function setY($startY)
115
    {
116
        $this->startY = $startY;
117
118
        return $this;
119
    }
120
121
    /**
122
     * @return float
123
     */
124
    public function getX()
125
    {
126
        return $this->startX;
127
    }
128
129
    /**
130
     * @return mixed
131
     */
132
    public function getY()
133
    {
134
        return $this->startY;
135
    }
136
137
    /**
138
     * @return float
139
     */
140
    public function getWidth()
141
    {
142
        return $this->width;
143
    }
144
145
    /**
146
     * @param float $width
147
     */
148
    public function setWidth($width)
149
    {
150
        $this->width = $width;
151
    }
152
153
    /**
154
     * @return float
155
     */
156
    public function getHeight()
157
    {
158
        return $this->height;
159
    }
160
161
    /**
162
     * @param float $height
163
     */
164
    public function setHeight($height)
165
    {
166
        $this->height = $height;
167
    }
168
169
    /**
170
     * @param object $element
171
     */
172
    public function addChild($element)
173
    {
174
        $this->elements[] = $element;
175
        $this->width += $element->getWidth() + $this->margin;
176
        $this->height += $element->getHeight();
177
    }
178

src/eXpansion/Framework/Gui/Layouts/layoutRow.php 1 location

@@ 11-179 (lines=169) @@
8
use FML\Types\Renderable;
9
use FML\Types\ScriptFeatureable;
10
11
class layoutRow implements Renderable, ScriptFeatureable
12
{
13
    private $frameClasses = [];
14
    /**
15
     * @var float|int
16
     */
17
    private $height = 0;
18
    /**
19
     * @var float|int
20
     */
21
    private $width = 0;
22
23
    /** @var Control[] */
24
    private $elements = [];
25
26
    /**
27
     * @var float|int
28
     */
29
    private $margin = 1;
30
31
    /**
32
     * @var float|int
33
     */
34
    private $startX;
35
36
    /**
37
     * @var float|int
38
     */
39
    private $startY;
40
41
    /**
42
     * layoutLine constructor.
43
     * @param float $startX
44
     * @param float $startY
45
     * @param object[] $elements
46
     * @param int $margin
47
     * @throws \Exception
48
     */
49
    public function __construct($startX, $startY, $elements = [], $margin = 0)
50
    {
51
        if (!is_array($elements)) {
52
            throw new \Exception('not an array');
53
        }
54
55
        $this->margin = $margin;
56
        $this->elements = $elements;
57
        $this->startX = $startX;
58
        $this->startY = $startY;
59
60
        foreach ($this->elements as $idx => $element) {
61
            $this->width += $element->getWidth();
62
            $this->height += $element->getHeight() + $this->margin;
63
        }
64
    }
65
66
    /**
67
     * Render the XML element
68
     *
69
     * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered
70
     * @return \DOMElement
71
     */
72
    public function render(\DOMDocument $domDocument)
73
    {
74
        $frame = new Frame();
75
        $frame->setPosition($this->startX, $this->startY);
76
        $frame->addClasses($this->frameClasses);
77
78
        $startY = 0;
79
        foreach ($this->elements as $idx => $element) {
80
            $element->setY($startY);
81
            $startY -= $element->getHeight() + $this->margin;
82
            $frame->addChild($element);
83
        }
84
85
        return $frame->render($domDocument);
86
    }
87
88
    /**
89
     * Get the Script Features
90
     *
91
     * @return ScriptFeature[]
92
     */
93
    public function getScriptFeatures()
94
    {
95
        $features = [];
96
        foreach ($this->elements as $element) {
97
            if ($element instanceof ScriptFeatureable) {
98
                $features[] = $element->getScriptFeatures();
99
            }
100
        }
101
102
        return ScriptFeature::collect($features);
103
    }
104
105
    /**
106
     * @param mixed $startX
107
     * @return static
108
     */
109
    public function setX($startX)
110
    {
111
        $this->startX = $startX;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @param mixed $startY
118
     * @return static
119
     */
120
    public function setY($startY)
121
    {
122
        $this->startY = $startY;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @return mixed
129
     */
130
    public function getX()
131
    {
132
        return $this->startX;
133
    }
134
135
    /**
136
     * @return mixed
137
     */
138
    public function getY()
139
    {
140
        return $this->startY;
141
    }
142
143
    /**
144
     * @return float
145
     */
146
    public function getHeight()
147
    {
148
        return $this->height;
149
    }
150
151
    /**
152
     * @param float $height
153
     */
154
    public function setHeight($height)
155
    {
156
        $this->height = $height;
157
    }
158
159
    /**
160
     * @param float $width
161
     * @return layoutRow
162
     */
163
    public function setWidth($width)
164
    {
165
        $this->width = $width;
166
167
        return $this;
168
    }
169
170
    /**
171
     * @return float|int
172
     */
173
    public function getWidth()
174
    {
175
        return $this->width;
176
    }
177
178
    /**
179
     * @param object $element
180
     */
181
    public function addChild($element)
182
    {