Completed
Push — master ( a1ee40...42cbd3 )
by Yann
01:55
created
src/Converters/Model/AbstractConverter.php 2 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
@@ -19,13 +19,13 @@
 block discarded – undo
19 19
 	 * @return mixed : The result of the conversion.
20 20
 	 */
21 21
 	public function convert($data, $options = []) {
22
-		if(!is_string($data) && !($data instanceof Document)) {
22
+		if (!is_string($data) && !($data instanceof Document)) {
23 23
 			throw new InvalidArgumentException('The $data variable must be of type "string" (the file path), or an instance of "Document".');
24
-		} elseif(!is_array($options)) {
24
+		} elseif (!is_array($options)) {
25 25
 			throw new InvalidArgumentException('The $options variable must be and array.');
26 26
 		}
27 27
 		
28
-		if(is_string($data)) {
28
+		if (is_string($data)) {
29 29
 			$parser = new Parser();
30 30
 			$data = $parser->buildDocumentTreeFromFilePath($data);	
31 31
 		}
Please login to merge, or discard this patch.
src/Models/Node.php 2 patches
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/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/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.
src/Models/Document.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -148,15 +148,15 @@
 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
-			} elseif($value instanceof DOMDocument) {
153
+			} elseif ($value instanceof DOMDocument) {
154 154
 				return;
155 155
 			}
156 156
 			$array[$key] = $value;
157 157
 		};
158 158
 		
159
-		foreach(get_object_vars($this) as $key => $value) {
159
+		foreach (get_object_vars($this) as $key => $value) {
160 160
 			$sorter($value, $key);
161 161
 		}
162 162
 		
Please login to merge, or discard this patch.
src/Parser.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 * @return Document : The document instance with all its nodes instances.
64 64
 	 */
65 65
 	public function buildDocumentTreeFromFilePath($filePath) {
66
-		if(!file_exists($filePath)) {
66
+		if (!file_exists($filePath)) {
67 67
 			throw new InvalidArgumentException('The given path : "'.$filePath.'" is invalid.');
68 68
 		}
69 69
 		
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	private function fillNode(DOMElement $domNode) {
87 87
 		//The given node name must be self::NODE_NODENAME
88
-		if($domNode->nodeName !== self::NODE_NODENAME) {
88
+		if ($domNode->nodeName !== self::NODE_NODENAME) {
89 89
 			throw new InvalidNodeNameException('The node name must be "node". "'.$domNode->nodeName.'" given.');
90 90
 		}
91 91
 		
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 		
96 96
 		//Build the list of children nodes and fill font information.
97 97
 		$children = new NodeList();
98
-		foreach($domNode->childNodes as $childNode) {
99
-			if($childNode->nodeName === self::NODE_NODENAME) {
98
+		foreach ($domNode->childNodes as $childNode) {
99
+			if ($childNode->nodeName === self::NODE_NODENAME) {
100 100
 				$children->add($this->fillNode($childNode));
101
-			} elseif($childNode->nodeName === self::FONT_NODENAME) {
101
+			} elseif ($childNode->nodeName === self::FONT_NODENAME) {
102 102
 				$this->fillNodeAttributes($childNode->attributes, self::$fontAvailableAttributes, $node);
103
-			} elseif($childNode->nodeName === self::ICON_NODENAME) {
104
-				foreach($childNode->attributes as $attribute) {
105
-					if(array_key_exists($attribute->nodeName, self::$iconAvailableAttributes)) {
103
+			} elseif ($childNode->nodeName === self::ICON_NODENAME) {
104
+				foreach ($childNode->attributes as $attribute) {
105
+					if (array_key_exists($attribute->nodeName, self::$iconAvailableAttributes)) {
106 106
 						$node->setIcon(new Icon($attribute->nodeValue));
107 107
 					}
108 108
 				}
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 	 * @param array $availableAttributes : One of the static array of this class to describe the list of known attributes.
122 122
 	 * @param Node $node : The Node object to fill in.
123 123
 	 */
124
-	private function fillNodeAttributes (DOMNamedNodeMap $nodeAtributes, array $availableAttributes, Node $node) {
125
-		foreach($nodeAtributes as $attribute) {
126
-			if(array_key_exists($attribute->nodeName, $availableAttributes)) {
124
+	private function fillNodeAttributes(DOMNamedNodeMap $nodeAtributes, array $availableAttributes, Node $node) {
125
+		foreach ($nodeAtributes as $attribute) {
126
+			if (array_key_exists($attribute->nodeName, $availableAttributes)) {
127 127
 				call_user_func([
128 128
 						$node, 
129 129
 						sprintf('openMindParser\Models\Node::set%s', ucfirst($availableAttributes[$attribute->nodeName]))
Please login to merge, or discard this patch.
src/Converters/HTML/GenericHTMLConverter.php 1 patch
Spacing   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 		$domElementA = $this->buildElement($document, $options[self::MAIN_TAG_KEY][0]);
139 139
 		
140 140
 		//Merge font size and font family to add inside the second wrapping DOMElement.
141
-		if($options[self::MAIN_TAG_MERGE_STYLE]) {
141
+		if ($options[self::MAIN_TAG_MERGE_STYLE]) {
142 142
 			$options[self::MAIN_TAG_KEY][1][self::ATTRIBUTES_KEY] = array_merge(
143 143
 				$options[self::MAIN_TAG_KEY][1][self::ATTRIBUTES_KEY], 
144 144
 				[
@@ -156,19 +156,18 @@  discard block
 block discarded – undo
156 156
 		$domElementB = $this->buildElement($document, $options[self::MAIN_TAG_KEY][1]);
157 157
 		
158 158
 		//Set the icon in an img tag whom will be wrapped in the second DOMElement.
159
-		if(!empty($node->getIcon()) && $options[self::MAIN_ICON_KEY][self::DISPLAY_ICON_KEY]) {
159
+		if (!empty($node->getIcon()) && $options[self::MAIN_ICON_KEY][self::DISPLAY_ICON_KEY]) {
160 160
 			$icon = $node->getIcon();
161 161
 			$domElementImg = $document->createElement('img');
162 162
 			
163 163
 			$iconUri = $icon->getShortUri();
164
-			if(array_key_exists(self::PATH_ICON_KEY, $options[self::MAIN_ICON_KEY])) {
165
-				if(!is_callable($callback = $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::CALLBACK_PATH_ICON_KEY])) {
164
+			if (array_key_exists(self::PATH_ICON_KEY, $options[self::MAIN_ICON_KEY])) {
165
+				if (!is_callable($callback = $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::CALLBACK_PATH_ICON_KEY])) {
166 166
 					throw new InvalidArgumentException('The argument with the key "'.self::CALLBACK_PATH_ICON_KEY.'" (self::CALLBACK_PATH_ICON_KEY) must be a valid callback.');
167 167
 				}
168 168
 				
169 169
 				$callBackoptions = array_key_exists(self::OPTIONS_PATH_ICON_KEY, $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY]) ?
170
-					$options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::OPTIONS_PATH_ICON_KEY] :
171
-					null;
170
+					$options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::OPTIONS_PATH_ICON_KEY] : null;
172 171
 				
173 172
 				$iconUri = $callback($icon->getFullName(), $callBackoptions);
174 173
 			}
@@ -182,13 +181,13 @@  discard block
 block discarded – undo
182 181
 		$text = $document->createTextNode($node->getText());
183 182
 		
184 183
 		//Bold an italic in old HTML way in order not to spread it to all children.
185
-		if($options[self::MAIN_TAG_MERGE_DECORATION]) {
186
-			if($node->isBold()) {
184
+		if ($options[self::MAIN_TAG_MERGE_DECORATION]) {
185
+			if ($node->isBold()) {
187 186
 				$bTag = $document->createElement('b');
188 187
 				$bTag->appendChild($text);
189 188
 				$text = $bTag;
190 189
 			}
191
-			if($node->isItalic()) {
190
+			if ($node->isItalic()) {
192 191
 				$iTag = $document->createElement('i');
193 192
 				$iTag->appendChild($text);
194 193
 				$text = $iTag;
@@ -196,7 +195,7 @@  discard block
 block discarded – undo
196 195
 		}
197 196
 		
198 197
 		//Append text node (real one or the one already wrapped inside <b> and/or <i> tags)
199
-		if(isset($options[self::MAIN_TAG_KEY][2])) {
198
+		if (isset($options[self::MAIN_TAG_KEY][2])) {
200 199
 			$domElementC = $this->buildElement($document, $options[self::MAIN_TAG_KEY][2]);
201 200
 			$domElementC->appendChild($text);
202 201
 			$domElementB->appendChild($domElementC);
@@ -206,7 +205,7 @@  discard block
 block discarded – undo
206 205
 		
207 206
 		$domElementA->appendChild($domElementB);
208 207
 		
209
-		foreach($node->getChildren() as $child) {
208
+		foreach ($node->getChildren() as $child) {
210 209
 			$domElementB->appendChild($this->buildHTMLTreeFromNode($document, $child, $options));
211 210
 		}
212 211
 		
@@ -219,8 +218,8 @@  discard block
 block discarded – undo
219 218
 	 * @param array &$options : The options array passed as reference.
220 219
 	 */
221 220
 	private function fillOptionalOptions(array &$options) {
222
-		foreach([self::MAIN_TAG_MERGE_DECORATION, self::MAIN_TAG_MERGE_STYLE] as $key) {
223
-			if(!array_key_exists($key, $options) || !is_bool($options[$key])) {
221
+		foreach ([self::MAIN_TAG_MERGE_DECORATION, self::MAIN_TAG_MERGE_STYLE] as $key) {
222
+			if (!array_key_exists($key, $options) || !is_bool($options[$key])) {
224 223
 				$options[$key] = true;
225 224
 			}
226 225
 		}
@@ -236,7 +235,7 @@  discard block
 block discarded – undo
236 235
 	 */
237 236
 	private function buildElement(DOMDocument $document, array $description) {
238 237
 		$domElement = $document->createElement($description[self::TAG_KEY]);
239
-		foreach($description[self::ATTRIBUTES_KEY] as $name => $attribute) {
238
+		foreach ($description[self::ATTRIBUTES_KEY] as $name => $attribute) {
240 239
 			$domElement->setAttribute($name, $attribute);
241 240
 		}
242 241
 		
Please login to merge, or discard this patch.