@@ -14,8 +14,11 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function traverse($key) { |
17 | - if (isset($this->data->{$key})) $this->data = $this->data->{$key}; |
|
18 | - else if ($this->isArray() && isset($this->data[$key])) $this->data = $this->data[$key]; |
|
17 | + if (isset($this->data->{$key})) { |
|
18 | + $this->data = $this->data->{$key}; |
|
19 | + } else if ($this->isArray() && isset($this->data[$key])) { |
|
20 | + $this->data = $this->data[$key]; |
|
21 | + } |
|
19 | 22 | } |
20 | 23 | |
21 | 24 | private function isArray() { |
@@ -24,10 +27,14 @@ discard block |
||
24 | 27 | |
25 | 28 | public function read($value) { |
26 | 29 | if ($this->isArray()) { |
27 | - if (isset($this->data[$value])) return $this->data[$value]; |
|
30 | + if (isset($this->data[$value])) { |
|
31 | + return $this->data[$value]; |
|
32 | + } |
|
33 | + } else if (isset($this->data->$value)) { |
|
34 | + return $this->data->$value; |
|
35 | + } else { |
|
36 | + return false; |
|
28 | 37 | } |
29 | - else if (isset($this->data->$value)) return $this->data->$value; |
|
30 | - else return false; |
|
31 | 38 | } |
32 | 39 | |
33 | 40 | public function call($func, $args) { |
@@ -40,14 +47,20 @@ discard block |
||
40 | 47 | |
41 | 48 | public function parseNested($parser, $token, $funcName) { |
42 | 49 | $args = $parser->parseTokens($token['value'], $this->data); |
43 | - if ($args[0] == $this->data) $args = []; |
|
50 | + if ($args[0] == $this->data) { |
|
51 | + $args = []; |
|
52 | + } |
|
44 | 53 | return $this->callFuncOnObject($this->data, $funcName, $args); |
45 | 54 | } |
46 | 55 | |
47 | 56 | private function callFuncOnObject($obj, $func, $args) { |
48 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
49 | - else if (is_callable([$obj, $func])) return call_user_func_array([$obj, $func], $args); |
|
50 | - else return false; |
|
57 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
58 | + return call_user_func_array($obj->$func, $args); |
|
59 | + } else if (is_callable([$obj, $func])) { |
|
60 | + return call_user_func_array([$obj, $func], $args); |
|
61 | + } else { |
|
62 | + return false; |
|
63 | + } |
|
51 | 64 | } |
52 | 65 | |
53 | 66 | public function extract($last, $autoLookup, $traversing) { |
@@ -11,25 +11,33 @@ |
||
11 | 11 | private $lastParentNode; |
12 | 12 | |
13 | 13 | public function match($name, $args, \DomElement $element) { |
14 | - if ($element->parentNode !== $this->lastParentNode) $this->count = 0; |
|
14 | + if ($element->parentNode !== $this->lastParentNode) { |
|
15 | + $this->count = 0; |
|
16 | + } |
|
15 | 17 | |
16 | 18 | $this->lastParentNode = $element->parentNode; |
17 | 19 | |
18 | 20 | |
19 | 21 | |
20 | - if ($name !== 'nth-child') return true; |
|
22 | + if ($name !== 'nth-child') { |
|
23 | + return true; |
|
24 | + } |
|
21 | 25 | |
22 | 26 | $this->count++; |
23 | 27 | $criteria = $args[0]; |
24 | 28 | |
25 | - if (is_callable([$this, $criteria])) return $this->$criteria($this->count); |
|
29 | + if (is_callable([$this, $criteria])) { |
|
30 | + return $this->$criteria($this->count); |
|
31 | + } |
|
26 | 32 | $this->assert(is_numeric($criteria), "Argument passed to 'nth-child' must be 'odd', 'even', or of type int"); |
27 | 33 | return $this->count == $criteria; |
28 | 34 | } |
29 | 35 | |
30 | 36 | //TODO: Abstract assertions throughout |
31 | 37 | private function assert($condition, $error) { |
32 | - if (!$condition) throw new \Exception($error); |
|
38 | + if (!$condition) { |
|
39 | + throw new \Exception($error); |
|
40 | + } |
|
33 | 41 | } |
34 | 42 | |
35 | 43 | private function odd($num) { |