@@ -37,7 +37,7 @@ |
||
37 | 37 | { |
38 | 38 | foreach ($this->map as $hash => $data) { |
39 | 39 | if ($data['state'] === static::CLEAN && |
40 | - $data['hash'] !== sha1(serialize($data['repository']->toArray($data['entity']))) // TODO |
|
40 | + $data['hash'] !== sha1(serialize($data['repository']->toArray($data['entity']))) // TODO |
|
41 | 41 | ) { |
42 | 42 | $this->map[$hash]['state'] = static::DIRTY; |
43 | 43 | } |
@@ -133,7 +133,7 @@ |
||
133 | 133 | $data[$column] = $entity->{$method}(); |
134 | 134 | } else if (property_exists($entity, $column) || method_exists($entity, '__get')) { |
135 | 135 | $data[$column] = $entity->{$column}; |
136 | - } |
|
136 | + } |
|
137 | 137 | } |
138 | 138 | // gather data from relations |
139 | 139 | if ($relations) { |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | if (isset($data[$name])) { |
69 | 69 | $mapper = $this->manager->getMapper($relation->table->getName()); |
70 | 70 | $entity->{$name} = $relation->many ? |
71 | - array_map(function ($v) use ($mapper) { |
|
71 | + array_map(function($v) use ($mapper) { |
|
72 | 72 | return $mapper->entity($v); |
73 | 73 | }, $data[$name]) : |
74 | 74 | $mapper->entity($data[$name]); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $entity->{$name} = $query; |
108 | 108 | } else { |
109 | 109 | if ($entity instanceof LazyLoadable) { |
110 | - $entity->lazyProperty($name, function () use ($query) { |
|
110 | + $entity->lazyProperty($name, function() use ($query) { |
|
111 | 111 | return $query[0]; |
112 | 112 | }); |
113 | 113 | } else { |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | if (!isset($data)) { |
215 | 215 | continue; |
216 | 216 | } |
217 | - $data = $relation->many ? $data : [ $data ]; |
|
217 | + $data = $relation->many ? $data : [$data]; |
|
218 | 218 | foreach ($data as $item) { |
219 | 219 | foreach ($relation->keymap as $local => $remote) { |
220 | 220 | if (isset($pkey[$local])) { |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | $repository = $this->manager->fromTable( |
303 | 303 | $relation->pivot ? $relation->pivot->getName() : $relation->table->getName() |
304 | 304 | ); |
305 | - $data = $relation->many ? $data : [ $data ]; |
|
305 | + $data = $relation->many ? $data : [$data]; |
|
306 | 306 | foreach ($data as $item) { |
307 | 307 | $repository->remove($item); |
308 | 308 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | public function lazyProperty(string $property, callable $resolve) |
9 | 9 | { |
10 | 10 | unset($this->{$property}); |
11 | - $this->lazyProperties[$property] = [ 'loaded' => false, 'value' => null, 'resolve' => $resolve ]; |
|
11 | + $this->lazyProperties[$property] = ['loaded' => false, 'value' => null, 'resolve' => $resolve]; |
|
12 | 12 | return $this; |
13 | 13 | } |
14 | 14 | public function overrideLazyProperty(string $property, $value) |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public function find($key) |
35 | 35 | { |
36 | 36 | if (!is_array($key)) { |
37 | - $key = [ $key ]; |
|
37 | + $key = [$key]; |
|
38 | 38 | } |
39 | 39 | foreach ($this->query->getDefinition()->getPrimaryKey() as $field) { |
40 | 40 | $this->filter($field, $key[$field] ?? array_shift($key) ?? null); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | } |
73 | 73 | public function current() |
74 | 74 | { |
75 | - if(!($data = $this->query->getIterator()->current())) { |
|
75 | + if (!($data = $this->query->getIterator()->current())) { |
|
76 | 76 | return null; |
77 | 77 | } |
78 | 78 | $this->consumed = true; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | public function offsetGet($offset) |
82 | 82 | { |
83 | - if(!($data = $this->query->offsetGet($offset))) { |
|
83 | + if (!($data = $this->query->offsetGet($offset))) { |
|
84 | 84 | return null; |
85 | 85 | } |
86 | 86 | $this->consumed = true; |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | $sql[] = $table . '.' . $name . ' = ?'; |
163 | 163 | $par[] = $q; |
164 | 164 | $sql[] = $table . '.' . $name . ' LIKE ?'; |
165 | - $par[] = '%' . str_replace(['%', '_'], ['\\%','\\_'], $q) . '%'; |
|
165 | + $par[] = '%' . str_replace(['%', '_'], ['\\%', '\\_'], $q) . '%'; |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | if (count($sql)) { |
169 | - $this->query->where("(".implode(" OR ", $sql).")", $par); |
|
169 | + $this->query->where("(" . implode(" OR ", $sql) . ")", $par); |
|
170 | 170 | } |
171 | 171 | return $this; |
172 | 172 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $this->collection = $collection; |
36 | 36 | $this->original = clone $collection; |
37 | 37 | $this->id = is_array($id) ? $id : [$id]; |
38 | - $this->searching = $searching ?? function () { |
|
38 | + $this->searching = $searching ?? function() { |
|
39 | 39 | return true; |
40 | 40 | }; |
41 | 41 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | } |
61 | 61 | public function reject(string $column, $value) : Repository |
62 | 62 | { |
63 | - $this->collection = $this->collection->reject(function ($v) use ($column, $value) { |
|
63 | + $this->collection = $this->collection->reject(function($v) use ($column, $value) { |
|
64 | 64 | $strict = false; |
65 | 65 | $vv = is_object($v) ? (isset($v->{$column}) ? $v->{$column} : null) : (isset($v[$column]) ? $v[$column] : null); |
66 | 66 | if (!$vv || ($strict && $vv !== $value) || (!$strict && $vv != $value)) { |
@@ -72,13 +72,11 @@ discard block |
||
72 | 72 | } |
73 | 73 | public function sort(string $column, bool $desc = false) : Repository |
74 | 74 | { |
75 | - $this->collection = $this->collection->sortBy(function ($a, $b) use ($column, $desc) { |
|
75 | + $this->collection = $this->collection->sortBy(function($a, $b) use ($column, $desc) { |
|
76 | 76 | $v1 = is_object($a) ? |
77 | - (isset($a->{$column}) ? $a->{$column} : null) : |
|
78 | - (isset($a[$column]) ? $a[$column] : null); |
|
77 | + (isset($a->{$column}) ? $a->{$column} : null) : (isset($a[$column]) ? $a[$column] : null); |
|
79 | 78 | $v2 = is_object($b) ? |
80 | - (isset($b->{$column}) ? $b->{$column} : null) : |
|
81 | - (isset($b[$column]) ? $b[$column] : null); |
|
79 | + (isset($b->{$column}) ? $b->{$column} : null) : (isset($b[$column]) ? $b[$column] : null); |
|
82 | 80 | return $desc ? $v2 <=> $v1 : $v1 <=> $v2; |
83 | 81 | }); |
84 | 82 | return $this; |
@@ -99,7 +97,7 @@ discard block |
||
99 | 97 | } |
100 | 98 | public function current() |
101 | 99 | { |
102 | - if(!($data = $this->collection->current())) { |
|
100 | + if (!($data = $this->collection->current())) { |
|
103 | 101 | return null; |
104 | 102 | } |
105 | 103 | $this->consumed = true; |
@@ -107,7 +105,7 @@ discard block |
||
107 | 105 | } |
108 | 106 | public function offsetGet($offset) |
109 | 107 | { |
110 | - if(!($data = $this->collection->offsetGet($offset))) { |
|
108 | + if (!($data = $this->collection->offsetGet($offset))) { |
|
111 | 109 | return null; |
112 | 110 | } |
113 | 111 | $this->consumed = true; |
@@ -182,7 +180,7 @@ discard block |
||
182 | 180 | |
183 | 181 | public function search(string $q) : Repository |
184 | 182 | { |
185 | - $this->collection = $this->collection->filter(function ($v) use ($q) { |
|
183 | + $this->collection = $this->collection->filter(function($v) use ($q) { |
|
186 | 184 | return call_user_func($this->searching, $v, $q); |
187 | 185 | }); |
188 | 186 | return $this; |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function registerGenericMapperWithClassName(string $table, string $class) |
61 | 61 | { |
62 | - return $this->registerGenericMapper($table, function () use ($class) { |
|
62 | + return $this->registerGenericMapper($table, function() use ($class) { |
|
63 | 63 | return new $class; |
64 | 64 | }); |
65 | 65 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | public function getMapper(string $table) |
83 | 83 | { |
84 | 84 | if (!isset($this->map[$table])) { |
85 | - $this->registerGenericMapper($table, function () { |
|
85 | + $this->registerGenericMapper($table, function() { |
|
86 | 86 | return new class() extends \StdClass implements LazyLoadable { |
87 | 87 | use LazyLoad; |
88 | 88 | }; |
@@ -94,8 +94,7 @@ discard block |
||
94 | 94 | { |
95 | 95 | $collection = $this->fromTable($table); |
96 | 96 | return !count($args) ? |
97 | - $collection : |
|
98 | - $collection->find($args[0]); |
|
97 | + $collection : $collection->find($args[0]); |
|
99 | 98 | } |
100 | 99 | /** |
101 | 100 | * Get a repository from a table query |