Node::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 17
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 16
nc 16
nop 15

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace OpenMindParser\Models;
4
5
use \DOMNode;
6
use \DOMElement;
7
use \DOMNamedNodeMap;
8
9
/*Object that represent a Node as the tag element in the openMind file.*/
10
class Node 
11
{
12
	/**
13
	 * @var String $id : The unique id of the node.
14
	 */
15
	private $id;
16
	/**
17
	 * @var String $color : The text color of the node.
18
	 */
19
	private $color;
20
	/**
21
	 * @var String $created : The timestamp of the creation date of the node.
22
	 */
23
	private $created;
24
	/**
25
	 * @var String $modified : The timestamp of the modified date of the node.
26
	 */
27
	private $modified;
28
	/**
29
	 * @var String $position : The relative position of the node.
30
	 */
31
	private $position;
32
	/**
33
	 * @var int $vshift : The vshift of the node.
34
	 */
35
	private $vshift;
36
	/**
37
	 * @var Bool $folded : Is the node folded or not.
38
	 */
39
	private $folded;
40
	/**
41
	 * @var String $text : The text of the node.
42
	 */
43
	private $text;
44
	/**
45
	 * @var Bool $bold : Is the text node in bold.
46
	 */
47
	private $bold;
48
	/**
49
	 * @var Bool $italic : Is the text node in italic.
50
	 */
51
	private $italic;
52
	/**
53
	 * @var String $fontName : The font name of the node.
54
	 */
55
	private $fontName;
56
	/**
57
	 * @var int $fontSize : The font size of the node.
58
	 */
59
	private $fontSize;
60
	/**
61
	 * @var Icon $icon : The icon of the node if there is one.
62
	 */
63
	private $icon;
64
	/**
65
	 * @var NodeList $children : The children of the node as a collection of Nodes.
66
	 */
67
	private $children;
68
	/**
69
	 * @var DOMElement $domNode : The DOMElement instance of the current Node.
70
	 */
71
	private $domNode;
72
	
73
	/**
74
	 * @param DOMElement $domNode : The DOMElement instance of the current Node.
75
	 * @param NodeList $children  : The children of the node as a collection of Nodes.
76
	 * @param Icon $icon          : The icon of the node if there is one.
77
	 * @param String $id          : The unique id of the node.
78
	 * @param String $color       : The text color of the node.
79
	 * @param String $created     : The timestamp of the creation date of the node.
80
	 * @param String $modified    : The timestamp of the modified date of the node.
81
	 * @param String $position    : The relative position of the node.
82
	 * @param int $vshift      : The vshift of the node.
83
	 * @param Bool $folded      : Is the node folded or not.
84
	 * @param String $text        : The text of the node.
85
	 * @param Bool $bold          : Is the text node in bold.
86
	 * @param Bool $italic        : Is the text node in italic.
87
	 * @param String $fontName    : The font name of the current Node.
88
	 * @param int $fontSize    : The font size of the node.
89
	 */
90
	public function __construct(DOMElement $domNode = null, NodeList $children = null, Icon $icon = null, $id = null, $color = null, $created = null, $modified = null, $position = null, $vshift = null, $folded = null, $text = null, $bold = null, $italic = null, $fontName = null, $fontSize = null) {
91
		$this->id = $id;
92
		$this->color = $color;
93
		$this->created = (string) $created;
94
		$this->modified = (string) $modified;
95
		$this->position = $position;
96
		$this->vshift = $vshift;
97
		$this->folded = $folded ? true : false;
98
		$this->text = $text;
99
		$this->bold = $bold ? true : false;
100
		$this->italic = $italic ? true : false;
101
		$this->fontName = $fontName;
102
		$this->fontSize = $fontSize;
103
		$this->icon = $icon;
104
		$this->children = $children ?: new NodeList();
105
		$this->domNode = $domNode;
106
	}
107
	
108
	/**
109
	 * Return the Id of the current node.
110
	 * 
111
	 * @return String : The node id.
112
	 */
113
	public function getId() {
114
		return $this->id;
115
	}
116
	
117
	/**
118
	 * Set the Id of the current node.
119
	 * 
120
	 * @param String $id : The node id.
121
	 */
122
	public function setId($id) {
123
		$this->id = $id;
124
	}
125
	
126
	/**
127
	 * Return the color of the current node.
128
	 * 
129
	 * @return String : The node color value in hexadecimal.
130
	 */
131
	public function getColor() {
132
		return $this->color;
133
	}
134
	
135
	/**
136
	 * Set the color of the current node.
137
	 * 
138
	 * @param String $color : The node color value in hexadecimal.
139
	 */
140
	public function setColor($color) {
141
		$this->color = $color;
142
	}
143
	
144
	/**
145
	 * Return the created timestamp of the current node.
146
	 * 
147
	 * @return String : The node created timestamp.
148
	 */
149
	public function getCreated() {
150
		return $this->created;
151
	}
152
	
153
	/**
154
	 * Set the created timestamp of the current node.
155
	 * 
156
	 * @param String $created : The node created timestamp.
157
	 */
158
	public function setCreated($created) {
159
		$this->created = (string) $created;
160
	}
161
	
162
	/**
163
	 * Return the modified timestamp of the current node.
164
	 * 
165
	 * @return String : The node modified timestamp.
166
	 */
167
	public function getModified() {
168
		return $this->modified;
169
	}
170
	
171
	/**
172
	 * Set the modified timestamp of the current node.
173
	 * 
174
	 * @param String $modified : The node modified timestamp.
175
	 */
176
	public function setModified($modified) {
177
		$this->modified = (string) $modified;
178
	}
179
	
180
	/**
181
	 * Return the relative position the current node to the parent node.
182
	 * 
183
	 * @return String : The node relative position.
184
	 */
185
	public function getPosition() {
186
		return $this->position;
187
	}
188
	
189
	/**
190
	 * Set the relative position the current node to the parent node.
191
	 * 
192
	 * @param String $position : The node relative position.
193
	 */
194
	public function setPosition($position) {
195
		$this->position = $position;
196
	}
197
	
198
	/**
199
	 * Return the vshift value of the current node.
200
	 * 
201
	 * @return int : The node vshift value.
202
	 */
203
	public function getVshift() {
204
		return $this->vshift;
205
	}
206
	
207
	/**
208
	 * Set the vshift value of the current node.
209
	 * 
210
	 * @param int $vshift : The node vshift value.
211
	 */
212
	public function setVshift($vshift) {
213
		$this->vshift = $vshift;
214
	}
215
	
216
	/**
217
	 * Return if the current node is folded or not.
218
	 * 
219
	 * @return Bool $folded
220
	 */
221
	public function isFolded() {
222
		return $this->folded;
223
	}
224
	
225
	/**
226
	 * Set if the current node is folded or not.
227
	 * 
228
	 * @param Bool $folded
229
	 */
230
	public function setFolded($folded) {
231
		$this->folded = $folded ? true : false;
232
	}
233
	
234
	/**
235
	 * Return the text of the current node with html entities decoded.
236
	 * 
237
	 * @return String : The node text value.
238
	 */
239
	public function getText() {
240
		return html_entity_decode($this->text);
241
	}
242
	
243
	/**
244
	 * Return the text of the current node.
245
	 * 
246
	 * @return String : The node text value.
247
	 */
248
	public function getRawText() {
249
		return $this->text;
250
	}
251
	
252
	/**
253
	 * Set the text of the current node with html entities decoded.
254
	 * 
255
	 * @param String $text : The node text value in plain text not html encoded.
256
	 */
257
	public function setText($text) {
258
		$this->text = htmlentities($text);
259
	}
260
	
261
	/**
262
	 * Return the font name of the current node.
263
	 * 
264
	 * @return String : The node font name.
265
	 */
266
	public function getFontName() {
267
		return $this->fontName;
268
	}
269
	
270
	/**
271
	 * Set the font name of the current node.
272
	 * 
273
	 * @param String $fontName : The node font name.
274
	 */
275
	public function setFontName($fontName) {
276
		$this->fontName = $fontName;
277
	}
278
	
279
	/**
280
	 * Return if the text node is bold.
281
	 * 
282
	 * @return Bool : If the text is bold or not.
283
	 */
284
	public function isBold() {
285
		return $this->bold;
286
	}
287
	
288
	/**
289
	 * Set if the text node is bold.
290
	 * 
291
	 * @param Bool $bold : If the text must be bold or not.
292
	 */
293
	public function setBold($bold) {
294
		$this->bold = $bold ? true : false;
295
	}
296
	
297
	/**
298
	 * Return if the text node is italic.
299
	 * 
300
	 * @return Bool : If the text is italic or not.
301
	 */
302
	public function isItalic() {
303
		return $this->italic;
304
	}
305
	
306
	/**
307
	 * Set if the text node is italic.
308
	 * 
309
	 * @param Bool $italic : If the text must be italic or not.
310
	 */
311
	public function setItalic($italic) {
312
		$this->italic = $italic ? true : false;
313
	}
314
	
315
	/**
316
	 * Return the font size of the current node.
317
	 * 
318
	 * @return int : The node font size.
319
	 */
320
	public function getFontSize() {
321
		return $this->fontSize;
322
	}
323
	
324
	/**
325
	 * Set the font size of the current node.
326
	 * 
327
	 * @param int $fontSize : The node font size.
328
	 */
329
	public function setFontSize($fontSize) {
330
		$this->fontSize = $fontSize;
331
	}
332
	
333
	/**
334
	 * Return the icon of the current node if there is one.
335
	 * 
336
	 * @return Icon : The icon.
337
	 */
338
	public function getIcon() {
339
		return $this->icon;
340
	}
341
	
342
	/**
343
	 * Set the icon of the current node.
344
	 * 
345
	 * @param Icon $icon : The node icon.
346
	 */
347
	public function setIcon(Icon $icon) {
348
		$this->icon = $icon;
349
	}
350
	
351
	/**
352
	 * Return the list of children of the current node.
353
	 * 
354
	 */
355
	public function getChildren() {
356
		return $this->children;
357
	}
358
	
359
	/**
360
	 * Set the list of children of the current node.
361
	 * 
362
	 * @param NodeList $children : The list of children node.
363
	 */
364
	public function setChildren(NodeList $children) {
365
		$this->children = $children;
366
	}
367
	
368
	/**
369
	 * Return the DOMElement instance of the cirrent Node.
370
	 * 
371
	 * @return DOMElement : DOMElement instance.
372
	 */
373
	public function getDomNode() {
374
		return $this->domNode;
375
	}
376
	
377
	/**
378
	 * Set the current DOMElement instance.
379
	 * 
380
	 * @param DOMElement $domNode : The DOMElement instance.
381
	 */
382
	public function setDomNode(DOMElement $domNode) {
383
		$this->domNode = $domNode;
384
	}
385
	
386
	/**
387
	 * To String method.
388
	 * 
389
	 * @return String : The text content of the node.
390
	 */
391
	public function __toString() {
392
		return $this->getText();
393
	}
394
	
395
	/**
396
	 * Transform the objects tree in an array tree.
397
	 * 
398
	 * @return Array $array : The array tree.
399
	 */
400
	public function toArray() {
401
		$array = [];
402
		$sorter = function($value, $key) use(&$array) {
403
			if($value instanceof NodeList) {
404
				$newValue = [];
405
				foreach($value as $node) {
406
					$newValue[] = $node->toArray();
407
				}
408
				$value = $newValue;
409
			}
410
			elseif($value instanceof Icon) {
411
				$value = $value->toArray();
412
			}
413
			elseif($value instanceof DOMElement) {
414
				return;
415
			}
416
			$array[$key] = $value;
417
		};
418
		
419
		foreach(get_object_vars($this) as $key => $value) {
420
			$sorter($value, $key);
421
		}
422
		
423
		return $array;
424
	}
425
}