Completed
Push — master ( dfc8a8...b88b69 )
by Yann
02:12
created

Node::isItalic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OpenMindParser\Models;
4
5
use \DOMNode;
6
use \DOMElement;
7
use \DOMNamedNodeMap;
8
use OpenMindParser\Exceptions\InvalidNodeNameException;
9
10
/*Object that represent a Node as the tag element in the openMind file.*/
11
class Node 
12
{
13
	/**
14
	 * @var String $id : The unique id of the node.
15
	 */
16
	private $id;
17
	/**
18
	 * @var String $color : The text color of the node.
19
	 */
20
	private $color;
21
	/**
22
	 * @var float $created : The timestamp of the creation date of the node.
23
	 */
24
	private $created;
25
	/**
26
	 * @var float $modified : The timestamp of the modified date of the node.
27
	 */
28
	private $modified;
29
	/**
30
	 * @var String $position : The relative position of the node.
31
	 */
32
	private $position;
33
	/**
34
	 * @var int $vshift : The vshift of the node.
35
	 */
36
	private $vshift;
37
	/**
38
	 * @var Bool $folded : Is the node folded or not.
39
	 */
40
	private $folded;
41
	/**
42
	 * @var String $text : The text of the node.
43
	 */
44
	private $text;
45
	/**
46
	 * @var Bool $bold : Is the text node in bold.
47
	 */
48
	private $bold;
49
	/**
50
	 * @var Bool $italic : Is the text node in italic.
51
	 */
52
	private $italic;
53
	/**
54
	 * @var String $fontName : The font name of the node.
55
	 */
56
	private $fontName;
57
	/**
58
	 * @var int $fontSize : The font size of the node.
59
	 */
60
	private $fontSize;
61
	/**
62
	 * @var Icon $icon : The icon of the node if there is one.
63
	 */
64
	private $icon;
65
	/**
66
	 * @var NodeList $children : The children of the node as a collection of Nodes.
67
	 */
68
	private $children;
69
	/**
70
	 * @var DOMElement $domNode : The DOMElement instance of the current Node.
71
	 */
72
	private $domNode;
73
	
74
	/**
75
	 * @param DOMElement $domNode : The DOMElement instance of the current Node.
76
	 * @param NodeList $children  : The children of the node as a collection of Nodes.
77
	 * @param Icon $icon          : The icon of the node if there is one.
78
	 * @param String $id          : The unique id of the node.
79
	 * @param String $color       : The text color of the node.
80
	 * @param float $created     : The timestamp of the creation date of the node.
81
	 * @param float $modified    : The timestamp of the modified date of the node.
82
	 * @param String $position    : The relative position of the node.
83
	 * @param int $vshift      : The vshift of the node.
84
	 * @param Bool $folded      : Is the node folded or not.
85
	 * @param String $text        : The text of the node.
86
	 * @param Bool $bold          : Is the text node in bold.
87
	 * @param Bool $italic        : Is the text node in italic.
88
	 * @param String $fontName    : The font name of the current Node.
89
	 * @param int $fontSize    : The font size of the node.
90
	 */
91
	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) {
92
		$this->id = $id;
93
		$this->color = $color;
94
		$this->created = $created;
95
		$this->modified = $modified;
96
		$this->position = $position;
97
		$this->vshift = $vshift;
98
		$this->folded = $folded ? true : false;
99
		$this->text = $text;
100
		$this->bold = $bold ? true : false;
101
		$this->italic = $italic ? true : false;
102
		$this->fontName = $fontName;
103
		$this->fontSize = $fontSize;
104
		$this->icon = $icon;
105
		$this->children = $children ?: new NodeList();
106
		$this->domNode = $domNode;
107
	}
108
	
109
	/**
110
	 * Return the Id of the current node.
111
	 * 
112
	 * @return String : The node id.
113
	 */
114
	public function getId() {
115
		return $this->id;
116
	}
117
	
118
	/**
119
	 * Set the Id of the current node.
120
	 * 
121
	 * @param String $id : The node id.
122
	 */
123
	public function setId($id) {
124
		$this->id = $id;
125
	}
126
	
127
	/**
128
	 * Return the color of the current node.
129
	 * 
130
	 * @return String : The node color value in hexadecimal.
131
	 */
132
	public function getColor() {
133
		return $this->color;
134
	}
135
	
136
	/**
137
	 * Set the color of the current node.
138
	 * 
139
	 * @param String $color : The node color value in hexadecimal.
140
	 */
141
	public function setColor($color) {
142
		$this->color = $color;
143
	}
144
	
145
	/**
146
	 * Return the created timestamp of the current node.
147
	 * 
148
	 * @return float : The node created timestamp.
149
	 */
150
	public function getCreated() {
151
		return $this->created;
152
	}
153
	
154
	/**
155
	 * Set the created timestamp of the current node.
156
	 * 
157
	 * @param float $created : The node created timestamp.
158
	 */
159
	public function setCreated($created) {
160
		$this->created = $created;
161
	}
162
	
163
	/**
164
	 * Return the modified timestamp of the current node.
165
	 * 
166
	 * @return float : The node modified timestamp.
167
	 */
168
	public function getModified() {
169
		return $this->modified;
170
	}
171
	
172
	/**
173
	 * Set the modified timestamp of the current node.
174
	 * 
175
	 * @param float $modified : The node modified timestamp.
176
	 */
177
	public function setModified($modified) {
178
		$this->modified = $modified;
179
	}
180
	
181
	/**
182
	 * Return the relative position the current node to the parent node.
183
	 * 
184
	 * @return String : The node relative position.
185
	 */
186
	public function getPosition() {
187
		return $this->position;
188
	}
189
	
190
	/**
191
	 * Set the relative position the current node to the parent node.
192
	 * 
193
	 * @param String $position : The node relative position.
194
	 */
195
	public function setPosition($position) {
196
		$this->position = $position;
197
	}
198
	
199
	/**
200
	 * Return the vshift value of the current node.
201
	 * 
202
	 * @return int : The node vshift value.
203
	 */
204
	public function getVshift() {
205
		return $this->vshift;
206
	}
207
	
208
	/**
209
	 * Set the vshift value of the current node.
210
	 * 
211
	 * @param int $vshift : The node vshift value.
212
	 */
213
	public function setVshift($vshift) {
214
		$this->vshift = $vshift;
215
	}
216
	
217
	/**
218
	 * Return if the current node is folded or not.
219
	 * 
220
	 * @return Bool $folded
221
	 */
222
	public function isFolded() {
223
		return $this->folded;
224
	}
225
	
226
	/**
227
	 * Set if the current node is folded or not.
228
	 * 
229
	 * @param Bool $folded
230
	 */
231
	public function setFolded($folded) {
232
		$this->folded = $folded ? true : false;
233
	}
234
	
235
	/**
236
	 * Return the text of the current node with html entities decoded.
237
	 * 
238
	 * @return String : The node text value.
239
	 */
240
	public function getText() {
241
		return html_entity_decode($this->text);
242
	}
243
	
244
	/**
245
	 * Return the text of the current node.
246
	 * 
247
	 * @return String : The node text value.
248
	 */
249
	public function getRawText() {
250
		return $this->text;
251
	}
252
	
253
	/**
254
	 * Set the text of the current node with html entities decoded.
255
	 * 
256
	 * @param String $text : The node text value in plain text not html encoded.
257
	 */
258
	public function setText($text) {
259
		$this->text = htmlentities($text);
260
	}
261
	
262
	/**
263
	 * Return the font name of the current node.
264
	 * 
265
	 * @return String : The node font name.
266
	 */
267
	public function getFontName() {
268
		return $this->fontName;
269
	}
270
	
271
	/**
272
	 * Set the font name of the current node.
273
	 * 
274
	 * @param String $fontName : The node font name.
275
	 */
276
	public function setFontName($fontName) {
277
		$this->fontName = $fontName;
278
	}
279
	
280
	/**
281
	 * Return if the text node is bold.
282
	 * 
283
	 * @return Bool : If the text is bold or not.
284
	 */
285
	public function isBold() {
286
		return $this->bold;
287
	}
288
	
289
	/**
290
	 * Set if the text node is bold.
291
	 * 
292
	 * @param Bool $bold : If the text must be bold or not.
293
	 */
294
	public function setBold($bold) {
295
		$this->bold = $bold ? true : false;
296
	}
297
	
298
	/**
299
	 * Return if the text node is italic.
300
	 * 
301
	 * @return Bool : If the text is italic or not.
302
	 */
303
	public function isItalic() {
304
		return $this->italic;
305
	}
306
	
307
	/**
308
	 * Set if the text node is italic.
309
	 * 
310
	 * @param Bool $italic : If the text must be italic or not.
311
	 */
312
	public function setItalic($italic) {
313
		$this->italic = $italic ? true : false;
314
	}
315
	
316
	/**
317
	 * Return the font size of the current node.
318
	 * 
319
	 * @return int : The node font size.
320
	 */
321
	public function getFontSize() {
322
		return $this->fontSize;
323
	}
324
	
325
	/**
326
	 * Set the font size of the current node.
327
	 * 
328
	 * @param int $fontSize : The node font size.
329
	 */
330
	public function setFontSize($fontSize) {
331
		$this->fontSize = $fontSize;
332
	}
333
	
334
	/**
335
	 * Return the icon of the current node if there is one.
336
	 * 
337
	 * @return Icon : The icon.
338
	 */
339
	public function getIcon() {
340
		return $this->icon;
341
	}
342
	
343
	/**
344
	 * Set the icon of the current node.
345
	 * 
346
	 * @param Icon $icon : The node icon.
347
	 */
348
	public function setIcon(Icon $icon) {
349
		$this->icon = $icon;
350
	}
351
	
352
	/**
353
	 * Return the list of children of the current node.
354
	 * 
355
	 * @param NodeList $children : The list of children node.
0 ignored issues
show
Bug introduced by
There is no parameter named $children. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
356
	 */
357
	public function getChildren() {
358
		return $this->children;
359
	}
360
	
361
	/**
362
	 * Set the list of children of the current node.
363
	 * 
364
	 * @param NodeList $children : The list of children node.
365
	 */
366
	public function setChildren(NodeList $children) {
367
		$this->children = $children;
368
	}
369
	
370
	/**
371
	 * Return the DOMElement instance of the cirrent Node.
372
	 * 
373
	 * @return DOMElement : DOMElement instance.
374
	 */
375
	public function getDomNode() {
376
		return $this->domNode;
377
	}
378
	
379
	/**
380
	 * Set the current DOMElement instance.
381
	 * 
382
	 * @param DOMElement $domNode : The DOMElement instance.
383
	 */
384
	public function setDomNode(DOMElement $domNode) {
385
		$this->domNode = $domNode;
386
	}
387
	
388
	/**
389
	 * To String method.
390
	 * 
391
	 * @return String : The text content of the node.
392
	 */
393
	public function __toString() {
394
		return $this->getText();
395
	}
396
	
397
	/**
398
	 * Transform the objects tree in an array tree.
399
	 * 
400
	 * @return Array $array : The array tree.
401
	 */
402
	public function toArray() {
403
		$array = [];
404
		$sorter = function($value, $key) use(&$array) {
405
			if($value instanceof NodeList) {
406
				$newValue = [];
407
				foreach($value as $node) {
408
					$newValue[] = $node->toArray();
409
				}
410
				$value = $newValue;
411
			}
412
			elseif($value instanceof Icon) {
413
				$value = $value->toArray();
414
			}
415
			elseif($value instanceof DOMElement) {
416
				return;
417
			}
418
			$array[$key] = $value;
419
		};
420
		
421
		foreach(get_object_vars($this) as $key => $value) {
422
			$sorter($value, $key);
423
		}
424
		
425
		return $array;
426
	}
427
}