@@ -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 | } |
@@ -6,11 +6,8 @@ |
||
| 6 | 6 | use As3\Modlr\Models\Model; |
| 7 | 7 | use As3\Modlr\Models\Collection; |
| 8 | 8 | use As3\Modlr\Metadata\EntityMetadata; |
| 9 | -use As3\Modlr\Metadata\AttributeMetadata; |
|
| 10 | -use As3\Modlr\Metadata\RelationshipMetadata; |
|
| 11 | 9 | use As3\Modlr\Persister\PersisterInterface; |
| 12 | 10 | use As3\Modlr\Persister\PersisterException; |
| 13 | -use As3\Modlr\Persister\Record; |
|
| 14 | 11 | use Doctrine\MongoDB\Connection; |
| 15 | 12 | use \MongoId; |
| 16 | 13 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * {@inheritDoc} |
| 87 | 87 | * @todo Implement sorting and pagination (limit/skip). |
| 88 | 88 | */ |
| 89 | - public function all(EntityMetadata $metadata, Store $store, array $identifiers = []) |
|
| 89 | + public function all(EntityMetadata $metadata, Store $store, array $identifiers = [ ]) |
|
| 90 | 90 | { |
| 91 | 91 | $criteria = $this->getRetrieveCritiera($metadata, $identifiers); |
| 92 | 92 | $cursor = $this->doQuery($metadata, $store, $criteria); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | /** |
| 97 | 97 | * {@inheritDoc} |
| 98 | 98 | */ |
| 99 | - public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
| 99 | + public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
| 100 | 100 | { |
| 101 | 101 | $cursor = $this->doQuery($metadata, $store, $criteria); |
| 102 | 102 | return $this->getHydrator()->hydrateMany($metadata, $cursor->toArray(), $store); |
@@ -132,32 +132,32 @@ discard block |
||
| 132 | 132 | public function create(Model $model) |
| 133 | 133 | { |
| 134 | 134 | $metadata = $model->getMetadata(); |
| 135 | - $insert[$this->getIdentifierKey()] = $this->convertId($model->getId()); |
|
| 135 | + $insert[ $this->getIdentifierKey() ] = $this->convertId($model->getId()); |
|
| 136 | 136 | if (true === $metadata->isChildEntity()) { |
| 137 | - $insert[$this->getPolymorphicKey()] = $metadata->type; |
|
| 137 | + $insert[ $this->getPolymorphicKey() ] = $metadata->type; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $changeset = $model->getChangeSet(); |
| 141 | - foreach ($changeset['attributes'] as $key => $values) { |
|
| 142 | - $value = $this->getFormatter()->getAttributeDbValue($metadata->getAttribute($key), $values['new']); |
|
| 141 | + foreach ($changeset[ 'attributes' ] as $key => $values) { |
|
| 142 | + $value = $this->getFormatter()->getAttributeDbValue($metadata->getAttribute($key), $values[ 'new' ]); |
|
| 143 | 143 | if (null === $value) { |
| 144 | 144 | continue; |
| 145 | 145 | } |
| 146 | - $insert[$key] = $value; |
|
| 146 | + $insert[ $key ] = $value; |
|
| 147 | 147 | } |
| 148 | - foreach ($changeset['hasOne'] as $key => $values) { |
|
| 149 | - $value = $this->getFormatter()->getHasOneDbValue($metadata->getRelationship($key), $values['new']); |
|
| 148 | + foreach ($changeset[ 'hasOne' ] as $key => $values) { |
|
| 149 | + $value = $this->getFormatter()->getHasOneDbValue($metadata->getRelationship($key), $values[ 'new' ]); |
|
| 150 | 150 | if (null === $value) { |
| 151 | 151 | continue; |
| 152 | 152 | } |
| 153 | - $insert[$key] = $value; |
|
| 153 | + $insert[ $key ] = $value; |
|
| 154 | 154 | } |
| 155 | - foreach ($changeset['hasMany'] as $key => $values) { |
|
| 156 | - $value = $this->getFormatter()->getHasManyDbValue($metadata->getRelationship($key), $values['new']); |
|
| 155 | + foreach ($changeset[ 'hasMany' ] as $key => $values) { |
|
| 156 | + $value = $this->getFormatter()->getHasManyDbValue($metadata->getRelationship($key), $values[ 'new' ]); |
|
| 157 | 157 | if (null === $value) { |
| 158 | 158 | continue; |
| 159 | 159 | } |
| 160 | - $insert[$key] = $value; |
|
| 160 | + $insert[ $key ] = $value; |
|
| 161 | 161 | } |
| 162 | 162 | $this->createQueryBuilder($metadata) |
| 163 | 163 | ->insert() |
@@ -178,39 +178,39 @@ discard block |
||
| 178 | 178 | $criteria = $this->getRetrieveCritiera($metadata, $model->getId()); |
| 179 | 179 | $changeset = $model->getChangeSet(); |
| 180 | 180 | |
| 181 | - $update = []; |
|
| 182 | - foreach ($changeset['attributes'] as $key => $values) { |
|
| 183 | - if (null === $values['new']) { |
|
| 181 | + $update = [ ]; |
|
| 182 | + foreach ($changeset[ 'attributes' ] as $key => $values) { |
|
| 183 | + if (null === $values[ 'new' ]) { |
|
| 184 | 184 | $op = '$unset'; |
| 185 | 185 | $value = 1; |
| 186 | 186 | } else { |
| 187 | 187 | $op = '$set'; |
| 188 | - $value = $this->getFormatter()->getAttributeDbValue($metadata->getAttribute($key), $values['new']); |
|
| 188 | + $value = $this->getFormatter()->getAttributeDbValue($metadata->getAttribute($key), $values[ 'new' ]); |
|
| 189 | 189 | } |
| 190 | - $update[$op][$key] = $value; |
|
| 190 | + $update[ $op ][ $key ] = $value; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // @todo Must prevent inverse relationships from persisting |
| 194 | - foreach ($changeset['hasOne'] as $key => $values) { |
|
| 195 | - if (null === $values['new']) { |
|
| 194 | + foreach ($changeset[ 'hasOne' ] as $key => $values) { |
|
| 195 | + if (null === $values[ 'new' ]) { |
|
| 196 | 196 | $op = '$unset'; |
| 197 | 197 | $value = 1; |
| 198 | 198 | } else { |
| 199 | 199 | $op = '$set'; |
| 200 | - $value = $this->getFormatter()->getHasOneDbValue($metadata->getRelationship($key), $values['new']); |
|
| 200 | + $value = $this->getFormatter()->getHasOneDbValue($metadata->getRelationship($key), $values[ 'new' ]); |
|
| 201 | 201 | } |
| 202 | - $update[$op][$key] = $value; |
|
| 202 | + $update[ $op ][ $key ] = $value; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - foreach ($changeset['hasMany'] as $key => $values) { |
|
| 206 | - if (null === $values['new']) { |
|
| 205 | + foreach ($changeset[ 'hasMany' ] as $key => $values) { |
|
| 206 | + if (null === $values[ 'new' ]) { |
|
| 207 | 207 | $op = '$unset'; |
| 208 | 208 | $value = 1; |
| 209 | 209 | } else { |
| 210 | 210 | $op = '$set'; |
| 211 | - $value = $this->getFormatter()->getHasManyDbValue($metadata->getRelationship($key), $values['new']); |
|
| 211 | + $value = $this->getFormatter()->getHasManyDbValue($metadata->getRelationship($key), $values[ 'new' ]); |
|
| 212 | 212 | } |
| 213 | - $update[$op][$key] = $value; |
|
| 213 | + $update[ $op ][ $key ] = $value; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | if (empty($update)) { |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * @param int $limit The number of Models to limit. |
| 316 | 316 | * @return \Doctrine\MongoDB\Cursor |
| 317 | 317 | */ |
| 318 | - protected function doQuery(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
| 318 | + protected function doQuery(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
| 319 | 319 | { |
| 320 | 320 | $criteria = $this->getFormatter()->formatQuery($metadata, $store, $criteria); |
| 321 | 321 | return $this->createQueryBuilder($metadata) |
@@ -335,17 +335,17 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | protected function getInverseCriteria(EntityMetadata $owner, EntityMetadata $related, $identifiers, $inverseField) |
| 337 | 337 | { |
| 338 | - $criteria[$inverseField] = (array) $identifiers; |
|
| 338 | + $criteria[ $inverseField ] = (array) $identifiers; |
|
| 339 | 339 | if (true === $owner->isChildEntity()) { |
| 340 | 340 | // The owner is owned by a polymorphic model. Must include the type with the inverse field criteria. |
| 341 | - $criteria[$inverseField] = [ |
|
| 342 | - $this->getIdentifierKey() => $criteria[$inverseField], |
|
| 341 | + $criteria[ $inverseField ] = [ |
|
| 342 | + $this->getIdentifierKey() => $criteria[ $inverseField ], |
|
| 343 | 343 | $this->getPolymorphicKey() => $owner->type, |
| 344 | 344 | ]; |
| 345 | 345 | } |
| 346 | 346 | if (true === $related->isChildEntity()) { |
| 347 | 347 | // The relationship is owned by a polymorphic model. Must include the type in the root criteria. |
| 348 | - $criteria[$this->getPolymorphicKey()] = $related->type; |
|
| 348 | + $criteria[ $this->getPolymorphicKey() ] = $related->type; |
|
| 349 | 349 | } |
| 350 | 350 | return $criteria; |
| 351 | 351 | } |
@@ -359,9 +359,9 @@ discard block |
||
| 359 | 359 | */ |
| 360 | 360 | protected function getRetrieveCritiera(EntityMetadata $metadata, $identifiers = null) |
| 361 | 361 | { |
| 362 | - $criteria = []; |
|
| 362 | + $criteria = [ ]; |
|
| 363 | 363 | if (true === $metadata->isChildEntity()) { |
| 364 | - $criteria[$this->getPolymorphicKey()] = $metadata->type; |
|
| 364 | + $criteria[ $this->getPolymorphicKey() ] = $metadata->type; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | if (null === $identifiers) { |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | if (empty($identifiers)) { |
| 372 | 372 | return $criteria; |
| 373 | 373 | } |
| 374 | - $criteria[$this->getIdentifierKey()] = (1 === count($identifiers)) ? $identifiers[0] : $identifiers; |
|
| 374 | + $criteria[ $this->getIdentifierKey() ] = (1 === count($identifiers)) ? $identifiers[ 0 ] : $identifiers; |
|
| 375 | 375 | return $criteria; |
| 376 | 376 | } |
| 377 | 377 | |
@@ -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.'); |