@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use As3\Modlr\Exception\MetadataException; |
6 | 6 | use As3\Modlr\Metadata\EntityMetadata; |
7 | -use As3\Modlr\Metadata\Interfaces\StorageLayerInterface; |
|
8 | 7 | use As3\Modlr\Metadata\Interfaces\StorageMetadataFactoryInterface; |
9 | 8 | use As3\Modlr\Util\EntityUtility; |
10 | 9 |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | { |
39 | 39 | $persistence = new StorageMetadata(); |
40 | 40 | |
41 | - if (isset($mapping['db'])) { |
|
42 | - $persistence->db = $mapping['db']; |
|
41 | + if (isset($mapping[ 'db' ])) { |
|
42 | + $persistence->db = $mapping[ 'db' ]; |
|
43 | 43 | } |
44 | 44 | |
45 | - if (isset($mapping['collection'])) { |
|
46 | - $persistence->collection = $mapping['collection']; |
|
45 | + if (isset($mapping[ 'collection' ])) { |
|
46 | + $persistence->collection = $mapping[ 'collection' ]; |
|
47 | 47 | } |
48 | 48 | return $persistence; |
49 | 49 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | private function validateIdStrategy(EntityMetadata $metadata) |
114 | 114 | { |
115 | 115 | $persistence = $metadata->persistence; |
116 | - $validIdStrategies = ['object']; |
|
116 | + $validIdStrategies = [ 'object' ]; |
|
117 | 117 | if (!in_array($persistence->idStrategy, $validIdStrategies)) { |
118 | 118 | throw MetadataException::invalidMetadata($metadata->type, sprintf('The persistence id strategy "%s" is invalid. Valid types are "%s"', $persistence->idStrategy, implode('", "', $validIdStrategies))); |
119 | 119 | } |
@@ -6,7 +6,6 @@ |
||
6 | 6 | use As3\Modlr\Models\Model; |
7 | 7 | use As3\Modlr\Models\Collection; |
8 | 8 | use As3\Modlr\Metadata\EntityMetadata; |
9 | -use As3\Modlr\Metadata\AttributeMetadata; |
|
10 | 9 | use As3\Modlr\Metadata\RelationshipMetadata; |
11 | 10 | use As3\Modlr\Persister\PersisterInterface; |
12 | 11 | use As3\Modlr\Persister\PersisterException; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * {@inheritDoc} |
79 | 79 | * @todo Implement sorting and pagination (limit/skip). |
80 | 80 | */ |
81 | - public function all(EntityMetadata $metadata, Store $store, array $identifiers = []) |
|
81 | + public function all(EntityMetadata $metadata, Store $store, array $identifiers = [ ]) |
|
82 | 82 | { |
83 | 83 | $criteria = $this->getRetrieveCritiera($metadata, $identifiers); |
84 | 84 | $cursor = $this->doQuery($metadata, $store, $criteria); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * {@inheritDoc} |
90 | 90 | */ |
91 | - public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
91 | + public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
92 | 92 | { |
93 | 93 | $cursor = $this->doQuery($metadata, $store, $criteria); |
94 | 94 | return $this->hydrateRecords($metadata, $cursor->toArray(), $store); |
@@ -124,32 +124,32 @@ discard block |
||
124 | 124 | public function create(Model $model) |
125 | 125 | { |
126 | 126 | $metadata = $model->getMetadata(); |
127 | - $insert[$this->getIdentifierKey()] = $this->convertId($model->getId()); |
|
127 | + $insert[ $this->getIdentifierKey() ] = $this->convertId($model->getId()); |
|
128 | 128 | if (true === $metadata->isChildEntity()) { |
129 | - $insert[$this->getPolymorphicKey()] = $metadata->type; |
|
129 | + $insert[ $this->getPolymorphicKey() ] = $metadata->type; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $changeset = $model->getChangeSet(); |
133 | - foreach ($changeset['attributes'] as $key => $values) { |
|
134 | - $value = $this->getFormatter()->getAttributeDbValue($metadata->getAttribute($key), $values['new']); |
|
133 | + foreach ($changeset[ 'attributes' ] as $key => $values) { |
|
134 | + $value = $this->getFormatter()->getAttributeDbValue($metadata->getAttribute($key), $values[ 'new' ]); |
|
135 | 135 | if (null === $value) { |
136 | 136 | continue; |
137 | 137 | } |
138 | - $insert[$key] = $value; |
|
138 | + $insert[ $key ] = $value; |
|
139 | 139 | } |
140 | - foreach ($changeset['hasOne'] as $key => $values) { |
|
141 | - $value = $this->getFormatter()->getHasOneDbValue($metadata->getRelationship($key), $values['new']); |
|
140 | + foreach ($changeset[ 'hasOne' ] as $key => $values) { |
|
141 | + $value = $this->getFormatter()->getHasOneDbValue($metadata->getRelationship($key), $values[ 'new' ]); |
|
142 | 142 | if (null === $value) { |
143 | 143 | continue; |
144 | 144 | } |
145 | - $insert[$key] = $value; |
|
145 | + $insert[ $key ] = $value; |
|
146 | 146 | } |
147 | - foreach ($changeset['hasMany'] as $key => $values) { |
|
148 | - $value = $this->getFormatter()->getHasManyDbValue($metadata->getRelationship($key), $values['new']); |
|
147 | + foreach ($changeset[ 'hasMany' ] as $key => $values) { |
|
148 | + $value = $this->getFormatter()->getHasManyDbValue($metadata->getRelationship($key), $values[ 'new' ]); |
|
149 | 149 | if (null === $value) { |
150 | 150 | continue; |
151 | 151 | } |
152 | - $insert[$key] = $value; |
|
152 | + $insert[ $key ] = $value; |
|
153 | 153 | } |
154 | 154 | $this->createQueryBuilder($metadata) |
155 | 155 | ->insert() |
@@ -170,39 +170,39 @@ discard block |
||
170 | 170 | $criteria = $this->getRetrieveCritiera($metadata, $model->getId()); |
171 | 171 | $changeset = $model->getChangeSet(); |
172 | 172 | |
173 | - $update = []; |
|
174 | - foreach ($changeset['attributes'] as $key => $values) { |
|
175 | - if (null === $values['new']) { |
|
173 | + $update = [ ]; |
|
174 | + foreach ($changeset[ 'attributes' ] as $key => $values) { |
|
175 | + if (null === $values[ 'new' ]) { |
|
176 | 176 | $op = '$unset'; |
177 | 177 | $value = 1; |
178 | 178 | } else { |
179 | 179 | $op = '$set'; |
180 | - $value = $this->getFormatter()->getAttributeDbValue($metadata->getAttribute($key), $values['new']); |
|
180 | + $value = $this->getFormatter()->getAttributeDbValue($metadata->getAttribute($key), $values[ 'new' ]); |
|
181 | 181 | } |
182 | - $update[$op][$key] = $value; |
|
182 | + $update[ $op ][ $key ] = $value; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | // @todo Must prevent inverse relationships from persisting |
186 | - foreach ($changeset['hasOne'] as $key => $values) { |
|
187 | - if (null === $values['new']) { |
|
186 | + foreach ($changeset[ 'hasOne' ] as $key => $values) { |
|
187 | + if (null === $values[ 'new' ]) { |
|
188 | 188 | $op = '$unset'; |
189 | 189 | $value = 1; |
190 | 190 | } else { |
191 | 191 | $op = '$set'; |
192 | - $value = $this->getFormatter()->getHasOneDbValue($metadata->getRelationship($key), $values['new']); |
|
192 | + $value = $this->getFormatter()->getHasOneDbValue($metadata->getRelationship($key), $values[ 'new' ]); |
|
193 | 193 | } |
194 | - $update[$op][$key] = $value; |
|
194 | + $update[ $op ][ $key ] = $value; |
|
195 | 195 | } |
196 | 196 | |
197 | - foreach ($changeset['hasMany'] as $key => $values) { |
|
198 | - if (null === $values['new']) { |
|
197 | + foreach ($changeset[ 'hasMany' ] as $key => $values) { |
|
198 | + if (null === $values[ 'new' ]) { |
|
199 | 199 | $op = '$unset'; |
200 | 200 | $value = 1; |
201 | 201 | } else { |
202 | 202 | $op = '$set'; |
203 | - $value = $this->getFormatter()->getHasManyDbValue($metadata->getRelationship($key), $values['new']); |
|
203 | + $value = $this->getFormatter()->getHasManyDbValue($metadata->getRelationship($key), $values[ 'new' ]); |
|
204 | 204 | } |
205 | - $update[$op][$key] = $value; |
|
205 | + $update[ $op ][ $key ] = $value; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | if (empty($update)) { |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | if (false === $metadata->isPolymorphic()) { |
288 | 288 | return $metadata->type; |
289 | 289 | } |
290 | - if (!isset($data[$this->getPolymorphicKey()])) { |
|
290 | + if (!isset($data[ $this->getPolymorphicKey() ])) { |
|
291 | 291 | throw PersisterException::badRequest(sprintf('Unable to extract polymorphic type. The "%s" key was not found.', $this->getPolymorphicKey())); |
292 | 292 | } |
293 | - return $data[$this->getPolymorphicKey()]; |
|
293 | + return $data[ $this->getPolymorphicKey() ]; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | * @param int $limit The number of Models to limit. |
306 | 306 | * @return \Doctrine\MongoDB\Cursor |
307 | 307 | */ |
308 | - protected function doQuery(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
308 | + protected function doQuery(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
309 | 309 | { |
310 | 310 | $criteria = $this->getFormatter()->formatQuery($metadata, $store, $criteria); |
311 | 311 | return $this->createQueryBuilder($metadata) |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | */ |
327 | 327 | protected function hydrateRecords(EntityMetadata $metadata, array $results, Store $store) |
328 | 328 | { |
329 | - $records = []; |
|
329 | + $records = [ ]; |
|
330 | 330 | foreach ($results as $data) { |
331 | - $records[] = $this->hydrateRecord($metadata, $data, $store); |
|
331 | + $records[ ] = $this->hydrateRecord($metadata, $data, $store); |
|
332 | 332 | } |
333 | 333 | return $records; |
334 | 334 | } |
@@ -343,27 +343,27 @@ discard block |
||
343 | 343 | */ |
344 | 344 | protected function hydrateRecord(EntityMetadata $metadata, array $data, Store $store) |
345 | 345 | { |
346 | - $identifier = $data[$this->getIdentifierKey()]; |
|
347 | - unset($data[$this->getIdentifierKey()]); |
|
346 | + $identifier = $data[ $this->getIdentifierKey() ]; |
|
347 | + unset($data[ $this->getIdentifierKey() ]); |
|
348 | 348 | |
349 | 349 | $type = $this->extractType($metadata, $data); |
350 | - unset($data[$this->getPolymorphicKey()]); |
|
350 | + unset($data[ $this->getPolymorphicKey() ]); |
|
351 | 351 | |
352 | 352 | $metadata = $store->getMetadataForType($type); |
353 | 353 | foreach ($metadata->getRelationships() as $key => $relMeta) { |
354 | - if (!isset($data[$key])) { |
|
354 | + if (!isset($data[ $key ])) { |
|
355 | 355 | continue; |
356 | 356 | } |
357 | - if (true === $relMeta->isMany() && !is_array($data[$key])) { |
|
358 | - throw PersisterException::badRequest(sprintf('Relationship key "%s" is a reference many. Expected record data type of array, "%s" found on model "%s" for identifier "%s"', $key, gettype($data[$key]), $type, $identifier)); |
|
357 | + if (true === $relMeta->isMany() && !is_array($data[ $key ])) { |
|
358 | + throw PersisterException::badRequest(sprintf('Relationship key "%s" is a reference many. Expected record data type of array, "%s" found on model "%s" for identifier "%s"', $key, gettype($data[ $key ]), $type, $identifier)); |
|
359 | 359 | } |
360 | - $references = $relMeta->isOne() ? [$data[$key]] : $data[$key]; |
|
360 | + $references = $relMeta->isOne() ? [ $data[ $key ] ] : $data[ $key ]; |
|
361 | 361 | |
362 | - $extracted = []; |
|
362 | + $extracted = [ ]; |
|
363 | 363 | foreach ($references as $reference) { |
364 | - $extracted[] = $this->extractRelationship($relMeta, $reference); |
|
364 | + $extracted[ ] = $this->extractRelationship($relMeta, $reference); |
|
365 | 365 | } |
366 | - $data[$key] = $relMeta->isOne() ? reset($extracted) : $extracted; |
|
366 | + $data[ $key ] = $relMeta->isOne() ? reset($extracted) : $extracted; |
|
367 | 367 | } |
368 | 368 | return new Record($type, $identifier, $data); |
369 | 369 | } |
@@ -381,9 +381,9 @@ discard block |
||
381 | 381 | $simple = false === $relMeta->isPolymorphic(); |
382 | 382 | $idKey = $this->getIdentifierKey(); |
383 | 383 | $typeKey = $this->getPolymorphicKey(); |
384 | - if (true === $simple && is_array($reference) && isset($reference[$idKey])) { |
|
384 | + if (true === $simple && is_array($reference) && isset($reference[ $idKey ])) { |
|
385 | 385 | return [ |
386 | - 'id' => $reference[$idKey], |
|
386 | + 'id' => $reference[ $idKey ], |
|
387 | 387 | 'type' => $relMeta->getEntityType(), |
388 | 388 | ]; |
389 | 389 | } elseif (true === $simple && !is_array($reference)) { |
@@ -391,10 +391,10 @@ discard block |
||
391 | 391 | 'id' => $reference, |
392 | 392 | 'type' => $relMeta->getEntityType(), |
393 | 393 | ]; |
394 | - } elseif (false === $simple && is_array($reference) && isset($reference[$idKey]) && isset($reference[$typeKey])) { |
|
394 | + } elseif (false === $simple && is_array($reference) && isset($reference[ $idKey ]) && isset($reference[ $typeKey ])) { |
|
395 | 395 | return [ |
396 | - 'id' => $reference[$idKey], |
|
397 | - 'type' => $reference[$typeKey], |
|
396 | + 'id' => $reference[ $idKey ], |
|
397 | + 'type' => $reference[ $typeKey ], |
|
398 | 398 | ]; |
399 | 399 | } else { |
400 | 400 | throw new RuntimeException('Unable to extract a reference id.'); |
@@ -410,17 +410,17 @@ discard block |
||
410 | 410 | */ |
411 | 411 | protected function getInverseCriteria(EntityMetadata $owner, EntityMetadata $related, $identifiers, $inverseField) |
412 | 412 | { |
413 | - $criteria[$inverseField] = (array) $identifiers; |
|
413 | + $criteria[ $inverseField ] = (array) $identifiers; |
|
414 | 414 | if (true === $owner->isChildEntity()) { |
415 | 415 | // The owner is owned by a polymorphic model. Must include the type with the inverse field criteria. |
416 | - $criteria[$inverseField] = [ |
|
417 | - $this->getIdentifierKey() => $criteria[$inverseField], |
|
416 | + $criteria[ $inverseField ] = [ |
|
417 | + $this->getIdentifierKey() => $criteria[ $inverseField ], |
|
418 | 418 | $this->getPolymorphicKey() => $owner->type, |
419 | 419 | ]; |
420 | 420 | } |
421 | 421 | if (true === $related->isChildEntity()) { |
422 | 422 | // The relationship is owned by a polymorphic model. Must include the type in the root criteria. |
423 | - $criteria[$this->getPolymorphicKey()] = $related->type; |
|
423 | + $criteria[ $this->getPolymorphicKey() ] = $related->type; |
|
424 | 424 | } |
425 | 425 | return $criteria; |
426 | 426 | } |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | */ |
435 | 435 | protected function getRetrieveCritiera(EntityMetadata $metadata, $identifiers = null) |
436 | 436 | { |
437 | - $criteria = []; |
|
437 | + $criteria = [ ]; |
|
438 | 438 | if (true === $metadata->isChildEntity()) { |
439 | - $criteria[$this->getPolymorphicKey()] = $metadata->type; |
|
439 | + $criteria[ $this->getPolymorphicKey() ] = $metadata->type; |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | if (null === $identifiers) { |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | if (empty($identifiers)) { |
447 | 447 | return $criteria; |
448 | 448 | } |
449 | - $criteria[$this->getIdentifierKey()] = (1 === count($identifiers)) ? $identifiers[0] : $identifiers; |
|
449 | + $criteria[ $this->getIdentifierKey() ] = (1 === count($identifiers)) ? $identifiers[ 0 ] : $identifiers; |
|
450 | 450 | return $criteria; |
451 | 451 | } |
452 | 452 |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | * @var array |
29 | 29 | */ |
30 | 30 | private $ops = [ |
31 | - 'root' => ['$and', '$or', '$nor'], |
|
32 | - 'single' => ['$eq', '$gt', '$gte', '$lt', '$lte', '$ne'], |
|
33 | - 'multiple' => ['$in', '$nin', '$all'], |
|
34 | - 'recursive' => ['$not', '$elemMatch'], |
|
35 | - 'ignore' => ['$exists', '$type', '$mod', '$size', '$regex', '$text', '$where'], |
|
31 | + 'root' => [ '$and', '$or', '$nor' ], |
|
32 | + 'single' => [ '$eq', '$gt', '$gte', '$lt', '$lte', '$ne' ], |
|
33 | + 'multiple' => [ '$in', '$nin', '$all' ], |
|
34 | + 'recursive' => [ '$not', '$elemMatch' ], |
|
35 | + 'ignore' => [ '$exists', '$type', '$mod', '$size', '$regex', '$text', '$where' ], |
|
36 | 36 | ]; |
37 | 37 | |
38 | 38 | /** |
@@ -47,23 +47,23 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function formatQuery(EntityMetadata $metadata, Store $store, array $criteria) |
49 | 49 | { |
50 | - $formatted = []; |
|
50 | + $formatted = [ ]; |
|
51 | 51 | foreach ($criteria as $key => $value) { |
52 | 52 | |
53 | 53 | if ($this->isOpType('root', $key) && is_array($value)) { |
54 | 54 | foreach ($value as $subKey => $subValue) { |
55 | - $formatted[$key][$subKey] = $this->formatQuery($metadata, $store, $subValue); |
|
55 | + $formatted[ $key ][ $subKey ] = $this->formatQuery($metadata, $store, $subValue); |
|
56 | 56 | } |
57 | 57 | continue; |
58 | 58 | } |
59 | 59 | |
60 | 60 | if ($this->isOperator($key) && is_array($value)) { |
61 | - $formatted[$key] = $this->formatQuery($metadata, $store, $value); |
|
61 | + $formatted[ $key ] = $this->formatQuery($metadata, $store, $value); |
|
62 | 62 | continue; |
63 | 63 | } |
64 | 64 | |
65 | 65 | list($key, $value) = $this->formatQueryElement($key, $value, $metadata, $store); |
66 | - $formatted[$key] = $value; |
|
66 | + $formatted[ $key ] = $value; |
|
67 | 67 | } |
68 | 68 | return $formatted; |
69 | 69 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | if (null === $models || true === $relMeta->isInverse) { |
112 | 112 | return null; |
113 | 113 | } |
114 | - $references = []; |
|
114 | + $references = [ ]; |
|
115 | 115 | foreach ($models as $model) { |
116 | - $references[] = $this->createReference($relMeta, $model); |
|
116 | + $references[ ] = $this->createReference($relMeta, $model); |
|
117 | 117 | } |
118 | 118 | return empty($references) ? null : $references; |
119 | 119 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function getIdentifierFields() |
141 | 141 | { |
142 | - return [Persister::IDENTIFIER_KEY, EntityMetadata::ID_KEY]; |
|
142 | + return [ Persister::IDENTIFIER_KEY, EntityMetadata::ID_KEY ]; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function getTypeFields() |
151 | 151 | { |
152 | - return [Persister::POLYMORPHIC_KEY, EntityMetadata::TYPE_KEY]; |
|
152 | + return [ Persister::POLYMORPHIC_KEY, EntityMetadata::TYPE_KEY ]; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | */ |
197 | 197 | private function createReference(RelationshipMetadata $relMeta, Model $model) |
198 | 198 | { |
199 | - $reference = []; |
|
199 | + $reference = [ ]; |
|
200 | 200 | $identifier = $this->getIdentifierDbValue($model->getId()); |
201 | 201 | if (true === $relMeta->isPolymorphic()) { |
202 | - $reference[Persister::IDENTIFIER_KEY] = $identifier; |
|
203 | - $reference[Persister::TYPE_KEY] = $model->getType(); |
|
202 | + $reference[ Persister::IDENTIFIER_KEY ] = $identifier; |
|
203 | + $reference[ Persister::TYPE_KEY ] = $model->getType(); |
|
204 | 204 | return $reference; |
205 | 205 | } |
206 | 206 | return $identifier; |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | } |
245 | 245 | |
246 | 246 | // Pass remaining elements unconverted. |
247 | - return [$key, $value]; |
|
247 | + return [ $key, $value ]; |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | if (is_array($value)) { |
269 | 269 | |
270 | 270 | if (true === $this->hasOperators($value)) { |
271 | - return [$key, $this->formatQueryExpression($value, $converter)]; |
|
271 | + return [ $key, $this->formatQueryExpression($value, $converter) ]; |
|
272 | 272 | } |
273 | 273 | |
274 | - if (in_array($attrMeta->dataType, ['array', 'object'])) { |
|
275 | - return [$key, $value]; |
|
274 | + if (in_array($attrMeta->dataType, [ 'array', 'object' ])) { |
|
275 | + return [ $key, $value ]; |
|
276 | 276 | } |
277 | - return [$key, $this->formatQueryExpression(['$in' => $value], $converter)]; |
|
277 | + return [ $key, $this->formatQueryExpression([ '$in' => $value ], $converter) ]; |
|
278 | 278 | } |
279 | - return [$key, $converter($value)]; |
|
279 | + return [ $key, $converter($value) ]; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -299,30 +299,30 @@ discard block |
||
299 | 299 | $root = array_shift($parts); |
300 | 300 | if (false === $metadata->hasRelationship($root)) { |
301 | 301 | // Nothing to format. Allow the dotted field to pass normally. |
302 | - return [$key, $value]; |
|
302 | + return [ $key, $value ]; |
|
303 | 303 | } |
304 | - $hasIndex = is_numeric($parts[0]); |
|
304 | + $hasIndex = is_numeric($parts[ 0 ]); |
|
305 | 305 | |
306 | 306 | if (true === $hasIndex) { |
307 | - $subKey = isset($parts[1]) ? $parts[1] : 'id'; |
|
307 | + $subKey = isset($parts[ 1 ]) ? $parts[ 1 ] : 'id'; |
|
308 | 308 | } else { |
309 | - $subKey = $parts[0]; |
|
309 | + $subKey = $parts[ 0 ]; |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | if ($this->isIdentifierField($subKey)) { |
313 | 313 | // Handle like a regular relationship |
314 | 314 | list($key, $value) = $this->formatQueryElementRel($root, $value, $metadata, $store); |
315 | - $key = (true === $hasIndex) ? sprintf('%s.%s', $key, $parts[0]) : $key; |
|
316 | - return [$key, $value]; |
|
315 | + $key = (true === $hasIndex) ? sprintf('%s.%s', $key, $parts[ 0 ]) : $key; |
|
316 | + return [ $key, $value ]; |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | if ($this->isTypeField($subKey)) { |
320 | 320 | // Handle as a model type field. |
321 | 321 | list($key, $value) = $this->formatQueryElementType($subKey, $value); |
322 | - $key = (true === $hasIndex) ? sprintf('%s.%s.%s', $root, $parts[0], $key) : sprintf('%s.%s', $root, $key); |
|
323 | - return [$key, $value]; |
|
322 | + $key = (true === $hasIndex) ? sprintf('%s.%s.%s', $root, $parts[ 0 ], $key) : sprintf('%s.%s', $root, $key); |
|
323 | + return [ $key, $value ]; |
|
324 | 324 | } |
325 | - return [$key, $value]; |
|
325 | + return [ $key, $value ]; |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -344,10 +344,10 @@ discard block |
||
344 | 344 | $converter = $this->getQueryIdConverter($metadata); |
345 | 345 | |
346 | 346 | if (is_array($value)) { |
347 | - $value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value]; |
|
348 | - return [$dbIdKey, $this->formatQueryExpression($value, $converter)]; |
|
347 | + $value = (true === $this->hasOperators($value)) ? $value : [ '$in' => $value ]; |
|
348 | + return [ $dbIdKey, $this->formatQueryExpression($value, $converter) ]; |
|
349 | 349 | } |
350 | - return [$dbIdKey, $converter($value)]; |
|
350 | + return [ $dbIdKey, $converter($value) ]; |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -373,10 +373,10 @@ discard block |
||
373 | 373 | } |
374 | 374 | |
375 | 375 | if (is_array($value)) { |
376 | - $value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value]; |
|
377 | - return [$key, $this->formatQueryExpression($value, $converter)]; |
|
376 | + $value = (true === $this->hasOperators($value)) ? $value : [ '$in' => $value ]; |
|
377 | + return [ $key, $this->formatQueryExpression($value, $converter) ]; |
|
378 | 378 | } |
379 | - return [$key, $converter($value)]; |
|
379 | + return [ $key, $converter($value) ]; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -397,10 +397,10 @@ discard block |
||
397 | 397 | $converter = $this->getQueryTypeConverter(); |
398 | 398 | |
399 | 399 | if (is_array($value)) { |
400 | - $value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value]; |
|
401 | - return [$dbTypeKey, $this->formatQueryExpression($value, $converter)]; |
|
400 | + $value = (true === $this->hasOperators($value)) ? $value : [ '$in' => $value ]; |
|
401 | + return [ $dbTypeKey, $this->formatQueryExpression($value, $converter) ]; |
|
402 | 402 | } |
403 | - return [$dbTypeKey, $converter($value)]; |
|
403 | + return [ $dbTypeKey, $converter($value) ]; |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -419,25 +419,25 @@ discard block |
||
419 | 419 | } |
420 | 420 | |
421 | 421 | if (true === $this->isOpType('single', $key)) { |
422 | - $expression[$key] = $converter($value); |
|
422 | + $expression[ $key ] = $converter($value); |
|
423 | 423 | continue; |
424 | 424 | } |
425 | 425 | |
426 | 426 | if (true === $this->isOpType('multiple', $key)) { |
427 | 427 | $value = (array) $value; |
428 | 428 | foreach ($value as $subKey => $subValue) { |
429 | - $expression[$key][$subKey] = $converter($subValue); |
|
429 | + $expression[ $key ][ $subKey ] = $converter($subValue); |
|
430 | 430 | } |
431 | 431 | continue; |
432 | 432 | } |
433 | 433 | |
434 | 434 | if (true === $this->isOpType('recursive', $key)) { |
435 | 435 | $value = (array) $value; |
436 | - $expression[$key] = $this->formatQueryExpression($value, $converter); |
|
436 | + $expression[ $key ] = $this->formatQueryExpression($value, $converter); |
|
437 | 437 | continue; |
438 | 438 | } |
439 | 439 | |
440 | - $expression[$key] = $converter($value); |
|
440 | + $expression[ $key ] = $converter($value); |
|
441 | 441 | } |
442 | 442 | return $expression; |
443 | 443 | } |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | */ |
452 | 452 | private function getQueryAttrConverter(Store $store, AttributeMetadata $attrMeta) |
453 | 453 | { |
454 | - return function ($value) use ($store, $attrMeta) { |
|
454 | + return function($value) use ($store, $attrMeta) { |
|
455 | 455 | $value = $store->convertAttributeValue($attrMeta->dataType, $value); |
456 | 456 | return $this->getAttributeDbValue($attrMeta, $value); |
457 | 457 | }; |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | */ |
530 | 530 | private function isOperator($key) |
531 | 531 | { |
532 | - return isset($key[0]) && '$' === $key[0]; |
|
532 | + return isset($key[ 0 ]) && '$' === $key[ 0 ]; |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -541,9 +541,9 @@ discard block |
||
541 | 541 | */ |
542 | 542 | private function isOpType($type, $key) |
543 | 543 | { |
544 | - if (!isset($this->ops[$type])) { |
|
544 | + if (!isset($this->ops[ $type ])) { |
|
545 | 545 | return false; |
546 | 546 | } |
547 | - return in_array($key, $this->ops[$type]); |
|
547 | + return in_array($key, $this->ops[ $type ]); |
|
548 | 548 | } |
549 | 549 | } |