Passed
Branch query-builder (144da5)
by Csaba
02:37
created
src/Database/Clusterpoint/Resource.php 1 patch
Spacing   +5 added lines, -7 removed lines patch added patch discarded remove patch
@@ -52,11 +52,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             [
Please login to merge, or discard this patch.
bootstrap.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
clusterpoint-example.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@
 block discarded – undo
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/',
Please login to merge, or discard this patch.
src/Database/DynamoDb/RestObject.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
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()
Please login to merge, or discard this patch.
src/Database/DynamoDb/Resource.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         } catch (DynamoDbException $ex) {
116 116
             $this->throwAwsPutError($ex);
117 117
         } catch (\Exception $ex) {
118
-            throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]);
118
+            throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]);
119 119
         }
120 120
         return $newResource;
121 121
     }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
             $res = $this->client->deleteItem($query);
128 128
             return $resourceId;
129 129
         } catch (\Exception $ex) {
130
-            throw new RestException($ex->getMessage(), ['result'=>empty($res)?null:$res]);
130
+            throw new RestException($ex->getMessage(), ['result'=>empty($res) ? null : $res]);
131 131
         }
132 132
     }
133 133
 }
Please login to merge, or discard this patch.
src/Database/Clusterpoint/RestObject.php 2 patches
Spacing   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,8 +32,7 @@  discard block
 block discarded – undo
32 32
         if ((int)$res->hits() > 0) {
33 33
             $results = json_decode($res->rawResponse())->results;
34 34
             $message = $results[0]->{$this->primaryKey} === $this->getPrimaryKeyValue() ?
35
-                'Primary key collision' :
36
-                'Unique constraint violation';
35
+                'Primary key collision' : 'Unique constraint violation';
37 36
             throw new RestException(
38 37
                 $message,
39 38
                 ['resourceName' => $this->resourceName, 'confilct' => $results[0]]
@@ -44,7 +43,7 @@  discard block
 block discarded – undo
44 43
     private function getUniqueFieldQuery($query, $uniqueFields)
45 44
     {
46 45
         // @codeCoverageIgnoreStart
47
-        $query->where(function ($query) use ($uniqueFields) {
46
+        $query->where(function($query) use ($uniqueFields) {
48 47
             foreach ($uniqueFields as $fieldName) {
49 48
                 if (property_exists($this->resource, $fieldName)) {
50 49
                     $query->orWhere($fieldName, '==', $this->resource->{$fieldName});
@@ -57,7 +56,7 @@  discard block
 block discarded – undo
57 56
 
58 57
     public function query()
59 58
     {
60
-        $query = $this->database->getClient()->database($this->database->getDatabaseName().'.'.$this->resourceName);
59
+        $query = $this->database->getClient()->database($this->database->getDatabaseName() . '.' . $this->resourceName);
61 60
         return $query;
62 61
     }
63 62
 }
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
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()
Please login to merge, or discard this patch.
src/Database/Clusterpoint/Finder.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@
 block discarded – undo
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
         };
Please login to merge, or discard this patch.
Doc Comments   +18 added lines patch added patch discarded remove patch
@@ -7,6 +7,9 @@  discard block
 block discarded – undo
7 7
 
8 8
 class Finder extends BaseFinder
9 9
 {
10
+    /**
11
+     * @param \Clusterpoint\Instance\Service $collection
12
+     */
10 13
     protected function setLimit($collection)
11 14
     {
12 15
         if ($this->queryConfiguration->limit !== null) {
@@ -14,6 +17,9 @@  discard block
 block discarded – undo
14 17
         }
15 18
     }
16 19
 
20
+    /**
21
+     * @param \Clusterpoint\Instance\Service $collection
22
+     */
17 23
     protected function setOffset($collection)
18 24
     {
19 25
         if ($this->queryConfiguration->offset !== null) {
@@ -21,6 +27,9 @@  discard block
 block discarded – undo
21 27
         }
22 28
     }
23 29
 
30
+    /**
31
+     * @param \Clusterpoint\Instance\Service $collection
32
+     */
24 33
     protected function setOrderBy($collection)
25 34
     {
26 35
         foreach ($this->queryConfiguration->orderBy as $orderBy) {
@@ -28,6 +37,9 @@  discard block
 block discarded – undo
28 37
         }
29 38
     }
30 39
 
40
+    /**
41
+     * @param \Clusterpoint\Instance\Service $collection
42
+     */
31 43
     protected function setSelect($collection)
32 44
     {
33 45
         if ($this->queryConfiguration->select !== '*') {
@@ -35,6 +47,9 @@  discard block
 block discarded – undo
35 47
         }
36 48
     }
37 49
 
50
+    /**
51
+     * @param \Clusterpoint\Instance\Service $collection
52
+     */
38 53
     public function setWhere($collection)
39 54
     {
40 55
         if (!empty($this->queryConfiguration->where)) {
@@ -85,6 +100,9 @@  discard block
 block discarded – undo
85 100
         };
86 101
     }
87 102
 
103
+    /**
104
+     * @param string $nextLogical
105
+     */
88 106
     protected function parseWhereGroup($logical, $collection, $condition, $nextLogical)
89 107
     {
90 108
         if ($logical === '||') {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
             );
52 52
         }
53 53
         $collection = $this->client->database(
54
-            $this->queryConfiguration->databaseName.
55
-            '.'.
54
+            $this->queryConfiguration->databaseName .
55
+            '.' .
56 56
             $this->queryConfiguration->from
57 57
         );
58 58
         $this->setLimit($collection);
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         $this->setWhere($collection);
63 63
         $items = json_decode(json_encode($collection->get()->toArray()));
64 64
         $c = count($items);
65
-        for ($i=0; $i<$c; $i++) {
65
+        for ($i = 0; $i < $c; $i++) {
66 66
             $this->resultSet[] = $items[$i];
67 67
         }
68 68
         return $this;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
       * @codeCoverageIgnore
81 81
       * Passing anonymous function to Clusterpoint API
82 82
       */
83
-        return function ($collection) use ($conditions, $logical) {
83
+        return function($collection) use ($conditions, $logical) {
84 84
             $this->parseWhere($collection, $conditions, $logical);
85 85
         };
86 86
     }
Please login to merge, or discard this patch.