@@ -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 | |
@@ -41,8 +45,10 @@ discard block |
||
| 41 | 45 | $recordsToLoad = []; |
| 42 | 46 | //Get a list of records by FK to eager load |
| 43 | 47 | foreach ($this->siblings as $sibling) { |
| 44 | - if ($sibling->parentField === $this->parentField) // Ensure that it is only loading records from the same type of relation |
|
| 48 | + if ($sibling->parentField === $this->parentField) { |
|
| 49 | + // Ensure that it is only loading records from the same type of relation |
|
| 45 | 50 | $recordsToLoad[] = $sibling->parentObject->{$sibling->parentField}; |
| 51 | + } |
|
| 46 | 52 | } |
| 47 | 53 | |
| 48 | 54 | $recordsToLoad = array_unique($recordsToLoad); |
@@ -60,7 +66,9 @@ discard block |
||
| 60 | 66 | |
| 61 | 67 | foreach ($this->siblings as $sibling) { |
| 62 | 68 | if ($sibling->parentField === $this->parentField && |
| 63 | - isset($cache[$sibling->parentObject->{$this->parentField}]))$sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
| 69 | + isset($cache[$sibling->parentObject->{$this->parentField}])) { |
|
| 70 | + $sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
| 71 | + } |
|
| 64 | 72 | } |
| 65 | 73 | /* |
| 66 | 74 | foreach ($this->siblings as $sibling) { |
@@ -71,13 +79,18 @@ discard block |
||
| 71 | 79 | } |
| 72 | 80 | |
| 73 | 81 | public function __call($func, array $args = []) { |
| 74 | - if ($this->lazyLoad() == null) return ''; |
|
| 82 | + if ($this->lazyLoad() == null) { |
|
| 83 | + return ''; |
|
| 84 | + } |
|
| 75 | 85 | return call_user_func_array([$this->lazyLoad(), $func], $args); |
| 76 | 86 | } |
| 77 | 87 | |
| 78 | 88 | public function __get($name) { |
| 79 | - if ($this->lazyLoad()) return $this->lazyLoad()->$name; |
|
| 80 | - else return null; |
|
| 89 | + if ($this->lazyLoad()) { |
|
| 90 | + return $this->lazyLoad()->$name; |
|
| 91 | + } else { |
|
| 92 | + return null; |
|
| 93 | + } |
|
| 81 | 94 | } |
| 82 | 95 | |
| 83 | 96 | public function __isset($name) { |