@@ -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) { |
@@ -18,8 +18,8 @@ |
||
18 | 18 | $client = $this->getClient(); |
19 | 19 | } |
20 | 20 | return (new Finder($client)) |
21 | - ->database($this->getDatabaseName()) |
|
22 | - ->from($this->getResourceName()); |
|
21 | + ->database($this->getDatabaseName()) |
|
22 | + ->from($this->getResourceName()); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function validateUniqueFields() |
@@ -40,10 +40,10 @@ |
||
40 | 40 | |
41 | 41 | protected function addWhereGroup($collection, $conditions, $logical) |
42 | 42 | { |
43 | - /** |
|
44 | - * @codeCoverageIgnore |
|
45 | - * Passing anonymous function to Clusterpoint API |
|
46 | - */ |
|
43 | + /** |
|
44 | + * @codeCoverageIgnore |
|
45 | + * Passing anonymous function to Clusterpoint API |
|
46 | + */ |
|
47 | 47 | return function ($collection) use ($conditions, $logical) { |
48 | 48 | $this->parseWhere($collection, $conditions, $logical); |
49 | 49 | }; |
@@ -42,6 +42,9 @@ discard block |
||
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | + /** |
|
46 | + * @param \Clusterpoint\Instance\Service $collection |
|
47 | + */ |
|
45 | 48 | protected function configQuery($collection) |
46 | 49 | { |
47 | 50 | $this->setLimit($collection); |
@@ -90,6 +93,9 @@ discard block |
||
90 | 93 | }; |
91 | 94 | } |
92 | 95 | |
96 | + /** |
|
97 | + * @param string $nextLogical |
|
98 | + */ |
|
93 | 99 | protected function parseWhereGroup($logical, $collection, $condition, $nextLogical) |
94 | 100 | { |
95 | 101 | if ($logical === '||') { |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | ); |
61 | 61 | } |
62 | 62 | $collection = $this->client->database( |
63 | - $this->queryConfiguration->databaseName. |
|
64 | - '.'. |
|
63 | + $this->queryConfiguration->databaseName . |
|
64 | + '.' . |
|
65 | 65 | $this->queryConfiguration->from |
66 | 66 | ); |
67 | 67 | $this->configQuery($collection); |
68 | 68 | $items = json_decode(json_encode($collection->get()->toArray())); |
69 | 69 | $count = count($items); |
70 | - for ($idx=0; $idx<$count; $idx++) { |
|
70 | + for ($idx = 0; $idx < $count; $idx++) { |
|
71 | 71 | $this->resultSet[] = $items[$idx]; |
72 | 72 | } |
73 | 73 | return $this; |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @codeCoverageIgnore |
86 | 86 | * Passing anonymous function to Clusterpoint API |
87 | 87 | */ |
88 | - return function ($collection) use ($conditions, $logical) { |
|
88 | + return function($collection) use ($conditions, $logical) { |
|
89 | 89 | $this->parseWhere($collection, $conditions, $logical); |
90 | 90 | }; |
91 | 91 | } |
@@ -18,8 +18,8 @@ |
||
18 | 18 | $client = $this->getClient(); |
19 | 19 | } |
20 | 20 | return (new Finder($client)) |
21 | - ->database($this->getDatabaseName()) |
|
22 | - ->from($this->getResourceName()); |
|
21 | + ->database($this->getDatabaseName()) |
|
22 | + ->from($this->getResourceName()); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function validateUniqueFields() |
@@ -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]] |
@@ -39,13 +38,13 @@ discard block |
||
39 | 38 | private function getUniqueFieldQuery() |
40 | 39 | { |
41 | 40 | $uniqueFields = $this->getUniqueFields(); |
42 | - $query = $this->getClient()->database($this->getDatabaseName().'.'.$this->resourceName); |
|
41 | + $query = $this->getClient()->database($this->getDatabaseName() . '.' . $this->resourceName); |
|
43 | 42 | if ($this->isModification()) { |
44 | 43 | $uniqueFields = array_diff($uniqueFields, [$this->primaryKey]); |
45 | 44 | $query->where($this->primaryKey, '!=', $this->getPrimaryKeyValue()); |
46 | 45 | } |
47 | 46 | // @codeCoverageIgnoreStart |
48 | - $query->where(function ($query) use ($uniqueFields) { |
|
47 | + $query->where(function($query) use ($uniqueFields) { |
|
49 | 48 | foreach ($uniqueFields as $fieldName) { |
50 | 49 | if (property_exists($this->resource, $fieldName)) { |
51 | 50 | $query->orWhere($fieldName, '==', $this->resource->{$fieldName}); |
@@ -66,7 +65,7 @@ discard block |
||
66 | 65 | |
67 | 66 | public function query() |
68 | 67 | { |
69 | - $query = $this->getClient()->database($this->getDatabaseName().'.'.$this->resourceName); |
|
68 | + $query = $this->getClient()->database($this->getDatabaseName() . '.' . $this->resourceName); |
|
70 | 69 | return $query; |
71 | 70 | } |
72 | 71 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $object->{$this->primaryKey}; |
58 | 58 | return $newResource; |
59 | 59 | } catch (\Exception $ex) { |
60 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
60 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ?null:$res]); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $this->failOnError($res); |
69 | 69 | return $this->toObject($res); |
70 | 70 | } catch (\Exception $ex) { |
71 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
71 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ?null:$res]); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $this->failOnError($res); |
80 | 80 | return $this->toObject($res); |
81 | 81 | } catch (\Exception $ex) { |
82 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
82 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ?null:$res]); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $this->failOnError($res); |
91 | 91 | return $this->toObject($res); |
92 | 92 | } catch (\Exception $ex) { |
93 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
93 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ?null:$res]); |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
@@ -100,8 +100,7 @@ discard block |
||
100 | 100 | return; |
101 | 101 | } |
102 | 102 | $message = $res->error()[0]->message === 'Requested document does not exist' ? |
103 | - 'Resource does not exist' : |
|
104 | - 'Database operation failed'; |
|
103 | + 'Resource does not exist' : 'Database operation failed'; |
|
105 | 104 | throw new RestException( |
106 | 105 | $message, |
107 | 106 | [ |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | } catch (DynamoDbException $ex) { |
120 | 120 | $this->throwAwsPutError($ex); |
121 | 121 | } catch (\Exception $ex) { |
122 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
122 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ?null:$res]); |
|
123 | 123 | } |
124 | 124 | return $newResource; |
125 | 125 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $res = $this->client->deleteItem($query); |
132 | 132 | return $resourceId; |
133 | 133 | } catch (\Exception $ex) { |
134 | - throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]); |
|
134 | + throw new RestException($ex->getMessage(), ['result'=>empty($res) ?null:$res]); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | } |
@@ -143,6 +143,10 @@ discard block |
||
143 | 143 | return $errors; |
144 | 144 | } |
145 | 145 | |
146 | + /** |
|
147 | + * @param string $paramKey |
|
148 | + * @param boolean|null $paramValue |
|
149 | + */ |
|
146 | 150 | private function filterFields($resource, $paramKey, $paramValue, $checkParamValue = true) |
147 | 151 | { |
148 | 152 | $fields = []; |
@@ -158,6 +162,9 @@ discard block |
||
158 | 162 | return $fields; |
159 | 163 | } |
160 | 164 | |
165 | + /** |
|
166 | + * @param boolean $checkRequired |
|
167 | + */ |
|
161 | 168 | private function isMatchedValue($checkRequired, $value, $valueToMatch) |
162 | 169 | { |
163 | 170 | if (!$checkRequired) { |
@@ -108,7 +108,7 @@ |
||
108 | 108 | return $errors; |
109 | 109 | } |
110 | 110 | if (!empty($diff = array_diff($this->getRequiredFields($resource), array_keys(get_object_vars($resource))))) { |
111 | - array_walk($diff, function ($item, $key) use (&$errors) { |
|
111 | + array_walk($diff, function($item, $key) use (&$errors) { |
|
112 | 112 | $errors[$item] = 'Missing required field'; |
113 | 113 | }); |
114 | 114 | } |