@@ -61,7 +61,9 @@ discard block |
||
61 | 61 | |
62 | 62 | $siblings = new \ArrayObject(); |
63 | 63 | |
64 | - foreach ($results as &$result) $result = $this->entity->create($result, $this->relations, $siblings); |
|
64 | + foreach ($results as &$result) { |
|
65 | + $result = $this->entity->create($result, $this->relations, $siblings); |
|
66 | + } |
|
65 | 67 | |
66 | 68 | return $results; |
67 | 69 | } |
@@ -78,13 +80,17 @@ discard block |
||
78 | 80 | private function processFilters($value) { |
79 | 81 | //When saving to a mapper with filters, write the filters back into the object being stored |
80 | 82 | foreach ($this->settings['filter'] as $key => $filterValue) { |
81 | - if (empty($value->$key) && !is_array($filterValue)) $value->$key = $filterValue; |
|
83 | + if (empty($value->$key) && !is_array($filterValue)) { |
|
84 | + $value->$key = $filterValue; |
|
85 | + } |
|
82 | 86 | } |
83 | 87 | return $value; |
84 | 88 | } |
85 | 89 | |
86 | 90 | public function offsetSet($offset, $valueObj) { |
87 | - if ($valueObj instanceof \Maphper\Relation) throw new \Exception(); |
|
91 | + if ($valueObj instanceof \Maphper\Relation) { |
|
92 | + throw new \Exception(); |
|
93 | + } |
|
88 | 94 | |
89 | 95 | //Extract private properties from the object |
90 | 96 | $visibilityOverride = new \Maphper\Lib\VisibilityOverride($valueObj); |
@@ -92,7 +98,9 @@ discard block |
||
92 | 98 | |
93 | 99 | $value = $this->processFilters($value); |
94 | 100 | $pk = $this->dataSource->getPrimaryKey(); |
95 | - if ($offset !== null) $value->{$pk[0]} = $offset; |
|
101 | + if ($offset !== null) { |
|
102 | + $value->{$pk[0]} = $offset; |
|
103 | + } |
|
96 | 104 | $valueCopy = clone $value; |
97 | 105 | $value = $this->entity->wrap($this->relations, $value); |
98 | 106 | $this->dataSource->save($value); |
@@ -104,7 +112,9 @@ discard block |
||
104 | 112 | } |
105 | 113 | |
106 | 114 | public function offsetExists($offset) { |
107 | - if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
115 | + if (count($this->dataSource->getPrimaryKey()) > 1) { |
|
116 | + return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
117 | + } |
|
108 | 118 | if (!empty($this->settings['filter'])) { |
109 | 119 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
110 | 120 | return isset($data[0]); |
@@ -117,7 +127,9 @@ discard block |
||
117 | 127 | } |
118 | 128 | |
119 | 129 | public function offsetGet($offset) { |
120 | - if (count($this->dataSource->getPrimaryKey()) > 1) return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
130 | + if (count($this->dataSource->getPrimaryKey()) > 1) { |
|
131 | + return new MultiPk($this, $offset, $this->dataSource->getPrimaryKey()); |
|
132 | + } |
|
121 | 133 | if (!empty($this->settings['filter'])) { |
122 | 134 | $data = $this->dataSource->findByField(array_merge($this->settings['filter'], [$this->dataSource->getPrimaryKey()[0] => $offset])); |
123 | 135 | return $this->entity->create(isset($data[0]) ? $data[0] : null, $this->relations); |
@@ -128,11 +140,15 @@ discard block |
||
128 | 140 | public function __call($method, $args) { |
129 | 141 | if (array_key_exists($method, $this->settings)) { |
130 | 142 | $maphper = new Maphper($this->dataSource, $this->settings, $this->relations); |
131 | - if (is_array($maphper->settings[$method])) $maphper->settings[$method] = $args[0] + $maphper->settings[$method]; |
|
132 | - else $maphper->settings[$method] = $args[0]; |
|
143 | + if (is_array($maphper->settings[$method])) { |
|
144 | + $maphper->settings[$method] = $args[0] + $maphper->settings[$method]; |
|
145 | + } else { |
|
146 | + $maphper->settings[$method] = $args[0]; |
|
147 | + } |
|
133 | 148 | return $maphper; |
149 | + } else { |
|
150 | + throw new \Exception('Method Maphper::' . $method . ' does not exist'); |
|
134 | 151 | } |
135 | - else throw new \Exception('Method Maphper::' . $method . ' does not exist'); |
|
136 | 152 | } |
137 | 153 | |
138 | 154 | public function findAggregate($function, $field, $group = null) { |
@@ -7,20 +7,20 @@ discard block |
||
7 | 7 | |
8 | 8 | public function __construct($object) { |
9 | 9 | if ($object instanceof \stdclass) { |
10 | - $this->readClosure = function() use ($object) { return $object; }; |
|
11 | - $this->writeClosure = function ($field, $value) use ($object) { $object->$field = $value; }; |
|
10 | + $this->readClosure = function() use ($object) { return $object; }; |
|
11 | + $this->writeClosure = function($field, $value) use ($object) { $object->$field = $value; }; |
|
12 | 12 | } |
13 | 13 | else { |
14 | 14 | $this->readClosure = function() { |
15 | 15 | $data = new \stdClass; |
16 | - foreach ($this as $k => $v) { |
|
16 | + foreach ($this as $k => $v) { |
|
17 | 17 | if (is_scalar($v) || is_null($v) || (is_object($v) && $v instanceof \DateTime)) $data->$k = $v; |
18 | 18 | } |
19 | 19 | return $data; |
20 | 20 | }; |
21 | 21 | $this->readClosure = $this->readClosure->bindTo($object, $object); |
22 | 22 | |
23 | - $this->writeClosure = function ($field, $value) { $this->$field = $value; }; |
|
23 | + $this->writeClosure = function($field, $value) { $this->$field = $value; }; |
|
24 | 24 | $this->writeClosure = $this->writeClosure->bindTo($object, $object); |
25 | 25 | } |
26 | 26 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public function write($data) { |
34 | 34 | if ($data != null) { |
35 | 35 | foreach ($data as $key => $value) { |
36 | - ($this->writeClosure)($key, $this->processDates($value)); |
|
36 | + ($this->writeClosure)($key, $this->processDates($value)); |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | } |
@@ -9,12 +9,13 @@ |
||
9 | 9 | if ($object instanceof \stdclass) { |
10 | 10 | $this->readClosure = function() use ($object) { return $object; }; |
11 | 11 | $this->writeClosure = function ($field, $value) use ($object) { $object->$field = $value; }; |
12 | - } |
|
13 | - else { |
|
12 | + } else { |
|
14 | 13 | $this->readClosure = function() { |
15 | 14 | $data = new \stdClass; |
16 | 15 | foreach ($this as $k => $v) { |
17 | - if (is_scalar($v) || is_null($v) || (is_object($v) && $v instanceof \DateTime)) $data->$k = $v; |
|
16 | + if (is_scalar($v) || is_null($v) || (is_object($v) && $v instanceof \DateTime)) { |
|
17 | + $data->$k = $v; |
|
18 | + } |
|
18 | 19 | } |
19 | 20 | return $data; |
20 | 21 | }; |