@@ -31,6 +31,9 @@ |
||
| 31 | 31 | return $response; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | + /** |
|
| 35 | + * @param double $start |
|
| 36 | + */ |
|
| 34 | 37 | private function log($start, $class, $request = [], $response = []) |
| 35 | 38 | { |
| 36 | 39 | if ($this->logging) { |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | public function disableRequest($class) |
| 26 | 26 | { |
| 27 | 27 | if (!is_subclass_of($class, Request::class)) { |
| 28 | - throw new Exception("Invalid request type: " . $class); |
|
| 28 | + throw new Exception("Invalid request type: ".$class); |
|
| 29 | 29 | } |
| 30 | 30 | $this->disabledRequests[] = $class; |
| 31 | 31 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | public function sendRequest(Request $request) |
| 34 | 34 | { |
| 35 | 35 | if (in_array(get_class($request), $this->disabledRequests)) { |
| 36 | - throw new Exception(get_class($request) . ' is disabled'); |
|
| 36 | + throw new Exception(get_class($request).' is disabled'); |
|
| 37 | 37 | } |
| 38 | 38 | $start = microtime(1); |
| 39 | 39 | $response = parent::sendRequest($request); |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | if (!is_object($migration)) { |
| 25 | 25 | $migration = new $migration; |
| 26 | 26 | } |
| 27 | - $schema->once(get_class($migration), function () use ($migration) { |
|
| 27 | + $schema->once(get_class($migration), function() use ($migration) { |
|
| 28 | 28 | $migration->migrate($this->mapper); |
| 29 | 29 | }); |
| 30 | 30 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | if (!is_subclass_of($class, Entity::class)) { |
| 39 | - throw new Exception("Entity should extend " . Entity::class . " class"); |
|
| 39 | + throw new Exception("Entity should extend ".Entity::class." class"); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $this->entityMapping[$space] = $class; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | if (!is_subclass_of($class, Repository::class)) { |
| 54 | - throw new Exception("Repository should extend " . Repository::class . " class"); |
|
| 54 | + throw new Exception("Repository should extend ".Repository::class." class"); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $this->repositoryMapping[$space] = $class; |
@@ -270,6 +270,9 @@ |
||
| 270 | 270 | $this->results = []; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | + /** |
|
| 274 | + * @param Entity $instance |
|
| 275 | + */ |
|
| 273 | 276 | public function save($instance) |
| 274 | 277 | { |
| 275 | 278 | $key = $this->space->getInstanceKey($instance); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $space->addIndex($index); |
| 140 | 140 | } catch (Exception $e) { |
| 141 | 141 | $presentation = json_encode($properties['indexes'][$i]); |
| 142 | - throw new Exception("Failed to add index $presentation. ". $e->getMessage(), 0, $e); |
|
| 142 | + throw new Exception("Failed to add index $presentation. ".$e->getMessage(), 0, $e); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | foreach ($schema->getSpaces() as $space) { |
| 149 | 149 | if (!count($space->getIndexes())) { |
| 150 | 150 | if (!$space->hasProperty('id')) { |
| 151 | - throw new Exception("No primary index on ". $space->getName()); |
|
| 151 | + throw new Exception("No primary index on ".$space->getName()); |
|
| 152 | 152 | } |
| 153 | 153 | $space->addIndex(['id']); |
| 154 | 154 | } |
@@ -29,6 +29,9 @@ |
||
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | + /** |
|
| 33 | + * @param Space $space |
|
| 34 | + */ |
|
| 32 | 35 | private function generateValue($space) |
| 33 | 36 | { |
| 34 | 37 | $this->initSchema(); |
@@ -183,6 +183,9 @@ |
||
| 183 | 183 | return $this->getData($entity, $id, $date, '_temporal_override_aggregate'); |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | + /** |
|
| 187 | + * @param string $space |
|
| 188 | + */ |
|
| 186 | 189 | private function getData($entity, $id, $date, $space) |
| 187 | 190 | { |
| 188 | 191 | $entity = $this->entityNameToId($entity); |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | 'entityId' => $id, |
| 383 | 383 | 'parent' => $node ? $node->id : 0, |
| 384 | 384 | ]; |
| 385 | - if (count($config) == $i+1) { |
|
| 385 | + if (count($config) == $i + 1) { |
|
| 386 | 386 | $params['begin'] = $link['begin']; |
| 387 | 387 | $params['timestamp'] = 0; |
| 388 | 388 | } |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | $this->mapper->getPlugin(Sequence::class); |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - $this->mapper->getSchema()->once(__CLASS__.'@entity', function (Mapper $mapper) { |
|
| 464 | + $this->mapper->getSchema()->once(__CLASS__.'@entity', function(Mapper $mapper) { |
|
| 465 | 465 | $this->mapper->getSchema() |
| 466 | 466 | ->createSpace('_temporal_entity', [ |
| 467 | 467 | 'id' => 'unsigned', |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | private function initLink() |
| 33 | 33 | { |
| 34 | - $this->mapper->getSchema()->once(__CLASS__.'@link', function (Mapper $mapper) { |
|
| 34 | + $this->mapper->getSchema()->once(__CLASS__.'@link', function(Mapper $mapper) { |
|
| 35 | 35 | $mapper->getSchema() |
| 36 | 36 | ->createSpace('_temporal_link', [ |
| 37 | 37 | 'id' => 'unsigned', |
@@ -62,14 +62,14 @@ discard block |
||
| 62 | 62 | ->addIndex(['entity', 'id', 'begin']); |
| 63 | 63 | }); |
| 64 | 64 | |
| 65 | - $this->mapper->getSchema()->once(__CLASS__.'@link-idle', function (Mapper $mapper) { |
|
| 65 | + $this->mapper->getSchema()->once(__CLASS__.'@link-idle', function(Mapper $mapper) { |
|
| 66 | 66 | $mapper->getSchema()->getSpace('_temporal_link')->addProperty('idle', 'unsigned'); |
| 67 | 67 | }); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | private function initOverride() |
| 71 | 71 | { |
| 72 | - $this->mapper->getSchema()->once(__CLASS__.'@states', function (Mapper $mapper) { |
|
| 72 | + $this->mapper->getSchema()->once(__CLASS__.'@states', function(Mapper $mapper) { |
|
| 73 | 73 | $mapper->getSchema() |
| 74 | 74 | ->createSpace('_temporal_override', [ |
| 75 | 75 | 'entity' => 'unsigned', |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | ->addIndex(['entity', 'id', 'begin']); |
| 94 | 94 | }); |
| 95 | 95 | |
| 96 | - $this->mapper->getSchema()->once(__CLASS__.'@override-idle', function (Mapper $mapper) { |
|
| 96 | + $this->mapper->getSchema()->once(__CLASS__.'@override-idle', function(Mapper $mapper) { |
|
| 97 | 97 | $mapper->getSchema()->getSpace('_temporal_override')->addProperty('idle', 'unsigned'); |
| 98 | 98 | }); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | private function initReference() |
| 102 | 102 | { |
| 103 | - $this->mapper->getSchema()->once(__CLASS__.'@reference', function (Mapper $mapper) { |
|
| 103 | + $this->mapper->getSchema()->once(__CLASS__.'@reference', function(Mapper $mapper) { |
|
| 104 | 104 | $mapper->getSchema() |
| 105 | 105 | ->createSpace('_temporal_reference', [ |
| 106 | 106 | 'idle' => 'unsigned', |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | ]; |
| 41 | 41 | |
| 42 | 42 | $changes = $mapper->find('_temporal_reference', $params); |
| 43 | - $states = $this->generateStates($changes, function ($state, $change) { |
|
| 43 | + $states = $this->generateStates($changes, function($state, $change) { |
|
| 44 | 44 | $state->data = $change->targetId; |
| 45 | 45 | }); |
| 46 | 46 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | 'targetId' => $entityId, |
| 67 | 67 | 'entity' => $params['entity'], |
| 68 | 68 | ]); |
| 69 | - $aggregates = $this->generateStates($changes, function ($state, $change) { |
|
| 69 | + $aggregates = $this->generateStates($changes, function($state, $change) { |
|
| 70 | 70 | if (!in_array($change->id, $state->data)) { |
| 71 | 71 | $state->data[] = $change->id; |
| 72 | 72 | } |
@@ -214,11 +214,11 @@ discard block |
||
| 214 | 214 | while (!$clean) { |
| 215 | 215 | $clean = true; |
| 216 | 216 | foreach ($states as $i => $state) { |
| 217 | - if (array_key_exists($i+1, $states)) { |
|
| 218 | - $next = $states[$i+1]; |
|
| 217 | + if (array_key_exists($i + 1, $states)) { |
|
| 218 | + $next = $states[$i + 1]; |
|
| 219 | 219 | if (json_encode($state->data) == json_encode($next->data)) { |
| 220 | 220 | $states[$i]->end = $next->end; |
| 221 | - unset($states[$i+1]); |
|
| 221 | + unset($states[$i + 1]); |
|
| 222 | 222 | $states = array_values($states); |
| 223 | 223 | $clean = false; |
| 224 | 224 | break; |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | ]; |
| 243 | 243 | |
| 244 | 244 | $changes = $mapper->find('_temporal_override', $params); |
| 245 | - $states = $this->generateStates($changes, function ($state, $change) { |
|
| 245 | + $states = $this->generateStates($changes, function($state, $change) { |
|
| 246 | 246 | $state->data = array_merge($state->data, $change->data); |
| 247 | 247 | }); |
| 248 | 248 | foreach ($mapper->find('_temporal_override_aggregate', $params) as $aggregate) { |
@@ -340,11 +340,11 @@ discard block |
||
| 340 | 340 | while (!$clean) { |
| 341 | 341 | $clean = true; |
| 342 | 342 | foreach ($states as $i => $state) { |
| 343 | - if (array_key_exists($i+1, $states)) { |
|
| 344 | - $next = $states[$i+1]; |
|
| 343 | + if (array_key_exists($i + 1, $states)) { |
|
| 344 | + $next = $states[$i + 1]; |
|
| 345 | 345 | if (json_encode($state->data) == json_encode($next->data)) { |
| 346 | 346 | $state->end = $next->end; |
| 347 | - unset($states[$i+1]); |
|
| 347 | + unset($states[$i + 1]); |
|
| 348 | 348 | $states = array_values($states); |
| 349 | 349 | $clean = false; |
| 350 | 350 | break; |
@@ -258,6 +258,9 @@ |
||
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | + /** |
|
| 262 | + * @param \Closure $callback |
|
| 263 | + */ |
|
| 261 | 264 | private function generateStates($changes, $callback) |
| 262 | 265 | { |
| 263 | 266 | $slices = []; |