@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | * @var array |
31 | 31 | */ |
32 | 32 | private $ops = [ |
33 | - 'root' => ['$and', '$or', '$nor'], |
|
34 | - 'single' => ['$eq', '$gt', '$gte', '$lt', '$lte', '$ne'], |
|
35 | - 'multiple' => ['$in', '$nin', '$all'], |
|
36 | - 'recursive' => ['$not', '$elemMatch'], |
|
37 | - 'ignore' => ['$exists', '$type', '$mod', '$size', '$regex', '$text', '$where'], |
|
33 | + 'root' => [ '$and', '$or', '$nor' ], |
|
34 | + 'single' => [ '$eq', '$gt', '$gte', '$lt', '$lte', '$ne' ], |
|
35 | + 'multiple' => [ '$in', '$nin', '$all' ], |
|
36 | + 'recursive' => [ '$not', '$elemMatch' ], |
|
37 | + 'ignore' => [ '$exists', '$type', '$mod', '$size', '$regex', '$text', '$where' ], |
|
38 | 38 | ]; |
39 | 39 | |
40 | 40 | /** |
@@ -49,23 +49,23 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function formatQuery(EntityMetadata $metadata, Store $store, array $criteria) |
51 | 51 | { |
52 | - $formatted = []; |
|
52 | + $formatted = [ ]; |
|
53 | 53 | foreach ($criteria as $key => $value) { |
54 | 54 | |
55 | 55 | if ($this->isOpType('root', $key) && is_array($value)) { |
56 | 56 | foreach ($value as $subKey => $subValue) { |
57 | - $formatted[$key][$subKey] = $this->formatQuery($metadata, $store, $subValue); |
|
57 | + $formatted[ $key ][ $subKey ] = $this->formatQuery($metadata, $store, $subValue); |
|
58 | 58 | } |
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | 62 | if ($this->isOperator($key) && is_array($value)) { |
63 | - $formatted[$key] = $this->formatQuery($metadata, $store, $value); |
|
63 | + $formatted[ $key ] = $this->formatQuery($metadata, $store, $value); |
|
64 | 64 | continue; |
65 | 65 | } |
66 | 66 | |
67 | 67 | list($key, $value) = $this->formatQueryElement($key, $value, $metadata, $store); |
68 | - $formatted[$key] = $value; |
|
68 | + $formatted[ $key ] = $value; |
|
69 | 69 | } |
70 | 70 | return $formatted; |
71 | 71 | } |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | if (null === $embeds) { |
106 | 106 | return; |
107 | 107 | } |
108 | - $created = []; |
|
108 | + $created = [ ]; |
|
109 | 109 | foreach ($embeds as $embed) { |
110 | - $created[] = $this->createEmbed($embeddedPropMeta, $embed); |
|
110 | + $created[ ] = $this->createEmbed($embeddedPropMeta, $embed); |
|
111 | 111 | } |
112 | 112 | return empty($created) ? null : $created; |
113 | 113 | } |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | if (null === $models || true === $relMeta->isInverse) { |
155 | 155 | return null; |
156 | 156 | } |
157 | - $references = []; |
|
157 | + $references = [ ]; |
|
158 | 158 | foreach ($models as $model) { |
159 | - $references[] = $this->createReference($relMeta, $model); |
|
159 | + $references[ ] = $this->createReference($relMeta, $model); |
|
160 | 160 | } |
161 | 161 | return empty($references) ? null : $references; |
162 | 162 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function getIdentifierFields() |
184 | 184 | { |
185 | - return [Persister::IDENTIFIER_KEY, EntityMetadata::ID_KEY]; |
|
185 | + return [ Persister::IDENTIFIER_KEY, EntityMetadata::ID_KEY ]; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function getTypeFields() |
194 | 194 | { |
195 | - return [Persister::POLYMORPHIC_KEY, EntityMetadata::TYPE_KEY]; |
|
195 | + return [ Persister::POLYMORPHIC_KEY, EntityMetadata::TYPE_KEY ]; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -241,20 +241,20 @@ discard block |
||
241 | 241 | { |
242 | 242 | $embedMeta = $embeddedPropMeta->embedMeta; |
243 | 243 | |
244 | - $obj = []; |
|
244 | + $obj = [ ]; |
|
245 | 245 | foreach ($embedMeta->getAttributes() as $key => $attrMeta) { |
246 | 246 | $value = $this->getAttributeDbValue($attrMeta, $embed->get($key)); |
247 | 247 | if (null === $value) { |
248 | 248 | continue; |
249 | 249 | } |
250 | - $obj[$key] = $value; |
|
250 | + $obj[ $key ] = $value; |
|
251 | 251 | } |
252 | 252 | foreach ($embedMeta->getEmbeds() as $key => $propMeta) { |
253 | 253 | $value = (true === $propMeta->isOne()) ? $this->getEmbedOneDbValue($propMeta, $embed->get($key)) : $this->getEmbedManyDbValue($propMeta, $embed->get($key)); |
254 | 254 | if (null === $value) { |
255 | 255 | continue; |
256 | 256 | } |
257 | - $obj[$key] = $value; |
|
257 | + $obj[ $key ] = $value; |
|
258 | 258 | } |
259 | 259 | return $obj; |
260 | 260 | } |
@@ -268,11 +268,11 @@ discard block |
||
268 | 268 | */ |
269 | 269 | private function createReference(RelationshipMetadata $relMeta, Model $model) |
270 | 270 | { |
271 | - $reference = []; |
|
271 | + $reference = [ ]; |
|
272 | 272 | $identifier = $this->getIdentifierDbValue($model->getId()); |
273 | 273 | if (true === $relMeta->isPolymorphic()) { |
274 | - $reference[Persister::IDENTIFIER_KEY] = $identifier; |
|
275 | - $reference[Persister::TYPE_KEY] = $model->getType(); |
|
274 | + $reference[ Persister::IDENTIFIER_KEY ] = $identifier; |
|
275 | + $reference[ Persister::TYPE_KEY ] = $model->getType(); |
|
276 | 276 | return $reference; |
277 | 277 | } |
278 | 278 | return $identifier; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | // Pass remaining elements unconverted. |
314 | - return [$key, $value]; |
|
314 | + return [ $key, $value ]; |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -335,15 +335,15 @@ discard block |
||
335 | 335 | if (is_array($value)) { |
336 | 336 | |
337 | 337 | if (true === $this->hasOperators($value)) { |
338 | - return [$key, $this->formatQueryExpression($value, $converter)]; |
|
338 | + return [ $key, $this->formatQueryExpression($value, $converter) ]; |
|
339 | 339 | } |
340 | 340 | |
341 | - if (in_array($attrMeta->dataType, ['array', 'object'])) { |
|
342 | - return [$key, $value]; |
|
341 | + if (in_array($attrMeta->dataType, [ 'array', 'object' ])) { |
|
342 | + return [ $key, $value ]; |
|
343 | 343 | } |
344 | - return [$key, $this->formatQueryExpression(['$in' => $value], $converter)]; |
|
344 | + return [ $key, $this->formatQueryExpression([ '$in' => $value ], $converter) ]; |
|
345 | 345 | } |
346 | - return [$key, $converter($value)]; |
|
346 | + return [ $key, $converter($value) ]; |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
@@ -366,30 +366,30 @@ discard block |
||
366 | 366 | $root = array_shift($parts); |
367 | 367 | if (false === $metadata->hasRelationship($root)) { |
368 | 368 | // Nothing to format. Allow the dotted field to pass normally. |
369 | - return [$key, $value]; |
|
369 | + return [ $key, $value ]; |
|
370 | 370 | } |
371 | - $hasIndex = is_numeric($parts[0]); |
|
371 | + $hasIndex = is_numeric($parts[ 0 ]); |
|
372 | 372 | |
373 | 373 | if (true === $hasIndex) { |
374 | - $subKey = isset($parts[1]) ? $parts[1] : 'id'; |
|
374 | + $subKey = isset($parts[ 1 ]) ? $parts[ 1 ] : 'id'; |
|
375 | 375 | } else { |
376 | - $subKey = $parts[0]; |
|
376 | + $subKey = $parts[ 0 ]; |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | if ($this->isIdentifierField($subKey)) { |
380 | 380 | // Handle like a regular relationship |
381 | 381 | list($key, $value) = $this->formatQueryElementRel($root, $value, $metadata, $store); |
382 | - $key = (true === $hasIndex) ? sprintf('%s.%s', $key, $parts[0]) : $key; |
|
383 | - return [$key, $value]; |
|
382 | + $key = (true === $hasIndex) ? sprintf('%s.%s', $key, $parts[ 0 ]) : $key; |
|
383 | + return [ $key, $value ]; |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | if ($this->isTypeField($subKey)) { |
387 | 387 | // Handle as a model type field. |
388 | 388 | list($key, $value) = $this->formatQueryElementRoot($subKey, $value, $metadata); |
389 | - $key = (true === $hasIndex) ? sprintf('%s.%s.%s', $root, $parts[0], $key) : sprintf('%s.%s', $root, $key); |
|
390 | - return [$key, $value]; |
|
389 | + $key = (true === $hasIndex) ? sprintf('%s.%s.%s', $root, $parts[ 0 ], $key) : sprintf('%s.%s', $root, $key); |
|
390 | + return [ $key, $value ]; |
|
391 | 391 | } |
392 | - return [$key, $value]; |
|
392 | + return [ $key, $value ]; |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -415,10 +415,10 @@ discard block |
||
415 | 415 | } |
416 | 416 | |
417 | 417 | if (is_array($value)) { |
418 | - $value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value]; |
|
419 | - return [$key, $this->formatQueryExpression($value, $converter)]; |
|
418 | + $value = (true === $this->hasOperators($value)) ? $value : [ '$in' => $value ]; |
|
419 | + return [ $key, $this->formatQueryExpression($value, $converter) ]; |
|
420 | 420 | } |
421 | - return [$key, $converter($value)]; |
|
421 | + return [ $key, $converter($value) ]; |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | |
@@ -443,10 +443,10 @@ discard block |
||
443 | 443 | |
444 | 444 | $converter = $this->getQueryRootConverter($metadata, $dbKey); |
445 | 445 | if (is_array($value)) { |
446 | - $value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value]; |
|
447 | - return [$dbKey, $this->formatQueryExpression($value, $converter)]; |
|
446 | + $value = (true === $this->hasOperators($value)) ? $value : [ '$in' => $value ]; |
|
447 | + return [ $dbKey, $this->formatQueryExpression($value, $converter) ]; |
|
448 | 448 | } |
449 | - return [$dbKey, $converter($value)]; |
|
449 | + return [ $dbKey, $converter($value) ]; |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -465,25 +465,25 @@ discard block |
||
465 | 465 | } |
466 | 466 | |
467 | 467 | if (true === $this->isOpType('single', $key)) { |
468 | - $expression[$key] = $converter($value); |
|
468 | + $expression[ $key ] = $converter($value); |
|
469 | 469 | continue; |
470 | 470 | } |
471 | 471 | |
472 | 472 | if (true === $this->isOpType('multiple', $key)) { |
473 | 473 | $value = (array) $value; |
474 | 474 | foreach ($value as $subKey => $subValue) { |
475 | - $expression[$key][$subKey] = $converter($subValue); |
|
475 | + $expression[ $key ][ $subKey ] = $converter($subValue); |
|
476 | 476 | } |
477 | 477 | continue; |
478 | 478 | } |
479 | 479 | |
480 | 480 | if (true === $this->isOpType('recursive', $key)) { |
481 | 481 | $value = (array) $value; |
482 | - $expression[$key] = $this->formatQueryExpression($value, $converter); |
|
482 | + $expression[ $key ] = $this->formatQueryExpression($value, $converter); |
|
483 | 483 | continue; |
484 | 484 | } |
485 | 485 | |
486 | - $expression[$key] = $converter($value); |
|
486 | + $expression[ $key ] = $converter($value); |
|
487 | 487 | } |
488 | 488 | return $expression; |
489 | 489 | } |
@@ -497,8 +497,8 @@ discard block |
||
497 | 497 | */ |
498 | 498 | private function getQueryAttrConverter(Store $store, AttributeMetadata $attrMeta) |
499 | 499 | { |
500 | - return function ($value) use ($store, $attrMeta) { |
|
501 | - if (in_array($attrMeta->dataType, ['object', 'array'])) { |
|
500 | + return function($value) use ($store, $attrMeta) { |
|
501 | + if (in_array($attrMeta->dataType, [ 'object', 'array' ])) { |
|
502 | 502 | // Leave the value as is. |
503 | 503 | return $value; |
504 | 504 | } |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | */ |
573 | 573 | private function isOperator($key) |
574 | 574 | { |
575 | - return isset($key[0]) && '$' === $key[0]; |
|
575 | + return isset($key[ 0 ]) && '$' === $key[ 0 ]; |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | /** |
@@ -584,9 +584,9 @@ discard block |
||
584 | 584 | */ |
585 | 585 | private function isOpType($type, $key) |
586 | 586 | { |
587 | - if (!isset($this->ops[$type])) { |
|
587 | + if (!isset($this->ops[ $type ])) { |
|
588 | 588 | return false; |
589 | 589 | } |
590 | - return in_array($key, $this->ops[$type]); |
|
590 | + return in_array($key, $this->ops[ $type ]); |
|
591 | 591 | } |
592 | 592 | } |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | * @var array |
28 | 28 | */ |
29 | 29 | private $changeSetMethods = [ |
30 | - 'attributes' => ['getAttribute', 'getAttributeDbValue'], |
|
31 | - 'hasOne' => ['getRelationship', 'getHasOneDbValue'], |
|
32 | - 'hasMany' => ['getRelationship', 'getHasManyDbValue'], |
|
33 | - 'embedOne' => ['getEmbed', 'getEmbedOneDbValue'], |
|
34 | - 'embedMany' => ['getEmbed', 'getEmbedManyDbValue'], |
|
30 | + 'attributes' => [ 'getAttribute', 'getAttributeDbValue' ], |
|
31 | + 'hasOne' => [ 'getRelationship', 'getHasOneDbValue' ], |
|
32 | + 'hasMany' => [ 'getRelationship', 'getHasManyDbValue' ], |
|
33 | + 'embedOne' => [ 'getEmbed', 'getEmbedOneDbValue' ], |
|
34 | + 'embedMany' => [ 'getEmbed', 'getEmbedManyDbValue' ], |
|
35 | 35 | ]; |
36 | 36 | |
37 | 37 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | /** |
70 | 70 | * {@inheritDoc} |
71 | 71 | */ |
72 | - public function all(EntityMetadata $metadata, Store $store, array $identifiers = []) |
|
72 | + public function all(EntityMetadata $metadata, Store $store, array $identifiers = [ ]) |
|
73 | 73 | { |
74 | 74 | $criteria = $this->getQuery()->getRetrieveCritiera($metadata, $identifiers); |
75 | 75 | $cursor = $this->getQuery()->executeFind($metadata, $store, $criteria); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | /** |
196 | 196 | * {@inheritDoc} |
197 | 197 | */ |
198 | - public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
198 | + public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
199 | 199 | { |
200 | 200 | $cursor = $this->getQuery()->executeFind($metadata, $store, $criteria); |
201 | 201 | return $this->getHydrator()->hydrateMany($metadata, $cursor->toArray(), $store); |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | |
249 | 249 | foreach ($this->changeSetMethods as $setKey => $methods) { |
250 | 250 | list($metaMethod, $formatMethod) = $methods; |
251 | - foreach ($changeset[$setKey] as $key => $values) { |
|
252 | - $value = $formatter->$formatMethod($metadata->$metaMethod($key), $values['new']); |
|
251 | + foreach ($changeset[ $setKey ] as $key => $values) { |
|
252 | + $value = $formatter->$formatMethod($metadata->$metaMethod($key), $values[ 'new' ]); |
|
253 | 253 | $obj = $handler($key, $value, $obj); |
254 | 254 | } |
255 | 255 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | $this->getIdentifierKey() => $this->convertId($model->getId()), |
270 | 270 | ]; |
271 | 271 | if (true === $metadata->isChildEntity()) { |
272 | - $insert[$this->getPolymorphicKey()] = $metadata->type; |
|
272 | + $insert[ $this->getPolymorphicKey() ] = $metadata->type; |
|
273 | 273 | } |
274 | 274 | return $this->appendChangeSet($model, $insert, $this->getCreateChangeSetHandler()); |
275 | 275 | } |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | */ |
283 | 283 | private function createUpdateObj(Model $model) |
284 | 284 | { |
285 | - return $this->appendChangeSet($model, [], $this->getUpdateChangeSetHandler()); |
|
285 | + return $this->appendChangeSet($model, [ ], $this->getUpdateChangeSetHandler()); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,9 +292,9 @@ discard block |
||
292 | 292 | */ |
293 | 293 | private function getCreateChangeSetHandler() |
294 | 294 | { |
295 | - return function ($key, $value, $obj) { |
|
295 | + return function($key, $value, $obj) { |
|
296 | 296 | if (null !== $value) { |
297 | - $obj[$key] = $value; |
|
297 | + $obj[ $key ] = $value; |
|
298 | 298 | } |
299 | 299 | return $obj; |
300 | 300 | }; |
@@ -307,13 +307,13 @@ discard block |
||
307 | 307 | */ |
308 | 308 | private function getUpdateChangeSetHandler() |
309 | 309 | { |
310 | - return function ($key, $value, $obj) { |
|
310 | + return function($key, $value, $obj) { |
|
311 | 311 | $op = '$set'; |
312 | 312 | if (null === $value) { |
313 | 313 | $op = '$unset'; |
314 | 314 | $value = 1; |
315 | 315 | } |
316 | - $obj[$op][$key] = $value; |
|
316 | + $obj[ $op ][ $key ] = $value; |
|
317 | 317 | return $obj; |
318 | 318 | }; |
319 | 319 | } |