@@ -6,7 +6,6 @@  | 
                                                    ||
| 6 | 6 | use Aws\DynamoDb\Marshaler;  | 
                                                        
| 7 | 7 | use Fathomminds\Rest\Exceptions\RestException;  | 
                                                        
| 8 | 8 | use Fathomminds\Rest\Contracts\IResource;  | 
                                                        
| 9 | -use Fathomminds\Rest\Helpers\Uuid;  | 
                                                        |
| 10 | 9 | use Aws\DynamoDb\Exception\DynamoDbException;  | 
                                                        
| 11 | 10 | |
| 12 | 11 | class Resource implements IResource  | 
                                                        
@@ -142,7 +142,7 @@ discard block  | 
                                                    ||
| 142 | 142 |          } catch (DynamoDbException $ex) { | 
                                                        
| 143 | 143 | $this->throwAwsPutError($ex);  | 
                                                        
| 144 | 144 |          } catch (\Exception $ex) { | 
                                                        
| 145 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]);  | 
                                                        |
| 145 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]);  | 
                                                        |
| 146 | 146 | }  | 
                                                        
| 147 | 147 | return $newResource;  | 
                                                        
| 148 | 148 | }  | 
                                                        
@@ -165,7 +165,7 @@ discard block  | 
                                                    ||
| 165 | 165 | $res = $this->client->deleteItem($query);  | 
                                                        
| 166 | 166 | return $resourceId;  | 
                                                        
| 167 | 167 |          } catch (\Exception $ex) { | 
                                                        
| 168 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]);  | 
                                                        |
| 168 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]);  | 
                                                        |
| 169 | 169 | }  | 
                                                        
| 170 | 170 | }  | 
                                                        
| 171 | 171 | |
@@ -85,6 +85,9 @@ discard block  | 
                                                    ||
| 85 | 85 | return $query;  | 
                                                        
| 86 | 86 | }  | 
                                                        
| 87 | 87 | |
| 88 | + /**  | 
                                                        |
| 89 | + * @param DynamoDbException $exception  | 
                                                        |
| 90 | + */  | 
                                                        |
| 88 | 91 | protected function throwAwsPostError($exception)  | 
                                                        
| 89 | 92 |      { | 
                                                        
| 90 | 93 |          switch ($exception->getAwsErrorCode()) { | 
                                                        
@@ -121,6 +124,9 @@ discard block  | 
                                                    ||
| 121 | 124 | return $query;  | 
                                                        
| 122 | 125 | }  | 
                                                        
| 123 | 126 | |
| 127 | + /**  | 
                                                        |
| 128 | + * @param DynamoDbException $exception  | 
                                                        |
| 129 | + */  | 
                                                        |
| 124 | 130 | protected function throwAwsPutError($exception)  | 
                                                        
| 125 | 131 |      { | 
                                                        
| 126 | 132 |          switch ($exception->getAwsErrorCode()) { | 
                                                        
@@ -26,8 +26,7 @@ discard block  | 
                                                    ||
| 26 | 26 |          if ((int)$res->hits() > 0) { | 
                                                        
| 27 | 27 | $results = json_decode($res->rawResponse())->results;  | 
                                                        
| 28 | 28 |              $message = $results[0]->{$this->primaryKey} === $this->getPrimaryKeyValue() ? | 
                                                        
| 29 | - 'Primary key collision' :  | 
                                                        |
| 30 | - 'Unique constraint violation';  | 
                                                        |
| 29 | + 'Primary key collision' : 'Unique constraint violation';  | 
                                                        |
| 31 | 30 | throw new RestException(  | 
                                                        
| 32 | 31 | $message,  | 
                                                        
| 33 | 32 | ['resourceName' => $this->resourceName, 'confilct' => $results[0]]  | 
                                                        
@@ -38,7 +37,7 @@ discard block  | 
                                                    ||
| 38 | 37 | private function getUniqueFieldQuery($query, $uniqueFields)  | 
                                                        
| 39 | 38 |      { | 
                                                        
| 40 | 39 | // @codeCoverageIgnoreStart  | 
                                                        
| 41 | -        $query->where(function ($query) use ($uniqueFields) { | 
                                                        |
| 40 | +        $query->where(function($query) use ($uniqueFields) { | 
                                                        |
| 42 | 41 |              foreach ($uniqueFields as $fieldName) { | 
                                                        
| 43 | 42 |                  if (property_exists($this->resource, $fieldName)) { | 
                                                        
| 44 | 43 |                      $query->orWhere($fieldName, '==', $this->resource->{$fieldName}); | 
                                                        
@@ -52,11 +52,10 @@ discard block  | 
                                                    ||
| 52 | 52 | $this->failOnError($res);  | 
                                                        
| 53 | 53 | $object = $this->toObject($res);  | 
                                                        
| 54 | 54 |              $newResource->{$this->primaryKey} = empty($object->{$this->primaryKey}) ? | 
                                                        
| 55 | - null :  | 
                                                        |
| 56 | -                $object->{$this->primaryKey}; | 
                                                        |
| 55 | +                null : $object->{$this->primaryKey}; | 
                                                        |
| 57 | 56 | return $newResource;  | 
                                                        
| 58 | 57 |          } catch (\Exception $ex) { | 
                                                        
| 59 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]);  | 
                                                        |
| 58 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]);  | 
                                                        |
| 60 | 59 | }  | 
                                                        
| 61 | 60 | }  | 
                                                        
| 62 | 61 | |
@@ -67,7 +66,7 @@ discard block  | 
                                                    ||
| 67 | 66 | $this->failOnError($res);  | 
                                                        
| 68 | 67 | return $this->toObject($res);  | 
                                                        
| 69 | 68 |          } catch (\Exception $ex) { | 
                                                        
| 70 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]);  | 
                                                        |
| 69 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]);  | 
                                                        |
| 71 | 70 | }  | 
                                                        
| 72 | 71 | }  | 
                                                        
| 73 | 72 | |
@@ -78,7 +77,7 @@ discard block  | 
                                                    ||
| 78 | 77 | $this->failOnError($res);  | 
                                                        
| 79 | 78 | return $this->toObject($res);  | 
                                                        
| 80 | 79 |          } catch (\Exception $ex) { | 
                                                        
| 81 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]);  | 
                                                        |
| 80 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]);  | 
                                                        |
| 82 | 81 | }  | 
                                                        
| 83 | 82 | }  | 
                                                        
| 84 | 83 | |
@@ -88,8 +87,7 @@ discard block  | 
                                                    ||
| 88 | 87 | return;  | 
                                                        
| 89 | 88 | }  | 
                                                        
| 90 | 89 | $message = $res->error()[0]->message === 'Requested document does not exist' ?  | 
                                                        
| 91 | - 'Resource does not exist' :  | 
                                                        |
| 92 | - 'Database operation failed';  | 
                                                        |
| 90 | + 'Resource does not exist' : 'Database operation failed';  | 
                                                        |
| 93 | 91 | throw new RestException(  | 
                                                        
| 94 | 92 | $message,  | 
                                                        
| 95 | 93 | [  | 
                                                        
@@ -41,7 +41,7 @@  | 
                                                    ||
| 41 | 41 | |
| 42 | 42 | public function __construct()  | 
                                                        
| 43 | 43 |      { | 
                                                        
| 44 | -        $this->setDefault('_id', function () { | 
                                                        |
| 44 | +        $this->setDefault('_id', function() { | 
                                                        |
| 45 | 45 | return (new Uuid)->generate();  | 
                                                        
| 46 | 46 | });  | 
                                                        
| 47 | 47 | }  | 
                                                        
@@ -1,12 +1,12 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | include_once __DIR__ . '/vendor/autoload.php';  | 
                                                        
| 3 | -if (!is_file(__DIR__. '/clusterpoint.php')) { | 
                                                        |
| 4 | - copy(__DIR__. '/clusterpoint-example.php', __DIR__. '/clusterpoint.php');  | 
                                                        |
| 3 | +if (!is_file(__DIR__ . '/clusterpoint.php')) { | 
                                                        |
| 4 | + copy(__DIR__ . '/clusterpoint-example.php', __DIR__ . '/clusterpoint.php');  | 
                                                        |
| 5 | 5 | }  | 
                                                        
| 6 | -if (!is_file(__DIR__. '/.env')) { | 
                                                        |
| 7 | - copy(__DIR__. '/.env-example', __DIR__. '/.env');  | 
                                                        |
| 6 | +if (!is_file(__DIR__ . '/.env')) { | 
                                                        |
| 7 | + copy(__DIR__ . '/.env-example', __DIR__ . '/.env');  | 
                                                        |
| 8 | 8 | }  | 
                                                        
| 9 | -if (is_file(__DIR__. '/.env')) { | 
                                                        |
| 9 | +if (is_file(__DIR__ . '/.env')) { | 
                                                        |
| 10 | 10 | $dotenv = new Dotenv\Dotenv(__DIR__);  | 
                                                        
| 11 | 11 | $dotenv->load();  | 
                                                        
| 12 | 12 | }  | 
                                                        
@@ -20,11 +20,11 @@  | 
                                                    ||
| 20 | 20 | |
| 21 | 21 | return [  | 
                                                        
| 22 | 22 | 'default' => [  | 
                                                        
| 23 | -      'host' => getenv('CLUSTERPOINT_HOST'), | 
                                                        |
| 24 | -      'account_id' => getenv('CLUSTERPOINT_ACCOUNT_ID'), | 
                                                        |
| 25 | -      'username' => getenv('CLUSTERPOINT_USERNAME'), | 
                                                        |
| 26 | -      'password' => getenv('CLUSTERPOINT_PASSWORD'), | 
                                                        |
| 27 | -      'debug' => getenv('CLUSTERPOINT_DEBUG_MODE'), | 
                                                        |
| 23 | +        'host' => getenv('CLUSTERPOINT_HOST'), | 
                                                        |
| 24 | +        'account_id' => getenv('CLUSTERPOINT_ACCOUNT_ID'), | 
                                                        |
| 25 | +        'username' => getenv('CLUSTERPOINT_USERNAME'), | 
                                                        |
| 26 | +        'password' => getenv('CLUSTERPOINT_PASSWORD'), | 
                                                        |
| 27 | +        'debug' => getenv('CLUSTERPOINT_DEBUG_MODE'), | 
                                                        |
| 28 | 28 | ],  | 
                                                        
| 29 | 29 | 'development' => [  | 
                                                        
| 30 | 30 | 'host' => 'https://api-eu.clusterpoint.com/v4/',  | 
                                                        
@@ -34,7 +34,7 @@ discard block  | 
                                                    ||
| 34 | 34 | $indexedFields = array_intersect($uniqueFields, $indexes); //Is unique and value is set and is indexed  | 
                                                        
| 35 | 35 | sort($uniqueFields);  | 
                                                        
| 36 | 36 | sort($indexedFields);  | 
                                                        
| 37 | - return $uniqueFields===$indexedFields;  | 
                                                        |
| 37 | + return $uniqueFields === $indexedFields;  | 
                                                        |
| 38 | 38 | }  | 
                                                        
| 39 | 39 | |
| 40 | 40 | protected function scanUniqueFields($fields)  | 
                                                        
@@ -60,7 +60,7 @@ discard block  | 
                                                    ||
| 60 | 60 | $filter = $this->generateScanFilter($fields);  | 
                                                        
| 61 | 61 |          if (property_exists($this->resource, $this->primaryKey)) { | 
                                                        
| 62 | 62 | $marshaler = new Marshaler;  | 
                                                        
| 63 | -            $filter['FilterExpression'] = '('.$filter['FilterExpression'].') AND #pk<>:pk'; | 
                                                        |
| 63 | +            $filter['FilterExpression'] = '(' . $filter['FilterExpression'] . ') AND #pk<>:pk'; | 
                                                        |
| 64 | 64 | $filter['ExpressionAttributeNames']['#pk'] = $this->primaryKey;  | 
                                                        
| 65 | 65 | $filter['ExpressionAttributeValues'][':pk'] = $marshaler->marshalValue(  | 
                                                        
| 66 | 66 |                  $this->resource->{$this->primaryKey} | 
                                                        
@@ -84,9 +84,9 @@ discard block  | 
                                                    ||
| 84 | 84 | ];  | 
                                                        
| 85 | 85 |          foreach ($fields as $field) { | 
                                                        
| 86 | 86 |              if (property_exists($this->resource, $field)) { | 
                                                        
| 87 | - $ret['FilterExpression'] .= '#'.$field.'=:'.$field.' OR ';  | 
                                                        |
| 88 | - $ret['ExpressionAttributeNames']['#'.$field] = $field;  | 
                                                        |
| 89 | - $ret['ExpressionAttributeValues'][':'.$field] = $marshaler->marshalValue(  | 
                                                        |
| 87 | + $ret['FilterExpression'] .= '#' . $field . '=:' . $field . ' OR ';  | 
                                                        |
| 88 | + $ret['ExpressionAttributeNames']['#' . $field] = $field;  | 
                                                        |
| 89 | + $ret['ExpressionAttributeValues'][':' . $field] = $marshaler->marshalValue(  | 
                                                        |
| 90 | 90 |                      $this->resource->{$field} | 
                                                        
| 91 | 91 | );  | 
                                                        
| 92 | 92 | }  | 
                                                        
@@ -130,10 +130,10 @@ discard block  | 
                                                    ||
| 130 | 130 | $marshaler = new Marshaler;  | 
                                                        
| 131 | 131 | $query = [  | 
                                                        
| 132 | 132 | 'TableName' => $this->database->getDatabaseName() . '-' . $this->resourceName,  | 
                                                        
| 133 | - 'KeyConditionExpression' => '#'.$field.'=:'.$field,  | 
                                                        |
| 133 | + 'KeyConditionExpression' => '#' . $field . '=:' . $field,  | 
                                                        |
| 134 | 134 | 'IndexName' => $this->indexNames[$field],  | 
                                                        
| 135 | - 'ExpressionAttributeNames' => ['#'.$field => $field],  | 
                                                        |
| 136 | - 'ExpressionAttributeValues' => [':'.$field => $marshaler->marshalValue(  | 
                                                        |
| 135 | + 'ExpressionAttributeNames' => ['#' . $field => $field],  | 
                                                        |
| 136 | + 'ExpressionAttributeValues' => [':' . $field => $marshaler->marshalValue(  | 
                                                        |
| 137 | 137 |                  $this->resource->{$field} | 
                                                        
| 138 | 138 | )],  | 
                                                        
| 139 | 139 | ];  | 
                                                        
@@ -160,7 +160,7 @@ discard block  | 
                                                    ||
| 160 | 160 | protected function generatePromise($client, $request)  | 
                                                        
| 161 | 161 |      { | 
                                                        
| 162 | 162 | $promise = new Promise(  | 
                                                        
| 163 | -            function () use (&$promise, $client, $request) { | 
                                                        |
| 163 | +            function() use (&$promise, $client, $request) { | 
                                                        |
| 164 | 164 | $query = new Query($client, $request);  | 
                                                        
| 165 | 165 |                  while ($res = $query->next()) { | 
                                                        
| 166 | 166 |                      if ($res['Count'] !== 0) { |