@@ -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 | } |
@@ -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 | /** |
@@ -198,8 +198,8 @@ discard block |
||
| 198 | 198 | { |
| 199 | 199 | $identifier = $this->getIdentifierDbValue($model->getId()); |
| 200 | 200 | if (true === $relMeta->isPolymorphic()) { |
| 201 | - $reference[$this->getIdentifierKey()] = $identifier; |
|
| 202 | - $reference[$this->getPolymorphicKey()] = $model->getType(); |
|
| 201 | + $reference[ $this->getIdentifierKey() ] = $identifier; |
|
| 202 | + $reference[ $this->getPolymorphicKey() ] = $model->getType(); |
|
| 203 | 203 | return $reference; |
| 204 | 204 | } |
| 205 | 205 | return $identifier; |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Pass remaining elements unconverted. |
| 246 | - return [$key, $value]; |
|
| 246 | + return [ $key, $value ]; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -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 | /** |
@@ -374,10 +374,10 @@ discard block |
||
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | if (is_array($value)) { |
| 377 | - $value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value]; |
|
| 378 | - return [$key, $this->formatQueryExpression($value, $converter)]; |
|
| 377 | + $value = (true === $this->hasOperators($value)) ? $value : [ '$in' => $value ]; |
|
| 378 | + return [ $key, $this->formatQueryExpression($value, $converter) ]; |
|
| 379 | 379 | } |
| 380 | - return [$key, $converter($value)]; |
|
| 380 | + return [ $key, $converter($value) ]; |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -398,10 +398,10 @@ discard block |
||
| 398 | 398 | $converter = $this->getQueryTypeConverter(); |
| 399 | 399 | |
| 400 | 400 | if (is_array($value)) { |
| 401 | - $value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value]; |
|
| 402 | - return [$dbTypeKey, $this->formatQueryExpression($value, $converter)]; |
|
| 401 | + $value = (true === $this->hasOperators($value)) ? $value : [ '$in' => $value ]; |
|
| 402 | + return [ $dbTypeKey, $this->formatQueryExpression($value, $converter) ]; |
|
| 403 | 403 | } |
| 404 | - return [$dbTypeKey, $converter($value)]; |
|
| 404 | + return [ $dbTypeKey, $converter($value) ]; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /** |
@@ -420,25 +420,25 @@ discard block |
||
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | if (true === $this->isOpType('single', $key)) { |
| 423 | - $expression[$key] = $converter($value); |
|
| 423 | + $expression[ $key ] = $converter($value); |
|
| 424 | 424 | continue; |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | if (true === $this->isOpType('multiple', $key)) { |
| 428 | 428 | $value = (array) $value; |
| 429 | 429 | foreach ($value as $subKey => $subValue) { |
| 430 | - $expression[$key][$subKey] = $converter($subValue); |
|
| 430 | + $expression[ $key ][ $subKey ] = $converter($subValue); |
|
| 431 | 431 | } |
| 432 | 432 | continue; |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | if (true === $this->isOpType('recursive', $key)) { |
| 436 | 436 | $value = (array) $value; |
| 437 | - $expression[$key] = $this->formatQueryExpression($value, $converter); |
|
| 437 | + $expression[ $key ] = $this->formatQueryExpression($value, $converter); |
|
| 438 | 438 | continue; |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | - $expression[$key] = $converter($value); |
|
| 441 | + $expression[ $key ] = $converter($value); |
|
| 442 | 442 | } |
| 443 | 443 | return $expression; |
| 444 | 444 | } |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | */ |
| 453 | 453 | private function getQueryAttrConverter(Store $store, AttributeMetadata $attrMeta) |
| 454 | 454 | { |
| 455 | - return function ($value) use ($store, $attrMeta) { |
|
| 455 | + return function($value) use ($store, $attrMeta) { |
|
| 456 | 456 | $value = $store->convertAttributeValue($attrMeta->dataType, $value); |
| 457 | 457 | return $this->getAttributeDbValue($attrMeta, $value); |
| 458 | 458 | }; |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | */ |
| 531 | 531 | private function isOperator($key) |
| 532 | 532 | { |
| 533 | - return isset($key[0]) && '$' === $key[0]; |
|
| 533 | + return isset($key[ 0 ]) && '$' === $key[ 0 ]; |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -542,9 +542,9 @@ discard block |
||
| 542 | 542 | */ |
| 543 | 543 | private function isOpType($type, $key) |
| 544 | 544 | { |
| 545 | - if (!isset($this->ops[$type])) { |
|
| 545 | + if (!isset($this->ops[ $type ])) { |
|
| 546 | 546 | return false; |
| 547 | 547 | } |
| 548 | - return in_array($key, $this->ops[$type]); |
|
| 548 | + return in_array($key, $this->ops[ $type ]); |
|
| 549 | 549 | } |
| 550 | 550 | } |
@@ -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->prepareAttribute($metadata->getAttribute($key), $values['new']); |
|
| 133 | + foreach ($changeset[ 'attributes' ] as $key => $values) { |
|
| 134 | + $value = $this->prepareAttribute($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->prepareHasOne($metadata->getRelationship($key), $values['new']); |
|
| 140 | + foreach ($changeset[ 'hasOne' ] as $key => $values) { |
|
| 141 | + $value = $this->prepareHasOne($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->prepareHasMany($metadata->getRelationship($key), $values['new']); |
|
| 147 | + foreach ($changeset[ 'hasMany' ] as $key => $values) { |
|
| 148 | + $value = $this->prepareHasMany($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() |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | if (null === $models || true === $relMeta->isInverse) { |
| 207 | 207 | return null; |
| 208 | 208 | } |
| 209 | - $references = []; |
|
| 209 | + $references = [ ]; |
|
| 210 | 210 | foreach ($models as $model) { |
| 211 | - $references[] = $this->createReference($relMeta, $model); |
|
| 211 | + $references[ ] = $this->createReference($relMeta, $model); |
|
| 212 | 212 | } |
| 213 | 213 | return empty($references) ? null : $references; |
| 214 | 214 | } |
@@ -224,8 +224,8 @@ discard block |
||
| 224 | 224 | protected function createReference(RelationshipMetadata $relMeta, Model $model) |
| 225 | 225 | { |
| 226 | 226 | if (true === $relMeta->isPolymorphic()) { |
| 227 | - $reference[$this->getIdentifierKey()] = $this->convertId($model->getId()); |
|
| 228 | - $reference[$this->getPolymorphicKey()] = $model->getType(); |
|
| 227 | + $reference[ $this->getIdentifierKey() ] = $this->convertId($model->getId()); |
|
| 228 | + $reference[ $this->getPolymorphicKey() ] = $model->getType(); |
|
| 229 | 229 | return $reference; |
| 230 | 230 | } |
| 231 | 231 | return $this->convertId($model->getId()); |
@@ -241,39 +241,39 @@ discard block |
||
| 241 | 241 | $criteria = $this->getRetrieveCritiera($metadata, $model->getId()); |
| 242 | 242 | $changeset = $model->getChangeSet(); |
| 243 | 243 | |
| 244 | - $update = []; |
|
| 245 | - foreach ($changeset['attributes'] as $key => $values) { |
|
| 246 | - if (null === $values['new']) { |
|
| 244 | + $update = [ ]; |
|
| 245 | + foreach ($changeset[ 'attributes' ] as $key => $values) { |
|
| 246 | + if (null === $values[ 'new' ]) { |
|
| 247 | 247 | $op = '$unset'; |
| 248 | 248 | $value = 1; |
| 249 | 249 | } else { |
| 250 | 250 | $op = '$set'; |
| 251 | - $value = $this->prepareAttribute($metadata->getAttribute($key), $values['new']); |
|
| 251 | + $value = $this->prepareAttribute($metadata->getAttribute($key), $values[ 'new' ]); |
|
| 252 | 252 | } |
| 253 | - $update[$op][$key] = $value; |
|
| 253 | + $update[ $op ][ $key ] = $value; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // @todo Must prevent inverse relationships from persisting |
| 257 | - foreach ($changeset['hasOne'] as $key => $values) { |
|
| 258 | - if (null === $values['new']) { |
|
| 257 | + foreach ($changeset[ 'hasOne' ] as $key => $values) { |
|
| 258 | + if (null === $values[ 'new' ]) { |
|
| 259 | 259 | $op = '$unset'; |
| 260 | 260 | $value = 1; |
| 261 | 261 | } else { |
| 262 | 262 | $op = '$set'; |
| 263 | - $value = $this->prepareHasOne($metadata->getRelationship($key), $values['new']); |
|
| 263 | + $value = $this->prepareHasOne($metadata->getRelationship($key), $values[ 'new' ]); |
|
| 264 | 264 | } |
| 265 | - $update[$op][$key] = $value; |
|
| 265 | + $update[ $op ][ $key ] = $value; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - foreach ($changeset['hasMany'] as $key => $values) { |
|
| 269 | - if (null === $values['new']) { |
|
| 268 | + foreach ($changeset[ 'hasMany' ] as $key => $values) { |
|
| 269 | + if (null === $values[ 'new' ]) { |
|
| 270 | 270 | $op = '$unset'; |
| 271 | 271 | $value = 1; |
| 272 | 272 | } else { |
| 273 | 273 | $op = '$set'; |
| 274 | - $value = $this->prepareHasMany($metadata->getRelationship($key), $values['new']); |
|
| 274 | + $value = $this->prepareHasMany($metadata->getRelationship($key), $values[ 'new' ]); |
|
| 275 | 275 | } |
| 276 | - $update[$op][$key] = $value; |
|
| 276 | + $update[ $op ][ $key ] = $value; |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | if (empty($update)) { |
@@ -358,10 +358,10 @@ discard block |
||
| 358 | 358 | if (false === $metadata->isPolymorphic()) { |
| 359 | 359 | return $metadata->type; |
| 360 | 360 | } |
| 361 | - if (!isset($data[$this->getPolymorphicKey()])) { |
|
| 361 | + if (!isset($data[ $this->getPolymorphicKey() ])) { |
|
| 362 | 362 | throw PersisterException::badRequest(sprintf('Unable to extract polymorphic type. The "%s" key was not found.', $this->getPolymorphicKey())); |
| 363 | 363 | } |
| 364 | - return $data[$this->getPolymorphicKey()]; |
|
| 364 | + return $data[ $this->getPolymorphicKey() ]; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | * @param int $limit The number of Models to limit. |
| 377 | 377 | * @return \Doctrine\MongoDB\Cursor |
| 378 | 378 | */ |
| 379 | - protected function doQuery(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
| 379 | + protected function doQuery(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
| 380 | 380 | { |
| 381 | 381 | $criteria = $this->getFormatter()->formatQuery($metadata, $store, $criteria); |
| 382 | 382 | return $this->createQueryBuilder($metadata) |
@@ -397,9 +397,9 @@ discard block |
||
| 397 | 397 | */ |
| 398 | 398 | protected function hydrateRecords(EntityMetadata $metadata, array $results, Store $store) |
| 399 | 399 | { |
| 400 | - $records = []; |
|
| 400 | + $records = [ ]; |
|
| 401 | 401 | foreach ($results as $data) { |
| 402 | - $records[] = $this->hydrateRecord($metadata, $data, $store); |
|
| 402 | + $records[ ] = $this->hydrateRecord($metadata, $data, $store); |
|
| 403 | 403 | } |
| 404 | 404 | return $records; |
| 405 | 405 | } |
@@ -414,27 +414,27 @@ discard block |
||
| 414 | 414 | */ |
| 415 | 415 | protected function hydrateRecord(EntityMetadata $metadata, array $data, Store $store) |
| 416 | 416 | { |
| 417 | - $identifier = $data[$this->getIdentifierKey()]; |
|
| 418 | - unset($data[$this->getIdentifierKey()]); |
|
| 417 | + $identifier = $data[ $this->getIdentifierKey() ]; |
|
| 418 | + unset($data[ $this->getIdentifierKey() ]); |
|
| 419 | 419 | |
| 420 | 420 | $type = $this->extractType($metadata, $data); |
| 421 | - unset($data[$this->getPolymorphicKey()]); |
|
| 421 | + unset($data[ $this->getPolymorphicKey() ]); |
|
| 422 | 422 | |
| 423 | 423 | $metadata = $store->getMetadataForType($type); |
| 424 | 424 | foreach ($metadata->getRelationships() as $key => $relMeta) { |
| 425 | - if (!isset($data[$key])) { |
|
| 425 | + if (!isset($data[ $key ])) { |
|
| 426 | 426 | continue; |
| 427 | 427 | } |
| 428 | - if (true === $relMeta->isMany() && !is_array($data[$key])) { |
|
| 429 | - 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)); |
|
| 428 | + if (true === $relMeta->isMany() && !is_array($data[ $key ])) { |
|
| 429 | + 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)); |
|
| 430 | 430 | } |
| 431 | - $references = $relMeta->isOne() ? [$data[$key]] : $data[$key]; |
|
| 431 | + $references = $relMeta->isOne() ? [ $data[ $key ] ] : $data[ $key ]; |
|
| 432 | 432 | |
| 433 | - $extracted = []; |
|
| 433 | + $extracted = [ ]; |
|
| 434 | 434 | foreach ($references as $reference) { |
| 435 | - $extracted[] = $this->extractRelationship($relMeta, $reference); |
|
| 435 | + $extracted[ ] = $this->extractRelationship($relMeta, $reference); |
|
| 436 | 436 | } |
| 437 | - $data[$key] = $relMeta->isOne() ? reset($extracted) : $extracted; |
|
| 437 | + $data[ $key ] = $relMeta->isOne() ? reset($extracted) : $extracted; |
|
| 438 | 438 | } |
| 439 | 439 | return new Record($type, $identifier, $data); |
| 440 | 440 | } |
@@ -452,9 +452,9 @@ discard block |
||
| 452 | 452 | $simple = false === $relMeta->isPolymorphic(); |
| 453 | 453 | $idKey = $this->getIdentifierKey(); |
| 454 | 454 | $typeKey = $this->getPolymorphicKey(); |
| 455 | - if (true === $simple && is_array($reference) && isset($reference[$idKey])) { |
|
| 455 | + if (true === $simple && is_array($reference) && isset($reference[ $idKey ])) { |
|
| 456 | 456 | return [ |
| 457 | - 'id' => $reference[$idKey], |
|
| 457 | + 'id' => $reference[ $idKey ], |
|
| 458 | 458 | 'type' => $relMeta->getEntityType(), |
| 459 | 459 | ]; |
| 460 | 460 | } elseif (true === $simple && !is_array($reference)) { |
@@ -462,10 +462,10 @@ discard block |
||
| 462 | 462 | 'id' => $reference, |
| 463 | 463 | 'type' => $relMeta->getEntityType(), |
| 464 | 464 | ]; |
| 465 | - } elseif (false === $simple && is_array($reference) && isset($reference[$idKey]) && isset($reference[$typeKey])) { |
|
| 465 | + } elseif (false === $simple && is_array($reference) && isset($reference[ $idKey ]) && isset($reference[ $typeKey ])) { |
|
| 466 | 466 | return [ |
| 467 | - 'id' => $reference[$idKey], |
|
| 468 | - 'type' => $reference[$typeKey], |
|
| 467 | + 'id' => $reference[ $idKey ], |
|
| 468 | + 'type' => $reference[ $typeKey ], |
|
| 469 | 469 | ]; |
| 470 | 470 | } else { |
| 471 | 471 | throw new RuntimeException('Unable to extract a reference id.'); |
@@ -481,17 +481,17 @@ discard block |
||
| 481 | 481 | */ |
| 482 | 482 | protected function getInverseCriteria(EntityMetadata $owner, EntityMetadata $related, $identifiers, $inverseField) |
| 483 | 483 | { |
| 484 | - $criteria[$inverseField] = $this->getIdentifierCriteria($identifiers); |
|
| 484 | + $criteria[ $inverseField ] = $this->getIdentifierCriteria($identifiers); |
|
| 485 | 485 | if (true === $owner->isChildEntity()) { |
| 486 | 486 | // The owner is owned by a polymorphic model. Must include the type with the inverse field criteria. |
| 487 | - $criteria[$inverseField] = [ |
|
| 488 | - $this->getIdentifierKey() => $criteria[$inverseField], |
|
| 487 | + $criteria[ $inverseField ] = [ |
|
| 488 | + $this->getIdentifierKey() => $criteria[ $inverseField ], |
|
| 489 | 489 | $this->getPolymorphicKey() => $owner->type, |
| 490 | 490 | ]; |
| 491 | 491 | } |
| 492 | 492 | if (true === $related->isChildEntity()) { |
| 493 | 493 | // The relationship is owned by a polymorphic model. Must include the type in the root criteria. |
| 494 | - $criteria[$this->getPolymorphicKey()] = $related->type; |
|
| 494 | + $criteria[ $this->getPolymorphicKey() ] = $related->type; |
|
| 495 | 495 | } |
| 496 | 496 | return $criteria; |
| 497 | 497 | } |
@@ -505,9 +505,9 @@ discard block |
||
| 505 | 505 | */ |
| 506 | 506 | protected function getRetrieveCritiera(EntityMetadata $metadata, $identifiers = null) |
| 507 | 507 | { |
| 508 | - $criteria = []; |
|
| 508 | + $criteria = [ ]; |
|
| 509 | 509 | if (true === $metadata->isChildEntity()) { |
| 510 | - $criteria[$this->getPolymorphicKey()] = $metadata->type; |
|
| 510 | + $criteria[ $this->getPolymorphicKey() ] = $metadata->type; |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | if (null === $identifiers) { |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | if (empty($identifiers)) { |
| 518 | 518 | return $criteria; |
| 519 | 519 | } |
| 520 | - $criteria[$this->getIdentifierKey()] = (1 === count($identifiers)) ? $identifiers[0] : $identifiers; |
|
| 520 | + $criteria[ $this->getIdentifierKey() ] = (1 === count($identifiers)) ? $identifiers[ 0 ] : $identifiers; |
|
| 521 | 521 | return $criteria; |
| 522 | 522 | } |
| 523 | 523 | |