Completed
Push — master ( 3bdcbf...1018d5 )
by Yann
02:07
created
src/Converters/HTML/GenericHTMLConverter.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 * 		'icon' => boolean determining if the icons must be displayed or not,
71 71
 	 * ]. The first two are mandatory.
72 72
 	 * 
73
-	 * @return DOMDocument $domDocument : The DOMDocument instance created with the HTML.
73
+	 * @return \DOMElement $domDocument : The DOMDocument instance created with the HTML.
74 74
 	 */
75 75
 	private function buildHTMLTreeFromNode(DOMDocument $document, Node $node, array $options) {
76 76
 		$domElementA = $this->buildElement($document, $options[HTML_CONVERTER_MAIN_TAG_KEY][0]);
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * @param DOMDocument $document : The current DOMDocument in creation with the HTML tree.
118 118
 	 * @param array $description : The array describing the tag to create.
119 119
 	 * 
120
-	 * @return DOMElement $domElement : The created DOMElement.
120
+	 * @return \DOMElement $domElement : The created DOMElement.
121 121
 	 */
122 122
 	private function buildElement(DOMDocument $document, array $description) {
123 123
 		$domElement = $document->createElement($description[HTML_CONVERTER_TAG_KEY]);
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,6 @@
 block discarded – undo
5 5
 use OpenMindParser\Converters\Model\AbstractConverter;
6 6
 use OpenMindParser\Models\Document;
7 7
 use OpenMindParser\Models\Node;
8
-use OpenMindParser\Parser;
9 8
 use \DOMDocument;
10 9
 
11 10
 /*A singleton to convert a document tree (object Document) in a HTML tree following few options.*/
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -97,8 +97,7 @@
 block discarded – undo
97 97
 			$domElementC = $this->buildElement($document, $options[HTML_CONVERTER_MAIN_TAG_KEY][2]);
98 98
 			$domElementC->appendChild($text);
99 99
 			$domElementB->appendChild($domElementC);
100
-		}
101
-		else {
100
+		} else {
102 101
 			$domElementB->appendChild($text);
103 102
 		}
104 103
 		
Please login to merge, or discard this patch.
Spacing   +7 added lines, -8 removed lines patch added patch discarded remove patch
@@ -131,19 +131,18 @@  discard block
 block discarded – undo
131 131
 			]);
132 132
 		$domElementB = $this->buildElement($document, $options[self::MAIN_TAG_KEY][1]);
133 133
 		
134
-		if(!empty($node->getIcon()) && $options[self::MAIN_ICON_KEY][self::DISPLAY_ICON_KEY]) {
134
+		if (!empty($node->getIcon()) && $options[self::MAIN_ICON_KEY][self::DISPLAY_ICON_KEY]) {
135 135
 			$icon = $node->getIcon();
136 136
 			$domElementImg = $document->createElement('img');
137 137
 			
138 138
 			$iconUri = $icon->getShortUri();
139
-			if(array_key_exists(self::PATH_ICON_KEY, $options[self::MAIN_ICON_KEY])) {
140
-				if(!is_callable($callback = $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::CALLBACK_PATH_ICON_KEY])) {
139
+			if (array_key_exists(self::PATH_ICON_KEY, $options[self::MAIN_ICON_KEY])) {
140
+				if (!is_callable($callback = $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::CALLBACK_PATH_ICON_KEY])) {
141 141
 					throw new InvalidArgumentException('The argument with the key "'.self::CALLBACK_PATH_ICON_KEY.'" (self::CALLBACK_PATH_ICON_KEY) must be a valid callback.');
142 142
 				}
143 143
 				
144 144
 				$callBackoptions = array_key_exists(self::OPTIONS_PATH_ICON_KEY, $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY]) ?
145
-					$options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::OPTIONS_PATH_ICON_KEY] :
146
-					null;
145
+					$options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::OPTIONS_PATH_ICON_KEY] : null;
147 146
 				
148 147
 				$iconUri = $callback($icon->getFullName(), $callBackoptions);
149 148
 			}
@@ -154,7 +153,7 @@  discard block
 block discarded – undo
154 153
 		}
155 154
 		
156 155
 		$text = $document->createTextNode($node->getText());
157
-		if(isset($options[self::MAIN_TAG_KEY][2])) {
156
+		if (isset($options[self::MAIN_TAG_KEY][2])) {
158 157
 			$domElementC = $this->buildElement($document, $options[self::MAIN_TAG_KEY][2]);
159 158
 			$domElementC->appendChild($text);
160 159
 			$domElementB->appendChild($domElementC);
@@ -165,7 +164,7 @@  discard block
 block discarded – undo
165 164
 		
166 165
 		$domElementA->appendChild($domElementB);
167 166
 		
168
-		foreach($node->getChildren() as $child) {
167
+		foreach ($node->getChildren() as $child) {
169 168
 			$domElementB->appendChild($this->buildHTMLTreeFromNode($document, $child, $options));
170 169
 		}
171 170
 		
@@ -182,7 +181,7 @@  discard block
 block discarded – undo
182 181
 	 */
183 182
 	private function buildElement(DOMDocument $document, array $description) {
184 183
 		$domElement = $document->createElement($description[self::TAG_KEY]);
185
-		foreach($description[self::ATTRIBUTES_KEY] as $name => $attribute) {
184
+		foreach ($description[self::ATTRIBUTES_KEY] as $name => $attribute) {
186 185
 			$domElement->setAttribute($name, $attribute);
187 186
 		}
188 187
 		
Please login to merge, or discard this patch.
src/Converters/Model/AbstractConverter.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,6 @@
 block discarded – undo
38 38
 	/**
39 39
 	 * Abstract class to actually perform the conversion from the Document instance passed in parameter.
40 40
 	 * 
41
-	 * @param mixed $data : The data to convert. Here : a string as the file path or the Document instance.
42 41
 	 * @param array $options : An array of options for the conversion.
43 42
 	 * 
44 43
 	 * @return mixed : The result of the conversion.
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,14 +20,14 @@
 block discarded – undo
20 20
 	 * @return mixed : The result of the conversion.
21 21
 	 */
22 22
 	public function convert($data, $options = []) {
23
-		if(!is_string($data) && !($data instanceof Document)) {
23
+		if (!is_string($data) && !($data instanceof Document)) {
24 24
 			throw new InvalidArgumentException('The $data variable must be of type "string" (the file path), or an instance of "Document".');
25 25
 		}
26
-		elseif(!is_array($options)) {
26
+		elseif (!is_array($options)) {
27 27
 			throw new InvalidArgumentException('The $options variable must be and array.');
28 28
 		}
29 29
 		
30
-		if(is_string($data)) {
30
+		if (is_string($data)) {
31 31
 			$parser = Parser::getInstance();
32 32
 			$data = $parser->buildDocumentTreeFromFilePath($data);	
33 33
 		}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,8 +22,7 @@
 block discarded – undo
22 22
 	public function convert($data, $options = []) {
23 23
 		if(!is_string($data) && !($data instanceof Document)) {
24 24
 			throw new InvalidArgumentException('The $data variable must be of type "string" (the file path), or an instance of "Document".');
25
-		}
26
-		elseif(!is_array($options)) {
25
+		} elseif(!is_array($options)) {
27 26
 			throw new InvalidArgumentException('The $options variable must be and array.');
28 27
 		}
29 28
 		
Please login to merge, or discard this patch.
src/Models/Node.php 4 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	/**
209 209
 	 * Return if the current node is folded or not.
210 210
 	 * 
211
-	 * @return Bool $folded
211
+	 * @return string $folded
212 212
 	 */
213 213
 	public function isFolded() {
214 214
 		return $this->folded;
@@ -307,7 +307,6 @@  discard block
 block discarded – undo
307 307
 	/**
308 308
 	 * Return the list of children of the current node.
309 309
 	 * 
310
-	 * @param NodeList $children : The list of children node.
311 310
 	 */
312 311
 	public function getChildren() {
313 312
 		return $this->children;
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,6 @@
 block discarded – undo
5 5
 use \DOMNode;
6 6
 use \DOMElement;
7 7
 use \DOMNamedNodeMap;
8
-use OpenMindParser\Exceptions\InvalidNodeNameException;
9 8
 
10 9
 /*Object that represent a Node as the tag element in the openMind file.*/
11 10
 class Node 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -357,23 +357,23 @@
 block discarded – undo
357 357
 	public function toArray() {
358 358
 		$array = [];
359 359
 		$sorter = function($value, $key) use(&$array) {
360
-			if($value instanceof NodeList) {
360
+			if ($value instanceof NodeList) {
361 361
 				$newValue = [];
362
-				foreach($value as $node) {
362
+				foreach ($value as $node) {
363 363
 					$newValue[] = $node->toArray();
364 364
 				}
365 365
 				$value = $newValue;
366 366
 			}
367
-			elseif($value instanceof Icon) {
367
+			elseif ($value instanceof Icon) {
368 368
 				$value = $value->getFilePath();
369 369
 			}
370
-			elseif($value instanceof DOMElement) {
370
+			elseif ($value instanceof DOMElement) {
371 371
 				return;
372 372
 			}
373 373
 			$array[$key] = $value;
374 374
 		};
375 375
 		
376
-		foreach(get_object_vars($this) as $key => $value) {
376
+		foreach (get_object_vars($this) as $key => $value) {
377 377
 			$sorter($value, $key);
378 378
 		}
379 379
 		
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -363,11 +363,9 @@
 block discarded – undo
363 363
 					$newValue[] = $node->toArray();
364 364
 				}
365 365
 				$value = $newValue;
366
-			}
367
-			elseif($value instanceof Icon) {
366
+			} elseif($value instanceof Icon) {
368 367
 				$value = $value->getFilePath();
369
-			}
370
-			elseif($value instanceof DOMElement) {
368
+			} elseif($value instanceof DOMElement) {
371 369
 				return;
372 370
 			}
373 371
 			$array[$key] = $value;
Please login to merge, or discard this patch.
src/Parser.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@
 block discarded – undo
118 118
 	/**
119 119
 	 * For each attribute whom the name is the keys of $availableAttributes, its value will be put in the matching attribute.
120 120
 	 * 
121
-	 * @param DOMNamedNodeMap $nodeAttributes : The list of attributes of the current node to fill the Node object.
121
+	 * @param DOMNamedNodeMap $nodeAtributes : The list of attributes of the current node to fill the Node object.
122 122
 	 * @param array $availableAttributes : One of the static array of this class to describe the list of known attributes.
123 123
 	 * @param Node $node : The Node object to fill in.
124 124
 	 */
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @return Document : The document instance with all its nodes instances.
63 63
 	 */
64 64
 	public function buildDocumentTreeFromFilePath($filePath) {
65
-		if(!file_exists($filePath)) {
65
+		if (!file_exists($filePath)) {
66 66
 			throw new InvalidArgumentException('The given path : "'.$filePath.'" is invalid.');
67 67
 		}
68 68
 		
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	private function fillNode(DOMElement $domNode) {
86 86
 		//The given node name must be self::NODE_NODENAME
87
-		if($domNode->nodeName !== self::NODE_NODENAME) {
87
+		if ($domNode->nodeName !== self::NODE_NODENAME) {
88 88
 			throw new InvalidNodeNameException('The node name must be "node". "'.$domNode->nodeName.'" given.');
89 89
 		}
90 90
 		
@@ -94,16 +94,16 @@  discard block
 block discarded – undo
94 94
 		
95 95
 		//Build the list of children nodes and fill font information.
96 96
 		$children = new NodeList();
97
-		foreach($domNode->childNodes as $childNode) {
98
-			if($childNode->nodeName === self::NODE_NODENAME) {
97
+		foreach ($domNode->childNodes as $childNode) {
98
+			if ($childNode->nodeName === self::NODE_NODENAME) {
99 99
 				$children->add($this->fillNode($childNode));
100 100
 			}
101
-			elseif($childNode->nodeName === self::FONT_NODENAME) {
101
+			elseif ($childNode->nodeName === self::FONT_NODENAME) {
102 102
 				$this->fillNodeAttributes($childNode->attributes, self::$fontAvailableAttributes, $node);
103 103
 			}
104
-			elseif($childNode->nodeName === self::ICON_NODENAME) {
105
-				foreach($childNode->attributes as $attribute) {
106
-					if(array_key_exists($attribute->nodeName, self::$iconAvailableAttributes)) {
104
+			elseif ($childNode->nodeName === self::ICON_NODENAME) {
105
+				foreach ($childNode->attributes as $attribute) {
106
+					if (array_key_exists($attribute->nodeName, self::$iconAvailableAttributes)) {
107 107
 						$node->setIcon(new Icon($attribute->nodeValue));
108 108
 					}
109 109
 				}
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 	 * @param array $availableAttributes : One of the static array of this class to describe the list of known attributes.
123 123
 	 * @param Node $node : The Node object to fill in.
124 124
 	 */
125
-	private function fillNodeAttributes (DOMNamedNodeMap $nodeAtributes, array $availableAttributes, Node $node) {
126
-		foreach($nodeAtributes as $attribute) {
127
-			if(array_key_exists($attribute->nodeName, $availableAttributes)) {
125
+	private function fillNodeAttributes(DOMNamedNodeMap $nodeAtributes, array $availableAttributes, Node $node) {
126
+		foreach ($nodeAtributes as $attribute) {
127
+			if (array_key_exists($attribute->nodeName, $availableAttributes)) {
128 128
 				call_user_func([
129 129
 						$node, 
130 130
 						sprintf('openMindParser\Models\Node::set%s', ucfirst($availableAttributes[$attribute->nodeName]))
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -97,11 +97,9 @@
 block discarded – undo
97 97
 		foreach($domNode->childNodes as $childNode) {
98 98
 			if($childNode->nodeName === self::NODE_NODENAME) {
99 99
 				$children->add($this->fillNode($childNode));
100
-			}
101
-			elseif($childNode->nodeName === self::FONT_NODENAME) {
100
+			} elseif($childNode->nodeName === self::FONT_NODENAME) {
102 101
 				$this->fillNodeAttributes($childNode->attributes, self::$fontAvailableAttributes, $node);
103
-			}
104
-			elseif($childNode->nodeName === self::ICON_NODENAME) {
102
+			} elseif($childNode->nodeName === self::ICON_NODENAME) {
105 103
 				foreach($childNode->attributes as $attribute) {
106 104
 					if(array_key_exists($attribute->nodeName, self::$iconAvailableAttributes)) {
107 105
 						$node->setIcon(new Icon($attribute->nodeValue));
Please login to merge, or discard this patch.
src/Models/NodeList.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@
 block discarded – undo
14 14
 	private $list;
15 15
 	
16 16
 	public function __construct(array $list = null) {
17
-		if(empty($list)) {
17
+		if (empty($list)) {
18 18
 			$list = [];
19 19
 		}
20 20
 		
21
-		foreach($list as $node) {
22
-			if(!($node instanceof Node)) {
21
+		foreach ($list as $node) {
22
+			if (!($node instanceof Node)) {
23 23
 				throw new InvalidArgumentException('The array must contain only Node objects. "'.get_class($node).'" given.');
24 24
 			}
25 25
 		}
Please login to merge, or discard this patch.
src/Models/Document.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -148,16 +148,16 @@
 block discarded – undo
148 148
 	public function toArray() {
149 149
 		$array = [];
150 150
 		$sorter = function($value, $key) use(&$array) {
151
-			if($value instanceof Node) {
151
+			if ($value instanceof Node) {
152 152
 				$value = $value->toArray();
153 153
 			}
154
-			elseif($value instanceof DOMDocument) {
154
+			elseif ($value instanceof DOMDocument) {
155 155
 				return;
156 156
 			}
157 157
 			$array[$key] = $value;
158 158
 		};
159 159
 		
160
-		foreach(get_object_vars($this) as $key => $value) {
160
+		foreach (get_object_vars($this) as $key => $value) {
161 161
 			$sorter($value, $key);
162 162
 		}
163 163
 		
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -150,8 +150,7 @@
 block discarded – undo
150 150
 		$sorter = function($value, $key) use(&$array) {
151 151
 			if($value instanceof Node) {
152 152
 				$value = $value->toArray();
153
-			}
154
-			elseif($value instanceof DOMDocument) {
153
+			} elseif($value instanceof DOMDocument) {
155 154
 				return;
156 155
 			}
157 156
 			$array[$key] = $value;
Please login to merge, or discard this patch.
src/Models/Icon.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @param String $extension : The extension of the icon file without the leading dot. If it is a builtin icon, then it is 'png'.
43 43
 	 */ 
44 44
 	public function __construct($name = null, $extension = null, $path = null, $shortUri = null, $size = null) {
45
-		if(!empty($name)) {
45
+		if (!empty($name)) {
46 46
 			$this->setIcon($name, $extension, $path, $shortUri, $size);
47 47
 		}
48 48
 	}
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$this->shortUri = $shortUri ?: '/img/'.$this->fullName;
65 65
 		$this->path = $path ?: realpath(__DIR__.'/../../img/'.$this->fullName);
66 66
 		
67
-		if(!file_exists($this->path)) {
67
+		if (!file_exists($this->path)) {
68 68
 			throw new UnexistentFileException('The file '.$this->path.' does not exist !');
69 69
 		}
70 70
 		
Please login to merge, or discard this patch.
usage/SampleGenericHTMLConverter.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,6 @@
 block discarded – undo
5 5
 use OpenMindParser\Converters\Model\AbstractConverter;
6 6
 use OpenMindParser\Models\Document;
7 7
 use OpenMindParser\Models\Node;
8
-use OpenMindParser\Parser;
9 8
 use \DOMDocument;
10 9
 
11 10
 /*A singleton to convert a document tree (object Document) in a HTML tree following few options.*/
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
 	GenericHTMLConverter::MAIN_ICON_KEY => [
19 19
 		GenericHTMLConverter::DISPLAY_ICON_KEY => true,
20 20
 		GenericHTMLConverter::PATH_ICON_KEY    => [
21
-			GenericHTMLConverter::CALLBACK_PATH_ICON_KEY => function($fullName, $options = null){return '/openMindParser/img/'.$fullName;},
21
+			GenericHTMLConverter::CALLBACK_PATH_ICON_KEY => function($fullName, $options = null) {return '/openMindParser/img/'.$fullName; },
22 22
 		],
23 23
 	],
24 24
 ]);
Please login to merge, or discard this patch.