@@ -70,7 +70,7 @@ discard block |
||
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 |
||
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]); |
@@ -5,7 +5,6 @@ |
||
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.*/ |
@@ -97,8 +97,7 @@ |
||
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 |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | $domElementA = $this->buildElement($document, $options[self::MAIN_TAG_KEY][0]); |
137 | 137 | |
138 | 138 | //Merge font size and font family to add inside the second wrapping DOMElement. |
139 | - if(!array_key_exists(self::MAIN_TAG_MERGE_STYLE, $options) || !is_bool($options[self::MAIN_TAG_MERGE_STYLE])) { |
|
139 | + if (!array_key_exists(self::MAIN_TAG_MERGE_STYLE, $options) || !is_bool($options[self::MAIN_TAG_MERGE_STYLE])) { |
|
140 | 140 | $options[self::MAIN_TAG_MERGE_STYLE] = true; |
141 | 141 | } |
142 | - if($options[self::MAIN_TAG_MERGE_STYLE]) { |
|
142 | + if ($options[self::MAIN_TAG_MERGE_STYLE]) { |
|
143 | 143 | $options[self::MAIN_TAG_KEY][1][self::ATTRIBUTES_KEY] = array_merge( |
144 | 144 | $options[self::MAIN_TAG_KEY][1][self::ATTRIBUTES_KEY], |
145 | 145 | [ |
@@ -149,24 +149,23 @@ discard block |
||
149 | 149 | ] |
150 | 150 | ); |
151 | 151 | } |
152 | - $options[self::MAIN_TAG_KEY][1][self::ATTRIBUTES_KEY] = array_merge($options[self::MAIN_TAG_KEY][1][self::ATTRIBUTES_KEY], ['id' => $node->getId(),]); |
|
152 | + $options[self::MAIN_TAG_KEY][1][self::ATTRIBUTES_KEY] = array_merge($options[self::MAIN_TAG_KEY][1][self::ATTRIBUTES_KEY], ['id' => $node->getId(), ]); |
|
153 | 153 | //Create the second wrapping DOMElement whom will be append to the first one |
154 | 154 | $domElementB = $this->buildElement($document, $options[self::MAIN_TAG_KEY][1]); |
155 | 155 | |
156 | 156 | //Set the icon in an img tag whom will be wrapped in the second DOMElement. |
157 | - if(!empty($node->getIcon()) && $options[self::MAIN_ICON_KEY][self::DISPLAY_ICON_KEY]) { |
|
157 | + if (!empty($node->getIcon()) && $options[self::MAIN_ICON_KEY][self::DISPLAY_ICON_KEY]) { |
|
158 | 158 | $icon = $node->getIcon(); |
159 | 159 | $domElementImg = $document->createElement('img'); |
160 | 160 | |
161 | 161 | $iconUri = $icon->getShortUri(); |
162 | - if(array_key_exists(self::PATH_ICON_KEY, $options[self::MAIN_ICON_KEY])) { |
|
163 | - if(!is_callable($callback = $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::CALLBACK_PATH_ICON_KEY])) { |
|
162 | + if (array_key_exists(self::PATH_ICON_KEY, $options[self::MAIN_ICON_KEY])) { |
|
163 | + if (!is_callable($callback = $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::CALLBACK_PATH_ICON_KEY])) { |
|
164 | 164 | throw new InvalidArgumentException('The argument with the key "'.self::CALLBACK_PATH_ICON_KEY.'" (self::CALLBACK_PATH_ICON_KEY) must be a valid callback.'); |
165 | 165 | } |
166 | 166 | |
167 | 167 | $callBackoptions = array_key_exists(self::OPTIONS_PATH_ICON_KEY, $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY]) ? |
168 | - $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::OPTIONS_PATH_ICON_KEY] : |
|
169 | - null; |
|
168 | + $options[self::MAIN_ICON_KEY][self::PATH_ICON_KEY][self::OPTIONS_PATH_ICON_KEY] : null; |
|
170 | 169 | |
171 | 170 | $iconUri = $callback($icon->getFullName(), $callBackoptions); |
172 | 171 | } |
@@ -180,16 +179,16 @@ discard block |
||
180 | 179 | $text = $document->createTextNode($node->getText()); |
181 | 180 | |
182 | 181 | //Bold an italic in old HTML way in order not to spread it to all children. |
183 | - if(!array_key_exists(self::MAIN_TAG_MERGE_DECORATION, $options) || !is_bool($options[self::MAIN_TAG_MERGE_DECORATION])) { |
|
182 | + if (!array_key_exists(self::MAIN_TAG_MERGE_DECORATION, $options) || !is_bool($options[self::MAIN_TAG_MERGE_DECORATION])) { |
|
184 | 183 | $options[self::MAIN_TAG_MERGE_DECORATION] = true; |
185 | 184 | } |
186 | - if($options[self::MAIN_TAG_MERGE_DECORATION]) { |
|
187 | - if($node->isBold()) { |
|
185 | + if ($options[self::MAIN_TAG_MERGE_DECORATION]) { |
|
186 | + if ($node->isBold()) { |
|
188 | 187 | $bTag = $document->createElement('b'); |
189 | 188 | $bTag->appendChild($text); |
190 | 189 | $text = $bTag; |
191 | 190 | } |
192 | - if($node->isItalic()) { |
|
191 | + if ($node->isItalic()) { |
|
193 | 192 | $iTag = $document->createElement('i'); |
194 | 193 | $iTag->appendChild($text); |
195 | 194 | $text = $iTag; |
@@ -197,7 +196,7 @@ discard block |
||
197 | 196 | } |
198 | 197 | |
199 | 198 | //Append text node (real one or the one already wrapped inside <b> and/or <i> tags) |
200 | - if(isset($options[self::MAIN_TAG_KEY][2])) { |
|
199 | + if (isset($options[self::MAIN_TAG_KEY][2])) { |
|
201 | 200 | $domElementC = $this->buildElement($document, $options[self::MAIN_TAG_KEY][2]); |
202 | 201 | $domElementC->appendChild($text); |
203 | 202 | $domElementB->appendChild($domElementC); |
@@ -208,7 +207,7 @@ discard block |
||
208 | 207 | |
209 | 208 | $domElementA->appendChild($domElementB); |
210 | 209 | |
211 | - foreach($node->getChildren() as $child) { |
|
210 | + foreach ($node->getChildren() as $child) { |
|
212 | 211 | $domElementB->appendChild($this->buildHTMLTreeFromNode($document, $child, $options)); |
213 | 212 | } |
214 | 213 | |
@@ -225,7 +224,7 @@ discard block |
||
225 | 224 | */ |
226 | 225 | private function buildElement(DOMDocument $document, array $description) { |
227 | 226 | $domElement = $document->createElement($description[self::TAG_KEY]); |
228 | - foreach($description[self::ATTRIBUTES_KEY] as $name => $attribute) { |
|
227 | + foreach ($description[self::ATTRIBUTES_KEY] as $name => $attribute) { |
|
229 | 228 | $domElement->setAttribute($name, $attribute); |
230 | 229 | } |
231 | 230 |
@@ -38,7 +38,6 @@ |
||
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. |
@@ -20,14 +20,14 @@ |
||
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 | } |
@@ -22,8 +22,7 @@ |
||
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 |
@@ -5,7 +5,6 @@ |
||
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 |
@@ -357,23 +357,23 @@ |
||
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 |
@@ -363,11 +363,9 @@ |
||
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; |
@@ -352,7 +352,6 @@ |
||
352 | 352 | /** |
353 | 353 | * Return the list of children of the current node. |
354 | 354 | * |
355 | - * @param NodeList $children : The list of children node. |
|
356 | 355 | */ |
357 | 356 | public function getChildren() { |
358 | 357 | return $this->children; |
@@ -118,7 +118,7 @@ |
||
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 | */ |
@@ -62,7 +62,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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])) |
@@ -97,11 +97,9 @@ |
||
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)); |
@@ -14,12 +14,12 @@ |
||
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 | } |
@@ -148,16 +148,16 @@ |
||
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 |
@@ -150,8 +150,7 @@ |
||
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; |
@@ -42,7 +42,7 @@ discard block |
||
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 |
||
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 |
@@ -5,7 +5,6 @@ |
||
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.*/ |
@@ -18,7 +18,7 @@ |
||
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 | ]); |