@@ -76,13 +76,17 @@ discard block |
||
| 76 | 76 | private function processFilters($value) { |
| 77 | 77 | //When saving to a mapper with filters, write the filters back into the object being stored |
| 78 | 78 | foreach ($this->settings['filter'] as $key => $filterValue) { |
| 79 | - if (empty($value->$key) && !is_array($filterValue)) $value->$key = $filterValue; |
|
| 79 | + if (empty($value->$key) && !is_array($filterValue)) { |
|
| 80 | + $value->$key = $filterValue; |
|
| 81 | + } |
|
| 80 | 82 | } |
| 81 | 83 | return $value; |
| 82 | 84 | } |
| 83 | 85 | |
| 84 | 86 | public function offsetSet($offset, $valueObj) { |
| 85 | - if ($valueObj instanceof \Maphper\Relation) throw new \Exception(); |
|
| 87 | + if ($valueObj instanceof \Maphper\Relation) { |
|
| 88 | + throw new \Exception(); |
|
| 89 | + } |
|
| 86 | 90 | |
| 87 | 91 | //Extract private properties from the object |
| 88 | 92 | $propertyReader = new \Maphper\Lib\VisibilityOverride(); |
@@ -90,7 +94,9 @@ discard block |
||
| 90 | 94 | |
| 91 | 95 | $value = $this->processFilters($value); |
| 92 | 96 | $pk = $this->dataSource->getPrimaryKey(); |
| 93 | - if ($offset !== null) $value->{$pk[0]} = $offset; |
|
| 97 | + if ($offset !== null) { |
|
| 98 | + $value->{$pk[0]} = $offset; |
|
| 99 | + } |
|
| 94 | 100 | $valueCopy = clone $value; |
| 95 | 101 | $value = $this->wrap($value); |
| 96 | 102 | $this->dataSource->save($value); |
@@ -99,7 +105,9 @@ discard block |
||
| 99 | 105 | } |
| 100 | 106 | |
| 101 | 107 | public function offsetExists($offset) { |
| 102 | - if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
| 108 | + if (count($this->dataSource->getPrimaryKey()) > 1) { |
|
| 109 | + return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
| 110 | + } |
|
| 103 | 111 | if (!empty($this->settings['filter'])) { |
| 104 | 112 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
| 105 | 113 | return isset($data[0]); |
@@ -112,7 +120,9 @@ discard block |
||
| 112 | 120 | } |
| 113 | 121 | |
| 114 | 122 | public function offsetGet($offset) { |
| 115 | - if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
| 123 | + if (count($this->dataSource->getPrimaryKey()) > 1) { |
|
| 124 | + return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
| 125 | + } |
|
| 116 | 126 | if (!empty($this->settings['filter'])) { |
| 117 | 127 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
| 118 | 128 | return $this->wrap($this->createNew(isset($data[0]) ? $data[0] : null)); |
@@ -121,7 +131,9 @@ discard block |
||
| 121 | 131 | } |
| 122 | 132 | |
| 123 | 133 | private function createNew($data = [], $obj = null) { |
| 124 | - if (!$obj) $obj = (is_callable($this->settings['resultClass'])) ? call_user_func($this->settings['resultClass']) : new $this->settings['resultClass']; |
|
| 134 | + if (!$obj) { |
|
| 135 | + $obj = (is_callable($this->settings['resultClass'])) ? call_user_func($this->settings['resultClass']) : new $this->settings['resultClass']; |
|
| 136 | + } |
|
| 125 | 137 | $writer = new Lib\PropertyWriter($obj); |
| 126 | 138 | if ($data != null) { |
| 127 | 139 | foreach ($data as $key => $value) { |
@@ -141,7 +153,9 @@ discard block |
||
| 141 | 153 | foreach ($this->relations as $name => $relation) { |
| 142 | 154 | if (isset($object->$name) && !($object->$name instanceof \Maphper\Relation) ) { |
| 143 | 155 | //After overwriting the relation, does the parent object ($object) need overwriting as well? |
| 144 | - if ($relation->overwrite($object, $object->$name)) $this[] = $object; |
|
| 156 | + if ($relation->overwrite($object, $object->$name)) { |
|
| 157 | + $this[] = $object; |
|
| 158 | + } |
|
| 145 | 159 | } |
| 146 | 160 | |
| 147 | 161 | $object->$name = $relation->getData($object, $siblings); |
@@ -153,11 +167,15 @@ discard block |
||
| 153 | 167 | public function __call($method, $args) { |
| 154 | 168 | if (array_key_exists($method, $this->settings)) { |
| 155 | 169 | $maphper = new Maphper($this->dataSource, $this->settings, $this->relations); |
| 156 | - if (is_array($maphper->settings[$method])) $maphper->settings[$method] = $args[0] + $maphper->settings[$method]; |
|
| 157 | - else $maphper->settings[$method] = $args[0]; |
|
| 170 | + if (is_array($maphper->settings[$method])) { |
|
| 171 | + $maphper->settings[$method] = $args[0] + $maphper->settings[$method]; |
|
| 172 | + } else { |
|
| 173 | + $maphper->settings[$method] = $args[0]; |
|
| 174 | + } |
|
| 158 | 175 | return $maphper; |
| 176 | + } else { |
|
| 177 | + throw new \Exception('Method Maphper::' . $method . ' does not exist'); |
|
| 159 | 178 | } |
| 160 | - else throw new \Exception('Method Maphper::' . $method . ' does not exist'); |
|
| 161 | 179 | } |
| 162 | 180 | |
| 163 | 181 | public function findAggregate($function, $field, $group = null) { |
@@ -5,8 +5,7 @@ |
||
| 5 | 5 | public function __construct($object) { |
| 6 | 6 | if ($object instanceof \stdclass) { |
| 7 | 7 | $this->closure = function ($field, $value) use ($object) { $object->$field = $value; }; |
| 8 | - } |
|
| 9 | - else { |
|
| 8 | + } else { |
|
| 10 | 9 | $this->closure = function ($field, $value) { $this->$field = $value; }; |
| 11 | 10 | $this->closure = $this->closure->bindTo($object, $object); |
| 12 | 11 | } |