@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $value = $this->entity->wrap($this->relations, $value); |
97 | 97 | $this->dataSource->save($value); |
98 | 98 | $visibilityOverride->write($value); |
99 | - $this->entity->create((array_merge((array)$value, (array)$valueCopy)), $this->relations); |
|
99 | + $this->entity->create((array_merge((array)$value, (array)$valueCopy)), $this->relations); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | private function removeRelations($obj) { // Prevent saving ManyMany twice |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | |
108 | 108 | public function offsetExists($offset) { |
109 | 109 | if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
110 | - if (!empty($this->settings['filter'])) { |
|
111 | - $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
|
112 | - return isset($data[0]); |
|
113 | - } |
|
110 | + if (!empty($this->settings['filter'])) { |
|
111 | + $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
|
112 | + return isset($data[0]); |
|
113 | + } |
|
114 | 114 | return (bool) $this->dataSource->findById($offset); |
115 | 115 | } |
116 | 116 | |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | |
121 | 121 | public function offsetGet($offset) { |
122 | 122 | if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
123 | - if (!empty($this->settings['filter'])) { |
|
124 | - $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
|
125 | - return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations); |
|
126 | - } |
|
123 | + if (!empty($this->settings['filter'])) { |
|
124 | + $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
|
125 | + return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations); |
|
126 | + } |
|
127 | 127 | return $this->entity->create($this->dataSource->findById($offset), $this->relations); |
128 | 128 | } |
129 | 129 |
@@ -60,7 +60,9 @@ discard block |
||
60 | 60 | |
61 | 61 | $siblings = new \ArrayObject(); |
62 | 62 | |
63 | - foreach ($results as &$result) $result = $this->entity->create($result, $this->relations, $siblings); |
|
63 | + foreach ($results as &$result) { |
|
64 | + $result = $this->entity->create($result, $this->relations, $siblings); |
|
65 | + } |
|
64 | 66 | |
65 | 67 | return $results; |
66 | 68 | } |
@@ -77,13 +79,17 @@ discard block |
||
77 | 79 | private function processFilters($value) { |
78 | 80 | //When saving to a mapper with filters, write the filters back into the object being stored |
79 | 81 | foreach ($this->settings['filter'] as $key => $filterValue) { |
80 | - if (empty($value->$key) && !is_array($filterValue)) $value->$key = $filterValue; |
|
82 | + if (empty($value->$key) && !is_array($filterValue)) { |
|
83 | + $value->$key = $filterValue; |
|
84 | + } |
|
81 | 85 | } |
82 | 86 | return $value; |
83 | 87 | } |
84 | 88 | |
85 | 89 | public function offsetSet($offset, $valueObj) { |
86 | - if ($valueObj instanceof \Maphper\Relation) throw new \Exception(); |
|
90 | + if ($valueObj instanceof \Maphper\Relation) { |
|
91 | + throw new \Exception(); |
|
92 | + } |
|
87 | 93 | |
88 | 94 | //Extract private properties from the object |
89 | 95 | $visibilityOverride = new \Maphper\Lib\VisibilityOverride($valueObj); |
@@ -91,7 +97,9 @@ discard block |
||
91 | 97 | |
92 | 98 | $value = $this->processFilters($value); |
93 | 99 | $pk = $this->dataSource->getPrimaryKey(); |
94 | - if ($offset !== null) $value->{$pk[0]} = $offset; |
|
100 | + if ($offset !== null) { |
|
101 | + $value->{$pk[0]} = $offset; |
|
102 | + } |
|
95 | 103 | $valueCopy = $this->removeRelations(clone $value); |
96 | 104 | $value = $this->entity->wrap($this->relations, $value); |
97 | 105 | $this->dataSource->save($value); |
@@ -100,13 +108,16 @@ discard block |
||
100 | 108 | } |
101 | 109 | |
102 | 110 | private function removeRelations($obj) { // Prevent saving ManyMany twice |
103 | - foreach ($this->relations as $name => $relation) |
|
104 | - if ($relation instanceOf \Maphper\Relation\ManyMany && isset($obj->$name)) unset($obj->$name); |
|
111 | + foreach ($this->relations as $name => $relation) { |
|
112 | + if ($relation instanceOf \Maphper\Relation\ManyMany && isset($obj->$name)) unset($obj->$name); |
|
113 | + } |
|
105 | 114 | return $obj; |
106 | 115 | } |
107 | 116 | |
108 | 117 | public function offsetExists($offset) { |
109 | - if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
118 | + if (count($this->dataSource->getPrimaryKey()) > 1) { |
|
119 | + return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
120 | + } |
|
110 | 121 | if (!empty($this->settings['filter'])) { |
111 | 122 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
112 | 123 | return isset($data[0]); |
@@ -119,7 +130,9 @@ discard block |
||
119 | 130 | } |
120 | 131 | |
121 | 132 | public function offsetGet($offset) { |
122 | - if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
133 | + if (count($this->dataSource->getPrimaryKey()) > 1) { |
|
134 | + return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
135 | + } |
|
123 | 136 | if (!empty($this->settings['filter'])) { |
124 | 137 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
125 | 138 | return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations); |
@@ -130,11 +143,15 @@ discard block |
||
130 | 143 | public function __call($method, $args) { |
131 | 144 | if (array_key_exists($method, $this->settings)) { |
132 | 145 | $maphper = new Maphper($this->dataSource, $this->settings, $this->relations); |
133 | - if (is_array($maphper->settings[$method])) $maphper->settings[$method] = $args[0] + $maphper->settings[$method]; |
|
134 | - else $maphper->settings[$method] = $args[0]; |
|
146 | + if (is_array($maphper->settings[$method])) { |
|
147 | + $maphper->settings[$method] = $args[0] + $maphper->settings[$method]; |
|
148 | + } else { |
|
149 | + $maphper->settings[$method] = $args[0]; |
|
150 | + } |
|
135 | 151 | return $maphper; |
152 | + } else { |
|
153 | + throw new \Exception('Method Maphper::' . $method . ' does not exist'); |
|
136 | 154 | } |
137 | - else throw new \Exception('Method Maphper::' . $method . ' does not exist'); |
|
138 | 155 | } |
139 | 156 | |
140 | 157 | public function findAggregate($function, $field, $group = null) { |
@@ -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); |
@@ -59,7 +65,9 @@ discard block |
||
59 | 65 | } |
60 | 66 | |
61 | 67 | foreach ($this->siblings as $sibling) { |
62 | - if (isset($cache[$sibling->parentObject->{$this->parentField}])) $sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
68 | + if (isset($cache[$sibling->parentObject->{$this->parentField}])) { |
|
69 | + $sibling->data = $cache[$sibling->parentObject->{$this->parentField}]; |
|
70 | + } |
|
63 | 71 | } |
64 | 72 | /* |
65 | 73 | foreach ($this->siblings as $sibling) { |
@@ -70,13 +78,18 @@ discard block |
||
70 | 78 | } |
71 | 79 | |
72 | 80 | public function __call($func, array $args = []) { |
73 | - if ($this->lazyLoad() == null) return ''; |
|
81 | + if ($this->lazyLoad() == null) { |
|
82 | + return ''; |
|
83 | + } |
|
74 | 84 | return call_user_func_array([$this->lazyLoad(), $func], $args); |
75 | 85 | } |
76 | 86 | |
77 | 87 | public function __get($name) { |
78 | - if ($this->lazyLoad()) return $this->lazyLoad()->$name; |
|
79 | - else return null; |
|
88 | + if ($this->lazyLoad()) { |
|
89 | + return $this->lazyLoad()->$name; |
|
90 | + } else { |
|
91 | + return null; |
|
92 | + } |
|
80 | 93 | } |
81 | 94 | |
82 | 95 | public function __isset($name) { |