@@ -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.*/ |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | ]); |
| 85 | 85 | $domElementB = $this->buildElement($document, $options[HTML_CONVERTER_MAIN_TAG_KEY][1]); |
| 86 | 86 | |
| 87 | - if(!empty($node->getIcon()) && $options[HTML_CONVERTER_MAIN_ICON_KEY]) { |
|
| 87 | + if (!empty($node->getIcon()) && $options[HTML_CONVERTER_MAIN_ICON_KEY]) { |
|
| 88 | 88 | $icon = $node->getIcon(); |
| 89 | 89 | $domElementImg = $document->createElement('img'); |
| 90 | 90 | $domElementImg->setAttribute('src', $icon->getFilePath()); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $text = $document->createTextNode($node->getText()); |
| 96 | - if(isset($options[HTML_CONVERTER_MAIN_TAG_KEY][2])) { |
|
| 96 | + if (isset($options[HTML_CONVERTER_MAIN_TAG_KEY][2])) { |
|
| 97 | 97 | $domElementC = $this->buildElement($document, $options[HTML_CONVERTER_MAIN_TAG_KEY][2]); |
| 98 | 98 | $domElementC->appendChild($text); |
| 99 | 99 | $domElementB->appendChild($domElementC); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $domElementA->appendChild($domElementB); |
| 106 | 106 | |
| 107 | - foreach($node->getChildren() as $child) { |
|
| 107 | + foreach ($node->getChildren() as $child) { |
|
| 108 | 108 | $domElementB->appendChild($this->buildHTMLTreeFromNode($document, $child, $options)); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | private function buildElement(DOMDocument $document, array $description) { |
| 123 | 123 | $domElement = $document->createElement($description[HTML_CONVERTER_TAG_KEY]); |
| 124 | - foreach($description[HTML_CONVERTER_ATTRIBUTES_KEY] as $name => $attribute) { |
|
| 124 | + foreach ($description[HTML_CONVERTER_ATTRIBUTES_KEY] as $name => $attribute) { |
|
| 125 | 125 | $domElement->setAttribute($name, $attribute); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -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 | |
@@ -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 | |
@@ -208,7 +208,7 @@ discard block |
||
| 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 |
||
| 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; |
@@ -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; |
@@ -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; |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @param String $extension : The extension of the icon file without the leading dot. If it is a builtin icon, then it is 'png'. |
| 39 | 39 | */ |
| 40 | 40 | public function __construct($name = null, $extension = null, $fullFilePath = null, $filePath = null, $size = null) { |
| 41 | - if(!empty($name)) { |
|
| 41 | + if (!empty($name)) { |
|
| 42 | 42 | $this->setIcon($name, $extension, $fullFilePath, $filePath, $size); |
| 43 | 43 | } |
| 44 | 44 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $this->fullFilePath = $fullFilePath ?: realpath(IMG_FULL_ROOT_DIR.$this->name.'.'.$this->extension); |
| 60 | 60 | $this->filePath = $filePath ?: IMG_ROOT_DIR.$this->name.'.'.$this->extension; |
| 61 | 61 | |
| 62 | - if(!file_exists($this->fullFilePath)) { |
|
| 62 | + if (!file_exists($this->fullFilePath)) { |
|
| 63 | 63 | throw new UnexistentFileException('The file '.$this->fullFilePath.' does not exist !'); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /*Bunch of protected magic methods that must not be called in a Singleton pattern.*/ |
| 27 | - protected function __construct(){} |
|
| 28 | - protected function __clone(){} |
|
| 29 | - protected function __wakeup(){} |
|
| 27 | + protected function __construct() {} |
|
| 28 | + protected function __clone() {} |
|
| 29 | + protected function __wakeup() {} |
|
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |