| @@ -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 | /** | 
| @@ -461,7 +461,7 @@ discard block | ||
| 461 | 461 |          foreach ($expression as $key => $value) { | 
| 462 | 462 | |
| 463 | 463 |              if ('$regex' === $key && !$value instanceof \MongoRegex) { | 
| 464 | - $expression[$key] = new \MongoRegex($value); | |
| 464 | + $expression[ $key ] = new \MongoRegex($value); | |
| 465 | 465 | continue; | 
| 466 | 466 | } | 
| 467 | 467 | |
| @@ -470,25 +470,25 @@ discard block | ||
| 470 | 470 | } | 
| 471 | 471 | |
| 472 | 472 |              if (true === $this->isOpType('single', $key)) { | 
| 473 | - $expression[$key] = $converter($value); | |
| 473 | + $expression[ $key ] = $converter($value); | |
| 474 | 474 | continue; | 
| 475 | 475 | } | 
| 476 | 476 | |
| 477 | 477 |              if (true === $this->isOpType('multiple', $key)) { | 
| 478 | 478 | $value = (array) $value; | 
| 479 | 479 |                  foreach ($value as $subKey => $subValue) { | 
| 480 | - $expression[$key][$subKey] = $converter($subValue); | |
| 480 | + $expression[ $key ][ $subKey ] = $converter($subValue); | |
| 481 | 481 | } | 
| 482 | 482 | continue; | 
| 483 | 483 | } | 
| 484 | 484 | |
| 485 | 485 |              if (true === $this->isOpType('recursive', $key)) { | 
| 486 | 486 | $value = (array) $value; | 
| 487 | - $expression[$key] = $this->formatQueryExpression($value, $converter); | |
| 487 | + $expression[ $key ] = $this->formatQueryExpression($value, $converter); | |
| 488 | 488 | continue; | 
| 489 | 489 | } | 
| 490 | 490 | |
| 491 | - $expression[$key] = $converter($value); | |
| 491 | + $expression[ $key ] = $converter($value); | |
| 492 | 492 | } | 
| 493 | 493 | return $expression; | 
| 494 | 494 | } | 
| @@ -502,8 +502,8 @@ discard block | ||
| 502 | 502 | */ | 
| 503 | 503 | private function getQueryAttrConverter(Store $store, AttributeMetadata $attrMeta) | 
| 504 | 504 |      { | 
| 505 | -        return function ($value) use ($store, $attrMeta) { | |
| 506 | -            if (in_array($attrMeta->dataType, ['object', 'array'])) { | |
| 505 | +        return function($value) use ($store, $attrMeta) { | |
| 506 | +            if (in_array($attrMeta->dataType, [ 'object', 'array' ])) { | |
| 507 | 507 | // Leave the value as is. | 
| 508 | 508 | return $value; | 
| 509 | 509 | } | 
| @@ -577,7 +577,7 @@ discard block | ||
| 577 | 577 | */ | 
| 578 | 578 | private function isOperator($key) | 
| 579 | 579 |      { | 
| 580 | - return isset($key[0]) && '$' === $key[0]; | |
| 580 | + return isset($key[ 0 ]) && '$' === $key[ 0 ]; | |
| 581 | 581 | } | 
| 582 | 582 | |
| 583 | 583 | /** | 
| @@ -589,9 +589,9 @@ discard block | ||
| 589 | 589 | */ | 
| 590 | 590 | private function isOpType($type, $key) | 
| 591 | 591 |      { | 
| 592 | -        if (!isset($this->ops[$type])) { | |
| 592 | +        if (!isset($this->ops[ $type ])) { | |
| 593 | 593 | return false; | 
| 594 | 594 | } | 
| 595 | - return in_array($key, $this->ops[$type]); | |
| 595 | + return in_array($key, $this->ops[ $type ]); | |
| 596 | 596 | } | 
| 597 | 597 | } |