@@ -16,12 +16,14 @@ class MySQL extends MariaDB
1616{
1717 /**
1818 * Set max execution time
19- *
19+ * @param int $milliseconds
20+ * @param string $event
21+ * @return void
2022 * @throws DatabaseException
2123 */
2224 public function setTimeout (int $ milliseconds , string $ event = Database::EVENT_ALL ): void
2325 {
24- if (! $ this ->getSupportForTimeouts ()) {
26+ if (!$ this ->getSupportForTimeouts ()) {
2527 return ;
2628 }
2729 if ($ milliseconds <= 0 ) {
@@ -42,28 +44,29 @@ public function setTimeout(int $milliseconds, string $event = Database::EVENT_AL
4244
4345 /**
4446 * Get size of collection on disk
45- *
47+ * @param string $collection
48+ * @return int
4649 * @throws DatabaseException
4750 */
4851 public function getSizeOfCollectionOnDisk (string $ collection ): int
4952 {
5053 $ collection = $ this ->filter ($ collection );
51- $ collection = $ this ->getNamespace (). '_ ' . $ collection ;
54+ $ collection = $ this ->getNamespace () . '_ ' . $ collection ;
5255 $ database = $ this ->getDatabase ();
53- $ name = $ database. '/ ' . $ collection ;
54- $ permissions = $ database. '/ ' . $ collection. '_perms ' ;
56+ $ name = $ database . '/ ' . $ collection ;
57+ $ permissions = $ database . '/ ' . $ collection . '_perms ' ;
5558
56- $ collectionSize = $ this ->getPDO ()->prepare ('
59+ $ collectionSize = $ this ->getPDO ()->prepare ("
5760 SELECT SUM(FS_BLOCK_SIZE + ALLOCATED_SIZE)
5861 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES
5962 WHERE NAME = :name
60- ' );
63+ " );
6164
62- $ permissionsSize = $ this ->getPDO ()->prepare ('
65+ $ permissionsSize = $ this ->getPDO ()->prepare ("
6366 SELECT SUM(FS_BLOCK_SIZE + ALLOCATED_SIZE)
6467 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES
6568 WHERE NAME = :permissions
66- ' );
69+ " );
6770
6871 $ collectionSize ->bindParam (':name ' , $ name );
6972 $ permissionsSize ->bindParam (':permissions ' , $ permissions );
@@ -73,7 +76,7 @@ public function getSizeOfCollectionOnDisk(string $collection): int
7376 $ permissionsSize ->execute ();
7477 $ size = $ collectionSize ->fetchColumn () + $ permissionsSize ->fetchColumn ();
7578 } catch (PDOException $ e ) {
76- throw new DatabaseException ('Failed to get collection size: ' . $ e ->getMessage ());
79+ throw new DatabaseException ('Failed to get collection size: ' . $ e ->getMessage ());
7780 }
7881
7982 return $ size ;
@@ -82,8 +85,14 @@ public function getSizeOfCollectionOnDisk(string $collection): int
8285 /**
8386 * Handle distance spatial queries
8487 *
85- * @param array<string, mixed> $binds
86- */
88+ * @param Query $query
89+ * @param array<string, mixed> $binds
90+ * @param string $attribute
91+ * @param string $type
92+ * @param string $alias
93+ * @param string $placeholder
94+ * @return string
95+ */
8796 protected function handleDistanceSpatialQueries (Query $ query , array &$ binds , string $ attribute , string $ type , string $ alias , string $ placeholder ): string
8897 {
8998 $ distanceParams = $ query ->getValues ()[0 ];
@@ -106,19 +115,17 @@ protected function handleDistanceSpatialQueries(Query $query, array &$binds, str
106115 $ operator = '< ' ;
107116 break ;
108117 default :
109- throw new DatabaseException ('Unknown spatial query method: ' . $ query ->getMethod ());
118+ throw new DatabaseException ('Unknown spatial query method: ' . $ query ->getMethod ());
110119 }
111120
112121 if ($ useMeters ) {
113- $ attr = "ST_SRID( {$ alias }. {$ attribute }, " . Database::DEFAULT_SRID . ' ) ' ;
122+ $ attr = "ST_SRID( {$ alias }. {$ attribute }, " . Database::DEFAULT_SRID . " ) " ;
114123 $ geom = $ this ->getSpatialGeomFromText (": {$ placeholder }_0 " , null );
115-
116124 return "ST_Distance( {$ attr }, {$ geom }, 'metre') {$ operator } : {$ placeholder }_1 " ;
117125 }
118126 // need to use srid 0 because of geometric distance
119- $ attr = "ST_SRID( {$ alias }. {$ attribute }, " . 0 .' ) ' ;
127+ $ attr = "ST_SRID( {$ alias }. {$ attribute }, " . 0 . " ) " ;
120128 $ geom = $ this ->getSpatialGeomFromText (": {$ placeholder }_0 " , 0 );
121-
122129 return "ST_Distance( {$ attr }, {$ geom }) {$ operator } : {$ placeholder }_1 " ;
123130 }
124131
@@ -132,7 +139,7 @@ public function getSupportForIndexArray(): bool
132139
133140 public function getSupportForCastIndexArray (): bool
134141 {
135- if (! $ this ->getSupportForIndexArray ()) {
142+ if (!$ this ->getSupportForIndexArray ()) {
136143 return false ;
137144 }
138145
@@ -166,25 +173,29 @@ protected function processException(PDOException $e): \Exception
166173
167174 return parent ::processException ($ e );
168175 }
169-
170176 /**
171177 * Does the adapter includes boundary during spatial contains?
178+ *
179+ * @return bool
172180 */
173181 public function getSupportForBoundaryInclusiveContains (): bool
174182 {
175183 return false ;
176184 }
177-
178185 /**
179186 * Does the adapter support order attribute in spatial indexes?
180- */
187+ *
188+ * @return bool
189+ */
181190 public function getSupportForSpatialIndexOrder (): bool
182191 {
183192 return false ;
184193 }
185194
186195 /**
187196 * Does the adapter support calculating distance(in meters) between multidimension geometry(line, polygon,etc)?
197+ *
198+ * @return bool
188199 */
189200 public function getSupportForDistanceBetweenMultiDimensionGeometryInMeters (): bool
190201 {
@@ -193,52 +204,51 @@ public function getSupportForDistanceBetweenMultiDimensionGeometryInMeters(): bo
193204
194205 /**
195206 * Spatial type attribute
196- */
207+ */
197208 public function getSpatialSQLType (string $ type , bool $ required ): string
198209 {
199210 switch ($ type ) {
200211 case Database::VAR_POINT :
201212 $ type = 'POINT SRID 4326 ' ;
202- if (! $ this ->getSupportForSpatialIndexNull ()) {
213+ if (!$ this ->getSupportForSpatialIndexNull ()) {
203214 if ($ required ) {
204215 $ type .= ' NOT NULL ' ;
205216 } else {
206217 $ type .= ' NULL ' ;
207218 }
208219 }
209-
210220 return $ type ;
211221
212222 case Database::VAR_LINESTRING :
213223 $ type = 'LINESTRING SRID 4326 ' ;
214- if (! $ this ->getSupportForSpatialIndexNull ()) {
224+ if (!$ this ->getSupportForSpatialIndexNull ()) {
215225 if ($ required ) {
216226 $ type .= ' NOT NULL ' ;
217227 } else {
218228 $ type .= ' NULL ' ;
219229 }
220230 }
221-
222231 return $ type ;
223232
233+
224234 case Database::VAR_POLYGON :
225235 $ type = 'POLYGON SRID 4326 ' ;
226- if (! $ this ->getSupportForSpatialIndexNull ()) {
236+ if (!$ this ->getSupportForSpatialIndexNull ()) {
227237 if ($ required ) {
228238 $ type .= ' NOT NULL ' ;
229239 } else {
230240 $ type .= ' NULL ' ;
231241 }
232242 }
233-
234243 return $ type ;
235244 }
236-
237245 return '' ;
238246 }
239247
240248 /**
241249 * Does the adapter support spatial axis order specification?
250+ *
251+ * @return bool
242252 */
243253 public function getSupportForSpatialAxisOrder (): bool
244254 {
@@ -253,6 +263,8 @@ public function getSupportForObjectIndexes(): bool
253263 /**
254264 * Get the spatial axis order specification string for MySQL
255265 * MySQL with SRID 4326 expects lat-long by default, but our data is in long-lat format
266+ *
267+ * @return string
256268 */
257269 protected function getSpatialAxisOrderSpec (): string
258270 {
@@ -261,6 +273,8 @@ protected function getSpatialAxisOrderSpec(): string
261273
262274 /**
263275 * Adapter supports optional spatial attributes with existing rows.
276+ *
277+ * @return bool
264278 */
265279 public function getSupportForOptionalSpatialAttributeWithExistingRows (): bool
266280 {
@@ -271,21 +285,24 @@ public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool
271285 * Get SQL expression for operator
272286 * Override for MySQL-specific operator implementations
273287 *
274- * @param array<string, mixed> $binds
288+ * @param string $column
289+ * @param \Utopia\Database\Operator $operator
290+ * @param array<string, mixed> $binds
291+ * @return ?string
275292 */
276- protected function getOperatorSQL (string $ column , Operator $ operator , array &$ binds ): ?string
293+ protected function getOperatorSQL (string $ column , \ Utopia \ Database \ Operator $ operator , array &$ binds ): ?string
277294 {
278295 $ quotedColumn = $ this ->quote ($ column );
279296 $ method = $ operator ->getMethod ();
280297 $ values = $ operator ->getValues ();
281298
282299 switch ($ method ) {
283- case Operator::TYPE_ARRAY_APPEND : $ bindKey = $ this -> registerOperatorBind ( $ binds , json_encode ( $ values ));
284-
300+ case Operator::TYPE_ARRAY_APPEND :
301+ $ bindKey = $ this -> registerOperatorBind ( $ binds , json_encode ( $ values ));
285302 return "{$ quotedColumn } = JSON_MERGE_PRESERVE(IFNULL( {$ quotedColumn }, JSON_ARRAY()), : $ bindKey) " ;
286303
287- case Operator::TYPE_ARRAY_PREPEND : $ bindKey = $ this -> registerOperatorBind ( $ binds , json_encode ( $ values ));
288-
304+ case Operator::TYPE_ARRAY_PREPEND :
305+ $ bindKey = $ this -> registerOperatorBind ( $ binds , json_encode ( $ values ));
289306 return "{$ quotedColumn } = JSON_MERGE_PRESERVE(: $ bindKey, IFNULL( {$ quotedColumn }, JSON_ARRAY())) " ;
290307
291308 case Operator::TYPE_ARRAY_UNIQUE :
0 commit comments