@@ -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 | } |
@@ -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; |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // Pass remaining elements unconverted. |
| 242 | - return [$key, $value]; |
|
| 242 | + return [ $key, $value ]; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -263,15 +263,15 @@ discard block |
||
| 263 | 263 | if (is_array($value)) { |
| 264 | 264 | |
| 265 | 265 | if (true === $this->hasOperators($value)) { |
| 266 | - return [$key, $this->formatQueryExpression($value, $converter)]; |
|
| 266 | + return [ $key, $this->formatQueryExpression($value, $converter) ]; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - if (in_array($attrMeta->dataType, ['array', 'object'])) { |
|
| 270 | - return [$key, $value]; |
|
| 269 | + if (in_array($attrMeta->dataType, [ 'array', 'object' ])) { |
|
| 270 | + return [ $key, $value ]; |
|
| 271 | 271 | } |
| 272 | - return [$key, $this->formatQueryExpression(['$in' => $value], $converter)]; |
|
| 272 | + return [ $key, $this->formatQueryExpression([ '$in' => $value ], $converter) ]; |
|
| 273 | 273 | } |
| 274 | - return [$key, $converter($value)]; |
|
| 274 | + return [ $key, $converter($value) ]; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -294,30 +294,30 @@ discard block |
||
| 294 | 294 | $root = array_shift($parts); |
| 295 | 295 | if (false === $metadata->hasRelationship($root)) { |
| 296 | 296 | // Nothing to format. Allow the dotted field to pass normally. |
| 297 | - return [$key, $value]; |
|
| 297 | + return [ $key, $value ]; |
|
| 298 | 298 | } |
| 299 | - $hasIndex = is_numeric($parts[0]); |
|
| 299 | + $hasIndex = is_numeric($parts[ 0 ]); |
|
| 300 | 300 | |
| 301 | 301 | if (true === $hasIndex) { |
| 302 | - $subKey = isset($parts[1]) ? $parts[1] : 'id'; |
|
| 302 | + $subKey = isset($parts[ 1 ]) ? $parts[ 1 ] : 'id'; |
|
| 303 | 303 | } else { |
| 304 | - $subKey = $parts[0]; |
|
| 304 | + $subKey = $parts[ 0 ]; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | if ($this->isIdentifierField($subKey)) { |
| 308 | 308 | // Handle like a regular relationship |
| 309 | 309 | list($key, $value) = $this->formatQueryElementRel($root, $value, $metadata, $store); |
| 310 | - $key = (true === $hasIndex) ? sprintf('%s.%s', $key, $parts[0]) : $key; |
|
| 311 | - return [$key, $value]; |
|
| 310 | + $key = (true === $hasIndex) ? sprintf('%s.%s', $key, $parts[ 0 ]) : $key; |
|
| 311 | + return [ $key, $value ]; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | if ($this->isTypeField($subKey)) { |
| 315 | 315 | // Handle as a model type field. |
| 316 | 316 | list($key, $value) = $this->formatQueryElementType($subKey, $value); |
| 317 | - $key = (true === $hasIndex) ? sprintf('%s.%s.%s', $root, $parts[0], $key) : sprintf('%s.%s', $root, $key); |
|
| 318 | - return [$key, $value]; |
|
| 317 | + $key = (true === $hasIndex) ? sprintf('%s.%s.%s', $root, $parts[ 0 ], $key) : sprintf('%s.%s', $root, $key); |
|
| 318 | + return [ $key, $value ]; |
|
| 319 | 319 | } |
| 320 | - return [$key, $value]; |
|
| 320 | + return [ $key, $value ]; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -343,10 +343,10 @@ discard block |
||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | if (is_array($value)) { |
| 346 | - $value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value]; |
|
| 347 | - return [$key, $this->formatQueryExpression($value, $converter)]; |
|
| 346 | + $value = (true === $this->hasOperators($value)) ? $value : [ '$in' => $value ]; |
|
| 347 | + return [ $key, $this->formatQueryExpression($value, $converter) ]; |
|
| 348 | 348 | } |
| 349 | - return [$key, $converter($value)]; |
|
| 349 | + return [ $key, $converter($value) ]; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | |
@@ -371,10 +371,10 @@ discard block |
||
| 371 | 371 | |
| 372 | 372 | $converter = $this->getQueryRootConverter($metadata, $dbKey); |
| 373 | 373 | if (is_array($value)) { |
| 374 | - $value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value]; |
|
| 375 | - return [$dbKey, $this->formatQueryExpression($value, $converter)]; |
|
| 374 | + $value = (true === $this->hasOperators($value)) ? $value : [ '$in' => $value ]; |
|
| 375 | + return [ $dbKey, $this->formatQueryExpression($value, $converter) ]; |
|
| 376 | 376 | } |
| 377 | - return [$dbKey, $converter($value)]; |
|
| 377 | + return [ $dbKey, $converter($value) ]; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -393,25 +393,25 @@ discard block |
||
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | if (true === $this->isOpType('single', $key)) { |
| 396 | - $expression[$key] = $converter($value); |
|
| 396 | + $expression[ $key ] = $converter($value); |
|
| 397 | 397 | continue; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | if (true === $this->isOpType('multiple', $key)) { |
| 401 | 401 | $value = (array) $value; |
| 402 | 402 | foreach ($value as $subKey => $subValue) { |
| 403 | - $expression[$key][$subKey] = $converter($subValue); |
|
| 403 | + $expression[ $key ][ $subKey ] = $converter($subValue); |
|
| 404 | 404 | } |
| 405 | 405 | continue; |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | if (true === $this->isOpType('recursive', $key)) { |
| 409 | 409 | $value = (array) $value; |
| 410 | - $expression[$key] = $this->formatQueryExpression($value, $converter); |
|
| 410 | + $expression[ $key ] = $this->formatQueryExpression($value, $converter); |
|
| 411 | 411 | continue; |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - $expression[$key] = $converter($value); |
|
| 414 | + $expression[ $key ] = $converter($value); |
|
| 415 | 415 | } |
| 416 | 416 | return $expression; |
| 417 | 417 | } |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | */ |
| 426 | 426 | private function getQueryAttrConverter(Store $store, AttributeMetadata $attrMeta) |
| 427 | 427 | { |
| 428 | - return function ($value) use ($store, $attrMeta) { |
|
| 428 | + return function($value) use ($store, $attrMeta) { |
|
| 429 | 429 | $value = $store->convertAttributeValue($attrMeta->dataType, $value); |
| 430 | 430 | return $this->getAttributeDbValue($attrMeta, $value); |
| 431 | 431 | }; |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | */ |
| 497 | 497 | private function isOperator($key) |
| 498 | 498 | { |
| 499 | - return isset($key[0]) && '$' === $key[0]; |
|
| 499 | + return isset($key[ 0 ]) && '$' === $key[ 0 ]; |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -508,9 +508,9 @@ discard block |
||
| 508 | 508 | */ |
| 509 | 509 | private function isOpType($type, $key) |
| 510 | 510 | { |
| 511 | - if (!isset($this->ops[$type])) { |
|
| 511 | + if (!isset($this->ops[ $type ])) { |
|
| 512 | 512 | return false; |
| 513 | 513 | } |
| 514 | - return in_array($key, $this->ops[$type]); |
|
| 514 | + return in_array($key, $this->ops[ $type ]); |
|
| 515 | 515 | } |
| 516 | 516 | } |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public function hydrateMany(EntityMetadata $metadata, array $results, Store $store) |
| 65 | 65 | { |
| 66 | - $records = []; |
|
| 66 | + $records = [ ]; |
|
| 67 | 67 | foreach ($results as $data) { |
| 68 | - $records[] = $this->hydrateOne($metadata, $data, $store); |
|
| 68 | + $records[ ] = $this->hydrateOne($metadata, $data, $store); |
|
| 69 | 69 | } |
| 70 | 70 | return $records; |
| 71 | 71 | } |
@@ -80,19 +80,19 @@ discard block |
||
| 80 | 80 | private function convertRelationships(EntityMetadata $metadata, array $data) |
| 81 | 81 | { |
| 82 | 82 | foreach ($metadata->getRelationships() as $key => $relMeta) { |
| 83 | - if (!isset($data[$key])) { |
|
| 83 | + if (!isset($data[ $key ])) { |
|
| 84 | 84 | continue; |
| 85 | 85 | } |
| 86 | - if (true === $relMeta->isMany() && !is_array($data[$key])) { |
|
| 87 | - 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)); |
|
| 86 | + if (true === $relMeta->isMany() && !is_array($data[ $key ])) { |
|
| 87 | + 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)); |
|
| 88 | 88 | } |
| 89 | - $references = $relMeta->isOne() ? [$data[$key]] : $data[$key]; |
|
| 89 | + $references = $relMeta->isOne() ? [ $data[ $key ] ] : $data[ $key ]; |
|
| 90 | 90 | |
| 91 | - $extracted = []; |
|
| 91 | + $extracted = [ ]; |
|
| 92 | 92 | foreach ($references as $reference) { |
| 93 | - $extracted[] = $this->extractRelationship($relMeta, $reference); |
|
| 93 | + $extracted[ ] = $this->extractRelationship($relMeta, $reference); |
|
| 94 | 94 | } |
| 95 | - $data[$key] = $relMeta->isOne() ? reset($extracted) : $extracted; |
|
| 95 | + $data[ $key ] = $relMeta->isOne() ? reset($extracted) : $extracted; |
|
| 96 | 96 | } |
| 97 | 97 | return $data; |
| 98 | 98 | } |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | private function extractField($key, array $data) |
| 109 | 109 | { |
| 110 | - if (!isset($data[$key])) { |
|
| 110 | + if (!isset($data[ $key ])) { |
|
| 111 | 111 | throw PersisterException::badRequest(sprintf('Unable to extract a field value. The "%s" key was not found.', $key)); |
| 112 | 112 | } |
| 113 | - return $data[$key]; |
|
| 113 | + return $data[ $key ]; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | private function extractIdAndType(EntityMetadata $metadata, array &$data) |
| 126 | 126 | { |
| 127 | 127 | $identifier = $this->extractField(Persister::IDENTIFIER_KEY, $data); |
| 128 | - unset($data[Persister::IDENTIFIER_KEY]); |
|
| 128 | + unset($data[ Persister::IDENTIFIER_KEY ]); |
|
| 129 | 129 | |
| 130 | 130 | $key = Persister::POLYMORPHIC_KEY; |
| 131 | 131 | $type = $this->extractType($metadata, $data); |
| 132 | - if (isset($data[$key])) { |
|
| 133 | - unset($data[$key]); |
|
| 132 | + if (isset($data[ $key ])) { |
|
| 133 | + unset($data[ $key ]); |
|
| 134 | 134 | } |
| 135 | - return [$identifier, $type]; |
|
| 135 | + return [ $identifier, $type ]; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | $idKey = Persister::IDENTIFIER_KEY; |
| 150 | 150 | $typeKey = Persister::POLYMORPHIC_KEY; |
| 151 | 151 | |
| 152 | - if (true === $simple && is_array($reference) && isset($reference[$idKey])) { |
|
| 152 | + if (true === $simple && is_array($reference) && isset($reference[ $idKey ])) { |
|
| 153 | 153 | return [ |
| 154 | - 'id' => $reference[$idKey], |
|
| 154 | + 'id' => $reference[ $idKey ], |
|
| 155 | 155 | 'type' => $relMeta->getEntityType(), |
| 156 | 156 | ]; |
| 157 | 157 | } |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | ]; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - if (false === $simple && is_array($reference) && isset($reference[$idKey]) && isset($reference[$typeKey])) { |
|
| 166 | + if (false === $simple && is_array($reference) && isset($reference[ $idKey ]) && isset($reference[ $typeKey ])) { |
|
| 167 | 167 | return [ |
| 168 | - 'id' => $reference[$idKey], |
|
| 169 | - 'type' => $reference[$typeKey], |
|
| 168 | + 'id' => $reference[ $idKey ], |
|
| 169 | + 'type' => $reference[ $typeKey ], |
|
| 170 | 170 | ]; |
| 171 | 171 | } |
| 172 | 172 | throw PersisterException::badRequest('Unable to extract a reference id.'); |
@@ -9,7 +9,6 @@ |
||
| 9 | 9 | use As3\Modlr\Persister\PersisterException; |
| 10 | 10 | use As3\Modlr\Persister\PersisterInterface; |
| 11 | 11 | use As3\Modlr\Store\Store; |
| 12 | -use Doctrine\MongoDB\Connection; |
|
| 13 | 12 | |
| 14 | 13 | /** |
| 15 | 14 | * Persists and retrieves models to/from a MongoDB database. |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | * @var array |
| 29 | 29 | */ |
| 30 | 30 | private $changeSetMethods = [ |
| 31 | - 'attributes' => ['getAttribute', 'getAttributeDbValue'], |
|
| 32 | - 'hasOne' => ['getRelationship', 'getHasOneDbValue'], |
|
| 33 | - 'hasMany' => ['getRelationship', 'getHasManyDbValue'], |
|
| 31 | + 'attributes' => [ 'getAttribute', 'getAttributeDbValue' ], |
|
| 32 | + 'hasOne' => [ 'getRelationship', 'getHasOneDbValue' ], |
|
| 33 | + 'hasMany' => [ 'getRelationship', 'getHasManyDbValue' ], |
|
| 34 | 34 | ]; |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | /** |
| 69 | 69 | * {@inheritDoc} |
| 70 | 70 | */ |
| 71 | - public function all(EntityMetadata $metadata, Store $store, array $identifiers = []) |
|
| 71 | + public function all(EntityMetadata $metadata, Store $store, array $identifiers = [ ]) |
|
| 72 | 72 | { |
| 73 | 73 | $criteria = $this->getQuery()->getRetrieveCritiera($metadata, $identifiers); |
| 74 | 74 | $cursor = $this->getQuery()->executeFind($metadata, $store, $criteria); |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | /** |
| 195 | 195 | * {@inheritDoc} |
| 196 | 196 | */ |
| 197 | - public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
| 197 | + public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
| 198 | 198 | { |
| 199 | 199 | $cursor = $this->getQuery()->executeFind($metadata, $store, $criteria); |
| 200 | 200 | return $this->getHydrator()->hydrateMany($metadata, $cursor->toArray(), $store); |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | foreach ($this->changeSetMethods as $setKey => $methods) { |
| 249 | 249 | list($metaMethod, $formatMethod) = $methods; |
| 250 | - foreach ($changeset[$setKey] as $key => $values) { |
|
| 251 | - $value = $formatter->$formatMethod($metadata->$metaMethod($key), $values['new']); |
|
| 250 | + foreach ($changeset[ $setKey ] as $key => $values) { |
|
| 251 | + $value = $formatter->$formatMethod($metadata->$metaMethod($key), $values[ 'new' ]); |
|
| 252 | 252 | $obj = $handler($key, $value, $obj); |
| 253 | 253 | } |
| 254 | 254 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | $this->getIdentifierKey() => $this->convertId($model->getId()), |
| 269 | 269 | ]; |
| 270 | 270 | if (true === $metadata->isChildEntity()) { |
| 271 | - $insert[$this->getPolymorphicKey()] = $metadata->type; |
|
| 271 | + $insert[ $this->getPolymorphicKey() ] = $metadata->type; |
|
| 272 | 272 | } |
| 273 | 273 | return $this->appendChangeSet($model, $insert, $this->getCreateChangeSetHandler()); |
| 274 | 274 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | private function createUpdateObj(Model $model) |
| 283 | 283 | { |
| 284 | - return $this->appendChangeSet($model, [], $this->getUpdateChangeSetHandler()); |
|
| 284 | + return $this->appendChangeSet($model, [ ], $this->getUpdateChangeSetHandler()); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -291,9 +291,9 @@ discard block |
||
| 291 | 291 | */ |
| 292 | 292 | private function getCreateChangeSetHandler() |
| 293 | 293 | { |
| 294 | - return function ($key, $value, $obj) { |
|
| 294 | + return function($key, $value, $obj) { |
|
| 295 | 295 | if (null !== $value) { |
| 296 | - $obj[$key] = $value; |
|
| 296 | + $obj[ $key ] = $value; |
|
| 297 | 297 | } |
| 298 | 298 | return $obj; |
| 299 | 299 | }; |
@@ -306,13 +306,13 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | private function getUpdateChangeSetHandler() |
| 308 | 308 | { |
| 309 | - return function ($key, $value, $obj) { |
|
| 309 | + return function($key, $value, $obj) { |
|
| 310 | 310 | $op = '$set'; |
| 311 | 311 | if (null === $value) { |
| 312 | 312 | $op = '$unset'; |
| 313 | 313 | $value = 1; |
| 314 | 314 | } |
| 315 | - $obj[$op][$key] = $value; |
|
| 315 | + $obj[ $op ][ $key ] = $value; |
|
| 316 | 316 | return $obj; |
| 317 | 317 | }; |
| 318 | 318 | } |
@@ -57,7 +57,6 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @param EntityMetadata $metadata |
| 59 | 59 | * @param Store $store |
| 60 | - * @param array $toInsert |
|
| 61 | 60 | * @return array|bool |
| 62 | 61 | */ |
| 63 | 62 | public function executeDelete(EntityMetadata $metadata, Store $store, array $criteria) |
@@ -148,8 +147,8 @@ discard block |
||
| 148 | 147 | /** |
| 149 | 148 | * Gets standard database retrieval criteria for an inverse relationship. |
| 150 | 149 | * |
| 151 | - * @param EntityMetadata $metadata The entity to retrieve database records for. |
|
| 152 | 150 | * @param string|array $identifiers The IDs to query. |
| 151 | + * @param string $inverseField |
|
| 153 | 152 | * @return array |
| 154 | 153 | */ |
| 155 | 154 | public function getInverseCriteria(EntityMetadata $owner, EntityMetadata $related, $identifiers, $inverseField) |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param int $limit The number of Models to limit. |
| 84 | 84 | * @return \Doctrine\MongoDB\Cursor |
| 85 | 85 | */ |
| 86 | - public function executeFind(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
| 86 | + public function executeFind(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
| 87 | 87 | { |
| 88 | 88 | $criteria = $this->getFormatter()->formatQuery($metadata, $store, $criteria); |
| 89 | 89 | |
@@ -154,17 +154,17 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function getInverseCriteria(EntityMetadata $owner, EntityMetadata $related, $identifiers, $inverseField) |
| 156 | 156 | { |
| 157 | - $criteria[$inverseField] = (array) $identifiers; |
|
| 157 | + $criteria[ $inverseField ] = (array) $identifiers; |
|
| 158 | 158 | if (true === $owner->isChildEntity()) { |
| 159 | 159 | // The owner is owned by a polymorphic model. Must include the type with the inverse field criteria. |
| 160 | - $criteria[$inverseField] = [ |
|
| 161 | - Persister::IDENTIFIER_KEY => $criteria[$inverseField], |
|
| 160 | + $criteria[ $inverseField ] = [ |
|
| 161 | + Persister::IDENTIFIER_KEY => $criteria[ $inverseField ], |
|
| 162 | 162 | Persister::POLYMORPHIC_KEY => $owner->type, |
| 163 | 163 | ]; |
| 164 | 164 | } |
| 165 | 165 | if (true === $related->isChildEntity()) { |
| 166 | 166 | // The relationship is owned by a polymorphic model. Must include the type in the root criteria. |
| 167 | - $criteria[Persister::POLYMORPHIC_KEY] = $related->type; |
|
| 167 | + $criteria[ Persister::POLYMORPHIC_KEY ] = $related->type; |
|
| 168 | 168 | } |
| 169 | 169 | return $criteria; |
| 170 | 170 | } |
@@ -192,16 +192,16 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function getRetrieveCritiera(EntityMetadata $metadata, $identifiers = null) |
| 194 | 194 | { |
| 195 | - $criteria = []; |
|
| 195 | + $criteria = [ ]; |
|
| 196 | 196 | if (true === $metadata->isChildEntity()) { |
| 197 | - $criteria[Persister::POLYMORPHIC_KEY] = $metadata->type; |
|
| 197 | + $criteria[ Persister::POLYMORPHIC_KEY ] = $metadata->type; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | $identifiers = (array) $identifiers; |
| 201 | 201 | if (empty($identifiers)) { |
| 202 | 202 | return $criteria; |
| 203 | 203 | } |
| 204 | - $criteria[Persister::IDENTIFIER_KEY] = (1 === count($identifiers)) ? reset($identifiers) : $identifiers; |
|
| 204 | + $criteria[ Persister::IDENTIFIER_KEY ] = (1 === count($identifiers)) ? reset($identifiers) : $identifiers; |
|
| 205 | 205 | return $criteria; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -278,8 +278,8 @@ discard block |
||
| 278 | 278 | if ($type !== $include) { |
| 279 | 279 | PersisterException::badRequest('Field projection mismatch. You cannot both exclude and include fields.'); |
| 280 | 280 | } |
| 281 | - $fields[$key] = $type; |
|
| 281 | + $fields[ $key ] = $type; |
|
| 282 | 282 | } |
| 283 | - return [$fields, $include]; |
|
| 283 | + return [ $fields, $include ]; |
|
| 284 | 284 | } |
| 285 | 285 | } |