@@ -22,7 +22,9 @@ discard block |
||
22 | 22 | /** Binds data to an element */ |
23 | 23 | public function bind(\DomElement $element, $data) { |
24 | 24 | //This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem |
25 | - if (is_array($data) && count($data) === 1 && is_object($data[0])) $data = $data[0]; |
|
25 | + if (is_array($data) && count($data) === 1 && is_object($data[0])) { |
|
26 | + $data = $data[0]; |
|
27 | + } |
|
26 | 28 | $this->dataStorage[$element] = $data; |
27 | 29 | } |
28 | 30 | |
@@ -35,7 +37,9 @@ discard block |
||
35 | 37 | /** Returns the data that has been bound to $element, or, if no data is bound to $element climb the DOM tree to find the data bound to a parent node*/ |
36 | 38 | private function getData(\DomElement $element) { |
37 | 39 | while ($element) { |
38 | - if (isset($this->dataStorage[$element])) return $this->dataStorage[$element]; |
|
40 | + if (isset($this->dataStorage[$element])) { |
|
41 | + return $this->dataStorage[$element]; |
|
42 | + } |
|
39 | 43 | $element = $element->parentNode; |
40 | 44 | } |
41 | 45 | return $this->data; |
@@ -52,16 +56,24 @@ discard block |
||
52 | 56 | $parts = explode('.', $name[0]); |
53 | 57 | $obj = $data; |
54 | 58 | foreach ($parts as $part) { |
55 | - if ($part === '') continue; |
|
56 | - if (is_callable([$obj, $part])) $obj = call_user_func([$obj, $part]); |
|
57 | - else $obj = $this->ifNull($obj, $part); |
|
59 | + if ($part === '') { |
|
60 | + continue; |
|
61 | + } |
|
62 | + if (is_callable([$obj, $part])) { |
|
63 | + $obj = call_user_func([$obj, $part]); |
|
64 | + } else { |
|
65 | + $obj = $this->ifNull($obj, $part); |
|
66 | + } |
|
58 | 67 | } |
59 | 68 | return $obj; |
60 | 69 | } |
61 | 70 | |
62 | 71 | private function ifNull($obj, $key) { |
63 | - if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null; |
|
64 | - else return isset($obj->$key) ? $obj->$key : null; |
|
72 | + if (is_array($obj)) { |
|
73 | + return isset($obj[$key]) ? $obj[$key] : null; |
|
74 | + } else { |
|
75 | + return isset($obj->$key) ? $obj->$key : null; |
|
76 | + } |
|
65 | 77 | } |
66 | 78 | |
67 | 79 | public function attr($val, $element) { |
@@ -87,14 +99,18 @@ discard block |
||
87 | 99 | |
88 | 100 | $doc = $newTemplate->output([], true)->body; |
89 | 101 | |
90 | - if (isset($val[1])) return $this->templateSubsection($val[1], $doc, $element); |
|
102 | + if (isset($val[1])) { |
|
103 | + return $this->templateSubsection($val[1], $doc, $element); |
|
104 | + } |
|
91 | 105 | |
92 | 106 | $newNode = $element->ownerDocument->importNode($doc->documentElement, true); |
93 | 107 | |
94 | 108 | $result = []; |
95 | 109 | |
96 | 110 | if ($newNode->tagName === 'template') { |
97 | - foreach ($newNode->childNodes as $node) $result[] = $node->cloneNode(true); |
|
111 | + foreach ($newNode->childNodes as $node) { |
|
112 | + $result[] = $node->cloneNode(true); |
|
113 | + } |
|
98 | 114 | } |
99 | 115 | //else $result[] = $newNode; |
100 | 116 |