@@ -16,7 +16,6 @@ discard block |
||
| 16 | 16 | * Applies schemata |
| 17 | 17 | * |
| 18 | 18 | * @param Collection $collection The MongoDB Collection |
| 19 | - * @param array $index Associative array containing index data |
|
| 20 | 19 | */ |
| 21 | 20 | public function createSchemata(Collection $collection, array $schemata) |
| 22 | 21 | { |
@@ -31,7 +30,6 @@ discard block |
||
| 31 | 30 | * @todo Implement |
| 32 | 31 | * |
| 33 | 32 | * @param Collection $collection The MongoDB Collection |
| 34 | - * @param array $index Associative array containing index data |
|
| 35 | 33 | */ |
| 36 | 34 | public function syncSchemata(Collection $collection, array $schemata) |
| 37 | 35 | { |
@@ -21,11 +21,11 @@ |
||
| 21 | 21 | public function createSchemata(Collection $collection, array $schemata) |
| 22 | 22 | { |
| 23 | 23 | foreach ($schemata as $schema) { |
| 24 | - if (!isset($schema['keys']) || empty($schema['keys'])) { |
|
| 24 | + if (!isset($schema[ 'keys' ]) || empty($schema[ 'keys' ])) { |
|
| 25 | 25 | throw new \InvalidArgumentException('Cannot create an index with no keys defined.'); |
| 26 | 26 | } |
| 27 | - $schema['options']['background'] = true; |
|
| 28 | - $collection->ensureIndex($schema['keys'], $schema['options']); |
|
| 27 | + $schema[ 'options' ][ 'background' ] = true; |
|
| 28 | + $collection->ensureIndex($schema[ 'keys' ], $schema[ 'options' ]); |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | * |
| 42 | 42 | * @var array |
| 43 | 43 | */ |
| 44 | - public $schemata = []; |
|
| 44 | + public $schemata = [ ]; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * {@inheritDoc} |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | * @var array |
| 28 | 28 | */ |
| 29 | 29 | private $changeSetMethods = [ |
| 30 | - 'attributes' => ['getAttribute', 'getAttributeDbValue'], |
|
| 31 | - 'hasOne' => ['getRelationship', 'getHasOneDbValue'], |
|
| 32 | - 'hasMany' => ['getRelationship', 'getHasManyDbValue'], |
|
| 33 | - 'embedOne' => ['getEmbed', 'getEmbedOneDbValue'], |
|
| 34 | - 'embedMany' => ['getEmbed', 'getEmbedManyDbValue'], |
|
| 30 | + 'attributes' => [ 'getAttribute', 'getAttributeDbValue' ], |
|
| 31 | + 'hasOne' => [ 'getRelationship', 'getHasOneDbValue' ], |
|
| 32 | + 'hasMany' => [ 'getRelationship', 'getHasManyDbValue' ], |
|
| 33 | + 'embedOne' => [ 'getEmbed', 'getEmbedOneDbValue' ], |
|
| 34 | + 'embedMany' => [ 'getEmbed', 'getEmbedManyDbValue' ], |
|
| 35 | 35 | ]; |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | /** |
| 77 | 77 | * {@inheritDoc} |
| 78 | 78 | */ |
| 79 | - public function all(EntityMetadata $metadata, Store $store, array $identifiers = [], array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
| 79 | + public function all(EntityMetadata $metadata, Store $store, array $identifiers = [ ], array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
| 80 | 80 | { |
| 81 | 81 | $criteria = $this->getQuery()->getRetrieveCritiera($metadata, $identifiers); |
| 82 | 82 | $cursor = $this->getQuery()->executeFind($metadata, $store, $criteria, $fields, $sort, $offset, $limit); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | public function createSchemata(EntityMetadata $metadata) |
| 110 | 110 | { |
| 111 | 111 | $collection = $this->getQuery()->getModelCollection($metadata); |
| 112 | - $schemata = $metadata->persistence->schemata ?: []; |
|
| 112 | + $schemata = $metadata->persistence->schemata ?: [ ]; |
|
| 113 | 113 | return $this->schemaManager->createSchemata($collection, $schemata); |
| 114 | 114 | } |
| 115 | 115 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function syncSchemata(EntityMetadata $metadata) |
| 120 | 120 | { |
| 121 | 121 | $collection = $this->getQuery()->getModelCollection($metadata); |
| 122 | - $schemata = $metadata->persistence->schemata ?: []; |
|
| 122 | + $schemata = $metadata->persistence->schemata ?: [ ]; |
|
| 123 | 123 | return $this->schemaManager->syncSchemata($collection); |
| 124 | 124 | } |
| 125 | 125 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | /** |
| 223 | 223 | * {@inheritDoc} |
| 224 | 224 | */ |
| 225 | - public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [], array $sort = [], $offset = 0, $limit = 0) |
|
| 225 | + public function query(EntityMetadata $metadata, Store $store, array $criteria, array $fields = [ ], array $sort = [ ], $offset = 0, $limit = 0) |
|
| 226 | 226 | { |
| 227 | 227 | $cursor = $this->getQuery()->executeFind($metadata, $store, $criteria, $fields, $sort, $offset, $limit); |
| 228 | 228 | return $this->getHydrator()->createCursorRecordSet($metadata, $cursor, $store); |
@@ -272,8 +272,8 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | foreach ($this->changeSetMethods as $setKey => $methods) { |
| 274 | 274 | list($metaMethod, $formatMethod) = $methods; |
| 275 | - foreach ($changeset[$setKey] as $key => $values) { |
|
| 276 | - $value = $formatter->$formatMethod($metadata->$metaMethod($key), $values['new']); |
|
| 275 | + foreach ($changeset[ $setKey ] as $key => $values) { |
|
| 276 | + $value = $formatter->$formatMethod($metadata->$metaMethod($key), $values[ 'new' ]); |
|
| 277 | 277 | $obj = $handler($key, $value, $obj); |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | $this->getIdentifierKey() => $this->convertId($model->getId()), |
| 294 | 294 | ]; |
| 295 | 295 | if (true === $metadata->isChildEntity()) { |
| 296 | - $insert[$this->getPolymorphicKey()] = $metadata->type; |
|
| 296 | + $insert[ $this->getPolymorphicKey() ] = $metadata->type; |
|
| 297 | 297 | } |
| 298 | 298 | return $this->appendChangeSet($model, $insert, $this->getCreateChangeSetHandler()); |
| 299 | 299 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | private function createUpdateObj(Model $model) |
| 308 | 308 | { |
| 309 | - return $this->appendChangeSet($model, [], $this->getUpdateChangeSetHandler()); |
|
| 309 | + return $this->appendChangeSet($model, [ ], $this->getUpdateChangeSetHandler()); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -316,9 +316,9 @@ discard block |
||
| 316 | 316 | */ |
| 317 | 317 | private function getCreateChangeSetHandler() |
| 318 | 318 | { |
| 319 | - return function ($key, $value, $obj) { |
|
| 319 | + return function($key, $value, $obj) { |
|
| 320 | 320 | if (null !== $value) { |
| 321 | - $obj[$key] = $value; |
|
| 321 | + $obj[ $key ] = $value; |
|
| 322 | 322 | } |
| 323 | 323 | return $obj; |
| 324 | 324 | }; |
@@ -331,13 +331,13 @@ discard block |
||
| 331 | 331 | */ |
| 332 | 332 | private function getUpdateChangeSetHandler() |
| 333 | 333 | { |
| 334 | - return function ($key, $value, $obj) { |
|
| 334 | + return function($key, $value, $obj) { |
|
| 335 | 335 | $op = '$set'; |
| 336 | 336 | if (null === $value) { |
| 337 | 337 | $op = '$unset'; |
| 338 | 338 | $value = 1; |
| 339 | 339 | } |
| 340 | - $obj[$op][$key] = $value; |
|
| 340 | + $obj[ $op ][ $key ] = $value; |
|
| 341 | 341 | return $obj; |
| 342 | 342 | }; |
| 343 | 343 | } |
@@ -125,8 +125,8 @@ discard block |
||
| 125 | 125 | $metadata = $this->getMetadata()->persistence; |
| 126 | 126 | |
| 127 | 127 | foreach ($metadata->schemata as $schema) { |
| 128 | - $this->assertTrue(isset($schema['options']['name']) && !empty($schema['options']['name']), 'index name was not applied to schema'); |
|
| 129 | - $this->assertSame(stripos($schema['options']['name'], 'modlr_'), 0, '`modlr_` prefix missing from schema name'); |
|
| 128 | + $this->assertTrue(isset($schema[ 'options' ][ 'name' ]) && !empty($schema[ 'options' ][ 'name' ]), 'index name was not applied to schema'); |
|
| 129 | + $this->assertSame(stripos($schema[ 'options' ][ 'name' ], 'modlr_'), 0, '`modlr_` prefix missing from schema name'); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | public function testSchemaRequiresKeys() |
| 138 | 138 | { |
| 139 | - $schemata = [['options' => ['unique' => true]]]; |
|
| 139 | + $schemata = [ [ 'options' => [ 'unique' => true ] ] ]; |
|
| 140 | 140 | $metadata = $this->getMetadata($schemata); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public function testSchemaRequiresAtLeastOneKey() |
| 148 | 148 | { |
| 149 | - $schemata = ['keys' => [], ['options' => ['unique' => true]]]; |
|
| 149 | + $schemata = [ 'keys' => [ ], [ 'options' => [ 'unique' => true ] ] ]; |
|
| 150 | 150 | $metadata = $this->getMetadata($schemata); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $manager = new Modlr\Persister\MongoDb\SchemaManager; |
| 161 | 161 | |
| 162 | 162 | $schemata = [ |
| 163 | - ['options' => ['unique' => true]] |
|
| 163 | + [ 'options' => [ 'unique' => true ] ] |
|
| 164 | 164 | ]; |
| 165 | 165 | |
| 166 | 166 | $manager->createSchemata($collection, $schemata); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $manager = new Modlr\Persister\MongoDb\SchemaManager; |
| 177 | 177 | |
| 178 | 178 | $schemata = [ |
| 179 | - ['keys' => [], 'options' => ['unique' => true]] |
|
| 179 | + [ 'keys' => [ ], 'options' => [ 'unique' => true ] ] |
|
| 180 | 180 | ]; |
| 181 | 181 | |
| 182 | 182 | $manager->createSchemata($collection, $schemata); |
@@ -193,36 +193,36 @@ discard block |
||
| 193 | 193 | foreach ($metadata->persistence->schemata as $schema) { |
| 194 | 194 | $found = false; |
| 195 | 195 | foreach ($indices as $index) { |
| 196 | - if ($index['name'] === $schema['options']['name']) { |
|
| 196 | + if ($index[ 'name' ] === $schema[ 'options' ][ 'name' ]) { |
|
| 197 | 197 | $found = true; |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | - $this->assertTrue($found, sprintf('Index for "%s" was not created!', $schema['options']['name'])); |
|
| 200 | + $this->assertTrue($found, sprintf('Index for "%s" was not created!', $schema[ 'options' ][ 'name' ])); |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - private function getMetadata(array $schemata = []) |
|
| 204 | + private function getMetadata(array $schemata = [ ]) |
|
| 205 | 205 | { |
| 206 | 206 | $mapping = [ |
| 207 | 207 | 'type' => 'test-model', |
| 208 | 208 | 'attributes' => [ |
| 209 | - 'name' => ['data_type' => 'string'], |
|
| 210 | - 'active' => ['data_type' => 'boolean'] |
|
| 209 | + 'name' => [ 'data_type' => 'string' ], |
|
| 210 | + 'active' => [ 'data_type' => 'boolean' ] |
|
| 211 | 211 | ], |
| 212 | 212 | 'persistence' => [ |
| 213 | 213 | 'db' => self::$dbName, |
| 214 | 214 | 'collection' => 'test-model', |
| 215 | 215 | 'schemata' => [ |
| 216 | - ['keys' => ['name' => 1]], |
|
| 217 | - ['keys' => ['active' => 1], ['options' => ['unique' => true]]] |
|
| 216 | + [ 'keys' => [ 'name' => 1 ] ], |
|
| 217 | + [ 'keys' => [ 'active' => 1 ], [ 'options' => [ 'unique' => true ] ] ] |
|
| 218 | 218 | ] |
| 219 | 219 | ] |
| 220 | 220 | ]; |
| 221 | 221 | if (!empty($schemata)) { |
| 222 | - $mapping['persistence']['schemata'] = $schemata; |
|
| 222 | + $mapping[ 'persistence' ][ 'schemata' ] = $schemata; |
|
| 223 | 223 | } |
| 224 | - $metadata = new Modlr\Metadata\EntityMetadata($mapping['type']); |
|
| 225 | - $pmd = $this->smf->createInstance($mapping['persistence']); |
|
| 224 | + $metadata = new Modlr\Metadata\EntityMetadata($mapping[ 'type' ]); |
|
| 225 | + $pmd = $this->smf->createInstance($mapping[ 'persistence' ]); |
|
| 226 | 226 | $metadata->setPersistence($pmd); |
| 227 | 227 | $this->smf->handleValidate($metadata); |
| 228 | 228 | return $metadata; |
@@ -37,16 +37,16 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | $persistence = new StorageMetadata(); |
| 39 | 39 | |
| 40 | - if (isset($mapping['db'])) { |
|
| 41 | - $persistence->db = $mapping['db']; |
|
| 40 | + if (isset($mapping[ 'db' ])) { |
|
| 41 | + $persistence->db = $mapping[ 'db' ]; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if (isset($mapping['collection'])) { |
|
| 45 | - $persistence->collection = $mapping['collection']; |
|
| 44 | + if (isset($mapping[ 'collection' ])) { |
|
| 45 | + $persistence->collection = $mapping[ 'collection' ]; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if (isset($mapping['schemata'])) { |
|
| 49 | - $persistence->schemata = $this->rksort($mapping['schemata']); |
|
| 48 | + if (isset($mapping[ 'schemata' ])) { |
|
| 49 | + $persistence->schemata = $this->rksort($mapping[ 'schemata' ]); |
|
| 50 | 50 | } |
| 51 | 51 | return $persistence; |
| 52 | 52 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | ksort($array); |
| 83 | 83 | foreach ($array as $k => $v) { |
| 84 | 84 | if (is_array($v)) { |
| 85 | - $array[$k] = $this->rksort($v); |
|
| 85 | + $array[ $k ] = $this->rksort($v); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | return $array; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | private function validateIdStrategy(EntityMetadata $metadata) |
| 132 | 132 | { |
| 133 | 133 | $persistence = $metadata->persistence; |
| 134 | - $validIdStrategies = ['object']; |
|
| 134 | + $validIdStrategies = [ 'object' ]; |
|
| 135 | 135 | if (!in_array($persistence->idStrategy, $validIdStrategies)) { |
| 136 | 136 | throw MetadataException::invalidMetadata($metadata->type, sprintf('The persistence id strategy "%s" is invalid. Valid types are "%s"', $persistence->idStrategy, implode('", "', $validIdStrategies))); |
| 137 | 137 | } |
@@ -147,10 +147,10 @@ discard block |
||
| 147 | 147 | { |
| 148 | 148 | $persistence = $metadata->persistence; |
| 149 | 149 | foreach ($persistence->schemata as $k => $schema) { |
| 150 | - if (!isset($schema['keys']) || empty($schema['keys'])) { |
|
| 150 | + if (!isset($schema[ 'keys' ]) || empty($schema[ 'keys' ])) { |
|
| 151 | 151 | throw MetadataException::invalidMetadata($metadata->type, 'At least one key must be specified to define an index.'); |
| 152 | 152 | } |
| 153 | - $persistence->schemata[$k]['options']['name'] = sprintf('modlr_%s', md5(json_encode($schema))); |
|
| 153 | + $persistence->schemata[ $k ][ 'options' ][ 'name' ] = sprintf('modlr_%s', md5(json_encode($schema))); |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |