| @@ -445,8 +445,8 @@ | ||
| 445 | 445 | /** | 
| 446 | 446 | * Gets standard database retrieval criteria for an inverse relationship. | 
| 447 | 447 | * | 
| 448 | - * @param EntityMetadata $metadata The entity to retrieve database records for. | |
| 449 | 448 | * @param string|array $identifiers The IDs to query. | 
| 449 | + * @param string $inverseField | |
| 450 | 450 | * @return array | 
| 451 | 451 | */ | 
| 452 | 452 | protected function getInverseCriteria(EntityMetadata $owner, EntityMetadata $related, $identifiers, $inverseField) | 
| @@ -69,7 +69,7 @@ discard block | ||
| 69 | 69 |       * {@inheritDoc} | 
| 70 | 70 | * @todo Implement sorting and pagination (limit/skip). | 
| 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->getRetrieveCritiera($metadata, $identifiers); | 
| 75 | 75 | $cursor = $this->findFromDatabase($metadata, $criteria); | 
| @@ -106,32 +106,32 @@ discard block | ||
| 106 | 106 | public function create(Model $model) | 
| 107 | 107 |      { | 
| 108 | 108 | $metadata = $model->getMetadata(); | 
| 109 | - $insert[$this->getIdentifierKey()] = $this->convertId($model->getId()); | |
| 109 | + $insert[ $this->getIdentifierKey() ] = $this->convertId($model->getId()); | |
| 110 | 110 |          if (true === $metadata->isChildEntity()) { | 
| 111 | - $insert[$this->getPolymorphicKey()] = $metadata->type; | |
| 111 | + $insert[ $this->getPolymorphicKey() ] = $metadata->type; | |
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | 114 | $changeset = $model->getChangeSet(); | 
| 115 | -        foreach ($changeset['attributes'] as $key => $values) { | |
| 116 | - $value = $this->prepareAttribute($metadata->getAttribute($key), $values['new']); | |
| 115 | +        foreach ($changeset[ 'attributes' ] as $key => $values) { | |
| 116 | + $value = $this->prepareAttribute($metadata->getAttribute($key), $values[ 'new' ]); | |
| 117 | 117 |              if (null === $value) { | 
| 118 | 118 | continue; | 
| 119 | 119 | } | 
| 120 | - $insert[$key] = $value; | |
| 120 | + $insert[ $key ] = $value; | |
| 121 | 121 | } | 
| 122 | -        foreach ($changeset['hasOne'] as $key => $values) { | |
| 123 | - $value = $this->prepareHasOne($metadata->getRelationship($key), $values['new']); | |
| 122 | +        foreach ($changeset[ 'hasOne' ] as $key => $values) { | |
| 123 | + $value = $this->prepareHasOne($metadata->getRelationship($key), $values[ 'new' ]); | |
| 124 | 124 |              if (null === $value) { | 
| 125 | 125 | continue; | 
| 126 | 126 | } | 
| 127 | - $insert[$key] = $value; | |
| 127 | + $insert[ $key ] = $value; | |
| 128 | 128 | } | 
| 129 | -        foreach ($changeset['hasMany'] as $key => $values) { | |
| 130 | - $value = $this->prepareHasMany($metadata->getRelationship($key), $values['new']); | |
| 129 | +        foreach ($changeset[ 'hasMany' ] as $key => $values) { | |
| 130 | + $value = $this->prepareHasMany($metadata->getRelationship($key), $values[ 'new' ]); | |
| 131 | 131 |              if (null === $value) { | 
| 132 | 132 | continue; | 
| 133 | 133 | } | 
| 134 | - $insert[$key] = $value; | |
| 134 | + $insert[ $key ] = $value; | |
| 135 | 135 | } | 
| 136 | 136 | $this->createQueryBuilder($metadata) | 
| 137 | 137 | ->insert() | 
| @@ -185,9 +185,9 @@ discard block | ||
| 185 | 185 |          if (null === $models || true === $relMeta->isInverse) { | 
| 186 | 186 | return null; | 
| 187 | 187 | } | 
| 188 | - $references = []; | |
| 188 | + $references = [ ]; | |
| 189 | 189 |          foreach ($models as $model) { | 
| 190 | - $references[] = $this->createReference($relMeta, $model); | |
| 190 | + $references[ ] = $this->createReference($relMeta, $model); | |
| 191 | 191 | } | 
| 192 | 192 | return empty($references) ? null : $references; | 
| 193 | 193 | } | 
| @@ -202,8 +202,8 @@ discard block | ||
| 202 | 202 | protected function createReference(RelationshipMetadata $relMeta, Model $model) | 
| 203 | 203 |      { | 
| 204 | 204 |          if (true === $relMeta->isPolymorphic()) { | 
| 205 | - $reference[$this->getIdentifierKey()] = $this->convertId($model->getId()); | |
| 206 | - $reference[$this->getPolymorphicKey()] = $model->getType(); | |
| 205 | + $reference[ $this->getIdentifierKey() ] = $this->convertId($model->getId()); | |
| 206 | + $reference[ $this->getPolymorphicKey() ] = $model->getType(); | |
| 207 | 207 | return $reference; | 
| 208 | 208 | } | 
| 209 | 209 | return $this->convertId($model->getId()); | 
| @@ -219,39 +219,39 @@ discard block | ||
| 219 | 219 | $criteria = $this->getRetrieveCritiera($metadata, $model->getId()); | 
| 220 | 220 | $changeset = $model->getChangeSet(); | 
| 221 | 221 | |
| 222 | - $update = []; | |
| 223 | -        foreach ($changeset['attributes'] as $key => $values) { | |
| 224 | -            if (null === $values['new']) { | |
| 222 | + $update = [ ]; | |
| 223 | +        foreach ($changeset[ 'attributes' ] as $key => $values) { | |
| 224 | +            if (null === $values[ 'new' ]) { | |
| 225 | 225 | $op = '$unset'; | 
| 226 | 226 | $value = 1; | 
| 227 | 227 |              } else { | 
| 228 | 228 | $op = '$set'; | 
| 229 | - $value = $this->prepareAttribute($metadata->getAttribute($key), $values['new']); | |
| 229 | + $value = $this->prepareAttribute($metadata->getAttribute($key), $values[ 'new' ]); | |
| 230 | 230 | } | 
| 231 | - $update[$op][$key] = $value; | |
| 231 | + $update[ $op ][ $key ] = $value; | |
| 232 | 232 | } | 
| 233 | 233 | |
| 234 | 234 | // @todo Must prevent inverse relationships from persisting | 
| 235 | -        foreach ($changeset['hasOne'] as $key => $values) { | |
| 236 | -            if (null === $values['new']) { | |
| 235 | +        foreach ($changeset[ 'hasOne' ] as $key => $values) { | |
| 236 | +            if (null === $values[ 'new' ]) { | |
| 237 | 237 | $op = '$unset'; | 
| 238 | 238 | $value = 1; | 
| 239 | 239 |              } else { | 
| 240 | 240 | $op = '$set'; | 
| 241 | - $value = $this->prepareHasOne($metadata->getRelationship($key), $values['new']); | |
| 241 | + $value = $this->prepareHasOne($metadata->getRelationship($key), $values[ 'new' ]); | |
| 242 | 242 | } | 
| 243 | - $update[$op][$key] = $value; | |
| 243 | + $update[ $op ][ $key ] = $value; | |
| 244 | 244 | } | 
| 245 | 245 | |
| 246 | -        foreach ($changeset['hasMany'] as $key => $values) { | |
| 247 | -            if (null === $values['new']) { | |
| 246 | +        foreach ($changeset[ 'hasMany' ] as $key => $values) { | |
| 247 | +            if (null === $values[ 'new' ]) { | |
| 248 | 248 | $op = '$unset'; | 
| 249 | 249 | $value = 1; | 
| 250 | 250 |              } else { | 
| 251 | 251 | $op = '$set'; | 
| 252 | - $value = $this->prepareHasMany($metadata->getRelationship($key), $values['new']); | |
| 252 | + $value = $this->prepareHasMany($metadata->getRelationship($key), $values[ 'new' ]); | |
| 253 | 253 | } | 
| 254 | - $update[$op][$key] = $value; | |
| 254 | + $update[ $op ][ $key ] = $value; | |
| 255 | 255 | } | 
| 256 | 256 | |
| 257 | 257 |          if (empty($update)) { | 
| @@ -334,10 +334,10 @@ discard block | ||
| 334 | 334 |          if (false === $metadata->isPolymorphic()) { | 
| 335 | 335 | return $metadata->type; | 
| 336 | 336 | } | 
| 337 | -        if (!isset($data[$this->getPolymorphicKey()])) { | |
| 337 | +        if (!isset($data[ $this->getPolymorphicKey() ])) { | |
| 338 | 338 |              throw PersisterException::badRequest(sprintf('Unable to extract polymorphic type. The "%s" key was not found.', $this->getPolymorphicKey())); | 
| 339 | 339 | } | 
| 340 | - return $data[$this->getPolymorphicKey()]; | |
| 340 | + return $data[ $this->getPolymorphicKey() ]; | |
| 341 | 341 | } | 
| 342 | 342 | |
| 343 | 343 | /** | 
| @@ -367,9 +367,9 @@ discard block | ||
| 367 | 367 | */ | 
| 368 | 368 | protected function hydrateRecords(EntityMetadata $metadata, array $results, Store $store) | 
| 369 | 369 |      { | 
| 370 | - $records = []; | |
| 370 | + $records = [ ]; | |
| 371 | 371 |          foreach ($results as $data) { | 
| 372 | - $records[] = $this->hydrateRecord($metadata, $data, $store); | |
| 372 | + $records[ ] = $this->hydrateRecord($metadata, $data, $store); | |
| 373 | 373 | } | 
| 374 | 374 | return $records; | 
| 375 | 375 | } | 
| @@ -384,27 +384,27 @@ discard block | ||
| 384 | 384 | */ | 
| 385 | 385 | protected function hydrateRecord(EntityMetadata $metadata, array $data, Store $store) | 
| 386 | 386 |      { | 
| 387 | - $identifier = $data[$this->getIdentifierKey()]; | |
| 388 | - unset($data[$this->getIdentifierKey()]); | |
| 387 | + $identifier = $data[ $this->getIdentifierKey() ]; | |
| 388 | + unset($data[ $this->getIdentifierKey() ]); | |
| 389 | 389 | |
| 390 | 390 | $type = $this->extractType($metadata, $data); | 
| 391 | - unset($data[$this->getPolymorphicKey()]); | |
| 391 | + unset($data[ $this->getPolymorphicKey() ]); | |
| 392 | 392 | |
| 393 | 393 | $metadata = $store->getMetadataForType($type); | 
| 394 | 394 |          foreach ($metadata->getRelationships() as $key => $relMeta) { | 
| 395 | -            if (!isset($data[$key])) { | |
| 395 | +            if (!isset($data[ $key ])) { | |
| 396 | 396 | continue; | 
| 397 | 397 | } | 
| 398 | -            if (true === $relMeta->isMany() && !is_array($data[$key])) { | |
| 399 | -                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)); | |
| 398 | +            if (true === $relMeta->isMany() && !is_array($data[ $key ])) { | |
| 399 | +                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)); | |
| 400 | 400 | } | 
| 401 | - $references = $relMeta->isOne() ? [$data[$key]] : $data[$key]; | |
| 401 | + $references = $relMeta->isOne() ? [ $data[ $key ] ] : $data[ $key ]; | |
| 402 | 402 | |
| 403 | - $extracted = []; | |
| 403 | + $extracted = [ ]; | |
| 404 | 404 |              foreach ($references as $reference) { | 
| 405 | - $extracted[] = $this->extractRelationship($relMeta, $reference); | |
| 405 | + $extracted[ ] = $this->extractRelationship($relMeta, $reference); | |
| 406 | 406 | } | 
| 407 | - $data[$key] = $relMeta->isOne() ? reset($extracted) : $extracted; | |
| 407 | + $data[ $key ] = $relMeta->isOne() ? reset($extracted) : $extracted; | |
| 408 | 408 | } | 
| 409 | 409 | return new Record($type, $identifier, $data); | 
| 410 | 410 | } | 
| @@ -422,9 +422,9 @@ discard block | ||
| 422 | 422 | $simple = false === $relMeta->isPolymorphic(); | 
| 423 | 423 | $idKey = $this->getIdentifierKey(); | 
| 424 | 424 | $typeKey = $this->getPolymorphicKey(); | 
| 425 | -        if (true === $simple && is_array($reference) && isset($reference[$idKey])) { | |
| 425 | +        if (true === $simple && is_array($reference) && isset($reference[ $idKey ])) { | |
| 426 | 426 | return [ | 
| 427 | - 'id' => $reference[$idKey], | |
| 427 | + 'id' => $reference[ $idKey ], | |
| 428 | 428 | 'type' => $relMeta->getEntityType(), | 
| 429 | 429 | ]; | 
| 430 | 430 |          } elseif (true === $simple && !is_array($reference)) { | 
| @@ -432,10 +432,10 @@ discard block | ||
| 432 | 432 | 'id' => $reference, | 
| 433 | 433 | 'type' => $relMeta->getEntityType(), | 
| 434 | 434 | ]; | 
| 435 | -        } elseif (false === $simple && is_array($reference) && isset($reference[$idKey]) && isset($reference[$typeKey])) { | |
| 435 | +        } elseif (false === $simple && is_array($reference) && isset($reference[ $idKey ]) && isset($reference[ $typeKey ])) { | |
| 436 | 436 | return [ | 
| 437 | - 'id' => $reference[$idKey], | |
| 438 | - 'type' => $reference[$typeKey], | |
| 437 | + 'id' => $reference[ $idKey ], | |
| 438 | + 'type' => $reference[ $typeKey ], | |
| 439 | 439 | ]; | 
| 440 | 440 |          } else { | 
| 441 | 441 |              throw new RuntimeException('Unable to extract a reference id.'); | 
| @@ -451,17 +451,17 @@ discard block | ||
| 451 | 451 | */ | 
| 452 | 452 | protected function getInverseCriteria(EntityMetadata $owner, EntityMetadata $related, $identifiers, $inverseField) | 
| 453 | 453 |      { | 
| 454 | - $criteria[$inverseField] = $this->getIdentifierCriteria($identifiers); | |
| 454 | + $criteria[ $inverseField ] = $this->getIdentifierCriteria($identifiers); | |
| 455 | 455 |          if (true === $owner->isChildEntity()) { | 
| 456 | 456 | // The owner is owned by a polymorphic model. Must include the type with the inverse field criteria. | 
| 457 | - $criteria[$inverseField] = [ | |
| 458 | - $this->getIdentifierKey() => $criteria[$inverseField], | |
| 457 | + $criteria[ $inverseField ] = [ | |
| 458 | + $this->getIdentifierKey() => $criteria[ $inverseField ], | |
| 459 | 459 | $this->getPolymorphicKey() => $owner->type, | 
| 460 | 460 | ]; | 
| 461 | 461 | } | 
| 462 | 462 |          if (true === $related->isChildEntity()) { | 
| 463 | 463 | // The relationship is owned by a polymorphic model. Must include the type in the root criteria. | 
| 464 | - $criteria[$this->getPolymorphicKey()] = $related->type; | |
| 464 | + $criteria[ $this->getPolymorphicKey() ] = $related->type; | |
| 465 | 465 | } | 
| 466 | 466 | return $criteria; | 
| 467 | 467 | } | 
| @@ -476,12 +476,12 @@ discard block | ||
| 476 | 476 | protected function getRetrieveCritiera(EntityMetadata $metadata, $identifiers) | 
| 477 | 477 |      { | 
| 478 | 478 | $idKey = $this->getIdentifierKey(); | 
| 479 | - $criteria[$idKey] = $this->getIdentifierCriteria($identifiers); | |
| 480 | -        if (empty($criteria[$idKey])) { | |
| 481 | - unset($criteria[$idKey]); | |
| 479 | + $criteria[ $idKey ] = $this->getIdentifierCriteria($identifiers); | |
| 480 | +        if (empty($criteria[ $idKey ])) { | |
| 481 | + unset($criteria[ $idKey ]); | |
| 482 | 482 | } | 
| 483 | 483 |          if (true === $metadata->isChildEntity()) { | 
| 484 | - $criteria[$this->getPolymorphicKey()] = $metadata->type; | |
| 484 | + $criteria[ $this->getPolymorphicKey() ] = $metadata->type; | |
| 485 | 485 | } | 
| 486 | 486 | return $criteria; | 
| 487 | 487 | } | 
| @@ -494,16 +494,16 @@ discard block | ||
| 494 | 494 | */ | 
| 495 | 495 | protected function getIdentifierCriteria($identifiers) | 
| 496 | 496 |      { | 
| 497 | - $criteria = []; | |
| 497 | + $criteria = [ ]; | |
| 498 | 498 |          if (is_array($identifiers)) { | 
| 499 | - $ids = []; | |
| 499 | + $ids = [ ]; | |
| 500 | 500 |              foreach ($identifiers as $id) { | 
| 501 | - $ids[] = $this->convertId($id); | |
| 501 | + $ids[ ] = $this->convertId($id); | |
| 502 | 502 | } | 
| 503 | 503 |              if (1 === count($ids)) { | 
| 504 | - $criteria = $ids[0]; | |
| 504 | + $criteria = $ids[ 0 ]; | |
| 505 | 505 |              } elseif (!empty($ids)) { | 
| 506 | - $criteria = ['$in' => $ids]; | |
| 506 | + $criteria = [ '$in' => $ids ]; | |
| 507 | 507 | } | 
| 508 | 508 |          } else { | 
| 509 | 509 | $criteria = $this->convertId($identifiers); | 
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | /** | 
| 24 | 24 | * Constructor. | 
| 25 | 25 | * | 
| 26 | - * @param EntityUtility $entityUtl | |
| 26 | + * @param EntityUtility $entityUtil | |
| 27 | 27 | */ | 
| 28 | 28 | public function __construct(EntityUtility $entityUtil) | 
| 29 | 29 |      { | 
| @@ -55,7 +55,7 @@ | ||
| 55 | 55 |      { | 
| 56 | 56 | $persistence = $metadata->persistence; | 
| 57 | 57 | |
| 58 | - $validIdStrategies = ['object']; | |
| 58 | + $validIdStrategies = [ 'object' ]; | |
| 59 | 59 |          if (!in_array($persistence->idStrategy, $validIdStrategies)) { | 
| 60 | 60 |              throw MetadataException::invalidMetadata($metadata->type, sprintf('The persistence id strategy "%s" is invalid. Valid types are "%s"', $persistence->idStrategy, implode('", "', $validIdStrategies))); | 
| 61 | 61 | } |