@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | private $siblings = []; |
10 | 10 | |
11 | 11 | public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $criteria = []) { |
12 | - if ($criteria) $mapper = $mapper->filter($this->criteira); |
|
12 | + if ($criteria) $mapper = $mapper->filter($this->criteira); |
|
13 | 13 | $this->mapper = $mapper; |
14 | 14 | $this->parentField = $parentField; |
15 | 15 | $this->localField = $localField; |
@@ -48,17 +48,17 @@ discard block |
||
48 | 48 | //Fetch the results so they're in the cache for the corresponding maphper object |
49 | 49 | $results = $this->mapper->filter([$this->localField => $recordsToLoad]); |
50 | 50 | |
51 | - $this->loadDataIntoSiblings($results); |
|
51 | + $this->loadDataIntoSiblings($results); |
|
52 | 52 | } |
53 | 53 | |
54 | - private function loadDataIntoSiblings($results) { |
|
55 | - $cache = []; |
|
54 | + private function loadDataIntoSiblings($results) { |
|
55 | + $cache = []; |
|
56 | 56 | foreach ($results as $result) { |
57 | 57 | $cache[$result->{$this->localField}] = $result; |
58 | 58 | } |
59 | 59 | |
60 | 60 | foreach ($this->siblings as $sibling) { |
61 | - if (isset($cache[$sibling->parentObject->{$this->parentField}])) $sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
61 | + if (isset($cache[$sibling->parentObject->{$this->parentField}])) $sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
62 | 62 | } |
63 | 63 | /* |
64 | 64 | foreach ($this->siblings as $sibling) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | else $sibling->data = $sibling->mapper->filter([$sibling->localField => $sibling->parentObject->{$this->parentField}])->item(0); |
67 | 67 | } |
68 | 68 | */ |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | 71 | public function __call($func, array $args = []) { |
72 | 72 | if ($this->lazyLoad() == null) return ''; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | public function __get($name) { |
77 | 77 | if ($this->lazyLoad()) return $this->lazyLoad()->$name; |
78 | - else return null; |
|
78 | + else return null; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | public function __isset($name) { |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | public function overwrite($parentObject, &$data) { |
86 | - $this->mapper[] = $data; |
|
86 | + $this->mapper[] = $data; |
|
87 | 87 | |
88 | - if (!isset($parentObject->{$this->parentField}) || $parentObject->{$this->parentField} != $data->{$this->localField}) { |
|
88 | + if (!isset($parentObject->{$this->parentField}) || $parentObject->{$this->parentField} != $data->{$this->localField}) { |
|
89 | 89 | $parentObject->{$this->parentField} = $data->{$this->localField}; |
90 | 90 | //Trigger an update of the parent object |
91 | 91 | return true; |
@@ -9,7 +9,9 @@ discard block |
||
9 | 9 | private $siblings = []; |
10 | 10 | |
11 | 11 | public function __construct(\Maphper\Maphper $mapper, $parentField, $localField, array $criteria = []) { |
12 | - if ($criteria) $mapper = $mapper->filter($this->criteira); |
|
12 | + if ($criteria) { |
|
13 | + $mapper = $mapper->filter($this->criteira); |
|
14 | + } |
|
13 | 15 | $this->mapper = $mapper; |
14 | 16 | $this->parentField = $parentField; |
15 | 17 | $this->localField = $localField; |
@@ -29,7 +31,9 @@ discard block |
||
29 | 31 | private function lazyLoad() { |
30 | 32 | if (!isset($this->data)) { |
31 | 33 | |
32 | - if ($this->parentObject == null) throw new \Exception('Error, no object set'); |
|
34 | + if ($this->parentObject == null) { |
|
35 | + throw new \Exception('Error, no object set'); |
|
36 | + } |
|
33 | 37 | |
34 | 38 | $this->eagerLoad(); |
35 | 39 | |
@@ -58,7 +62,9 @@ discard block |
||
58 | 62 | } |
59 | 63 | |
60 | 64 | foreach ($this->siblings as $sibling) { |
61 | - if (isset($cache[$sibling->parentObject->{$this->parentField}])) $sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
65 | + if (isset($cache[$sibling->parentObject->{$this->parentField}])) { |
|
66 | + $sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
67 | + } |
|
62 | 68 | } |
63 | 69 | /* |
64 | 70 | foreach ($this->siblings as $sibling) { |
@@ -69,13 +75,18 @@ discard block |
||
69 | 75 | } |
70 | 76 | |
71 | 77 | public function __call($func, array $args = []) { |
72 | - if ($this->lazyLoad() == null) return ''; |
|
78 | + if ($this->lazyLoad() == null) { |
|
79 | + return ''; |
|
80 | + } |
|
73 | 81 | return call_user_func_array([$this->lazyLoad(), $func], $args); |
74 | 82 | } |
75 | 83 | |
76 | 84 | public function __get($name) { |
77 | - if ($this->lazyLoad()) return $this->lazyLoad()->$name; |
|
78 | - else return null; |
|
85 | + if ($this->lazyLoad()) { |
|
86 | + return $this->lazyLoad()->$name; |
|
87 | + } else { |
|
88 | + return null; |
|
89 | + } |
|
79 | 90 | } |
80 | 91 | |
81 | 92 | public function __isset($name) { |