Skip to content

Commit

Permalink
Run Linter
Browse files Browse the repository at this point in the history
  • Loading branch information
PineappleIOnic committed Sep 17, 2024
1 parent a931aab commit 4f3e91e
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 70 deletions.
22 changes: 11 additions & 11 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public function createIndex(string $collection, string $id, string $type, array

$attributes[$i] = "`{$attr}`{$length} {$order}";

if(!empty($collectionAttribute['array']) && $this->castIndexArray()) {
if (!empty($collectionAttribute['array']) && $this->castIndexArray()) {
$attributes[$i] = '(CAST(' . $attr . ' AS char(' . Database::ARRAY_INDEX_LENGTH . ') ARRAY))';
}
}
Expand Down Expand Up @@ -871,7 +871,7 @@ public function createDocument(string $collection, Document $document): Document
$stmtPermissions->execute();
}
} catch (\Throwable $e) {
if($e instanceof PDOException) {
if ($e instanceof PDOException) {
switch ($e->getCode()) {
case 1062:
case 23000:
Expand Down Expand Up @@ -919,7 +919,7 @@ public function createDocuments(string $collection, array $documents, int $batch
$attributes['_createdAt'] = $document->getCreatedAt();
$attributes['_updatedAt'] = $document->getUpdatedAt();
$attributes['_permissions'] = \json_encode($document->getPermissions());
if(!empty($document->getInternalId())) {
if (!empty($document->getInternalId())) {
$attributes['_id'] = $document->getInternalId();
}

Expand Down Expand Up @@ -999,7 +999,7 @@ public function createDocuments(string $collection, array $documents, int $batch
}
}
} catch (\Throwable $e) {
if($e instanceof PDOException) {
if ($e instanceof PDOException) {
switch ($e->getCode()) {
case 1062:
case 23000:
Expand Down Expand Up @@ -1247,7 +1247,7 @@ public function updateDocument(string $collection, Document $document): Document
}

} catch (\Throwable $e) {
if($e instanceof PDOException) {
if ($e instanceof PDOException) {
switch ($e->getCode()) {
case 1062:
case 23000:
Expand Down Expand Up @@ -1504,7 +1504,7 @@ public function updateDocuments(string $collection, array $documents, int $batch
}
}
} catch (\Throwable $e) {
if($e instanceof PDOException) {
if ($e instanceof PDOException) {
switch ($e->getCode()) {
case 1062:
case 23000:
Expand Down Expand Up @@ -1651,7 +1651,7 @@ public function deleteDocuments(string $collection, array $queries): bool
$queries = array_map(fn ($query) => clone $query, $queries);

$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
if (!empty($conditions)) {
$where[] = $conditions;
}

Expand Down Expand Up @@ -1786,7 +1786,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
}

$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
if (!empty($conditions)) {
$where[] = $conditions;
}

Expand Down Expand Up @@ -1914,7 +1914,7 @@ public function count(string $collection, array $queries = [], ?int $max = null)
$queries = array_map(fn ($query) => clone $query, $queries);

$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
if (!empty($conditions)) {
$where[] = $conditions;
}

Expand Down Expand Up @@ -2131,7 +2131,7 @@ protected function getSQLCondition(Query $query): string
return "`table_main`.{$attribute} {$this->getSQLOperator($query->getMethod())}";

case Query::TYPE_CONTAINS:
if($this->getSupportForJSONOverlaps() && $query->onArray()) {
if ($this->getSupportForJSONOverlaps() && $query->onArray()) {
return "JSON_OVERLAPS(`table_main`.{$attribute}, :{$placeholder}_0)";
}

Expand All @@ -2157,7 +2157,7 @@ protected function getSQLCondition(Query $query): string
*/
protected function getSQLType(string $type, int $size, bool $signed = true, bool $array = false): string
{
if($array === true) {
if ($array === true) {
return 'JSON';
}

Expand Down
11 changes: 5 additions & 6 deletions src/Database/Adapter/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Utopia\Database\Adapter;

use Exception;

use MongoDB\BSON\ObjectId;
use MongoDB\BSON\Regex;
use MongoDB\BSON\UTCDateTime;
Expand Down Expand Up @@ -291,7 +290,7 @@ public function getSizeOfCollection(string $collection): int
} else {
throw new DatabaseException('No size found');
}
} catch(Exception $e) {
} catch (Exception $e) {
throw new DatabaseException('Failed to get collection size: ' . $e->getMessage());
}
}
Expand Down Expand Up @@ -935,8 +934,8 @@ public function deleteDocuments(string $collection, array $queries): bool

try {
$res = $this->client->delete(
collection: $name,
filters: $filters,
collection: $name,
filters: $filters,
options: $options,
limit: 0
);
Expand Down Expand Up @@ -1406,7 +1405,7 @@ protected function buildFilters(array $queries, string $separator = '$and'): arr
$queries = Query::groupByType($queries)['filters'];
foreach ($queries as $query) {
/* @var $query Query */
if($query->isNested()) {
if ($query->isNested()) {
$operator = $this->getQueryOperator($query->getMethod());
$filters[$separator][] = $this->buildFilters($query->getValues(), $operator);
} else {
Expand Down Expand Up @@ -1460,7 +1459,7 @@ protected function buildFilter(Query $query): array
} elseif ($operator == '$ne' && \is_array($value)) {
$filter[$attribute]['$nin'] = $value;
} elseif ($operator == '$in') {
if($query->getMethod() === Query::TYPE_CONTAINS && !$query->onArray()) {
if ($query->getMethod() === Query::TYPE_CONTAINS && !$query->onArray()) {
$filter[$attribute]['$regex'] = new Regex(".*{$this->escapeWildcards($value)}.*", 'i');
} else {
$filter[$attribute]['$in'] = $query->getValues();
Expand Down
16 changes: 8 additions & 8 deletions src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ public function createDocument(string $collection, Document $document): Document

$queryPermissions = $this->trigger(Database::EVENT_PERMISSIONS_CREATE, $queryPermissions);
$stmtPermissions = $this->getPDO()->prepare($queryPermissions);
if($sqlTenant) {
if ($sqlTenant) {
$stmtPermissions->bindValue(':_tenant', $this->tenant);
}
}
Expand Down Expand Up @@ -900,7 +900,7 @@ public function createDocuments(string $collection, array $documents, int $batch
$attributes['_updatedAt'] = $document->getUpdatedAt();
$attributes['_permissions'] = \json_encode($document->getPermissions());

if($this->sharedTables) {
if ($this->sharedTables) {
$attributes['_tenant'] = $this->tenant;
}

Expand Down Expand Up @@ -1232,7 +1232,7 @@ public function updateDocuments(string $collection, array $documents, int $batch
$attributes['_updatedAt'] = $document->getUpdatedAt();
$attributes['_permissions'] = json_encode($document->getPermissions());

if($this->sharedTables) {
if ($this->sharedTables) {
$attributes['_tenant'] = $this->tenant;
}

Expand Down Expand Up @@ -1424,7 +1424,7 @@ public function updateDocuments(string $collection, array $documents, int $batch
$stmtAddPermissions->bindValue($key, $value, $this->getPDOType($value));
}

if($this->sharedTables) {
if ($this->sharedTables) {
$stmtAddPermissions->bindValue(':_tenant', $this->tenant);
}

Expand Down Expand Up @@ -1575,7 +1575,7 @@ public function deleteDocuments(string $collection, array $queries): bool
$queries = array_map(fn ($query) => clone $query, $queries);

$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
if (!empty($conditions)) {
$where[] = $conditions;
}

Expand Down Expand Up @@ -1708,7 +1708,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
}

$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
if (!empty($conditions)) {
$where[] = $conditions;
}

Expand Down Expand Up @@ -1836,7 +1836,7 @@ public function count(string $collection, array $queries = [], ?int $max = null)
$queries = array_map(fn ($query) => clone $query, $queries);

$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
if (!empty($conditions)) {
$where[] = $conditions;
}

Expand Down Expand Up @@ -2076,7 +2076,7 @@ protected function getFulltextValue(string $value): string
*/
protected function getSQLType(string $type, int $size, bool $signed = true, bool $array = false): string
{
if($array === true) {
if ($array === true) {
return 'JSONB';
}

Expand Down
6 changes: 3 additions & 3 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,14 +818,14 @@ protected function bindConditionValue(mixed $stmt, Query $query): void
return;
}

if($query->isNested()) {
if ($query->isNested()) {
foreach ($query->getValues() as $value) {
$this->bindConditionValue($stmt, $value);
}
return;
}

if($this->getSupportForJSONOverlaps() && $query->onArray() && $query->getMethod() == Query::TYPE_CONTAINS) {
if ($this->getSupportForJSONOverlaps() && $query->onArray() && $query->getMethod() == Query::TYPE_CONTAINS) {
$placeholder = $this->getSQLPlaceholder($query) . '_0';
$stmt->bindValue($placeholder, json_encode($query->getValues()), PDO::PARAM_STR);
return;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ public function getSQLConditions(array $queries = [], string $separator = 'AND')
continue;
}

if($query->isNested()) {
if ($query->isNested()) {
$conditions[] = $this->getSQLConditions($query->getValues(), $query->getMethod());
} else {
$conditions[] = $this->getSQLCondition($query);
Expand Down
12 changes: 6 additions & 6 deletions src/Database/Adapter/SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public function createDocument(string $collection, Document $document): Document
$attributes['_updatedAt'] = $document->getUpdatedAt();
$attributes['_permissions'] = json_encode($document->getPermissions());

if($this->sharedTables) {
if ($this->sharedTables) {
$attributes['_tenant'] = $this->tenant;
}

Expand Down Expand Up @@ -522,7 +522,7 @@ public function createDocument(string $collection, Document $document): Document

$stmtPermissions = $this->getPDO()->prepare($queryPermissions);

if($this->sharedTables) {
if ($this->sharedTables) {
$stmtPermissions->bindValue(':_tenant', $this->tenant);
}
}
Expand Down Expand Up @@ -567,7 +567,7 @@ public function updateDocument(string $collection, Document $document): Document
$attributes['_updatedAt'] = $document->getUpdatedAt();
$attributes['_permissions'] = json_encode($document->getPermissions());

if($this->sharedTables) {
if ($this->sharedTables) {
$attributes['_tenant'] = $this->tenant;
}

Expand Down Expand Up @@ -701,7 +701,7 @@ public function updateDocument(string $collection, Document $document): Document
$stmtAddPermissions = $this->getPDO()->prepare($sql);

$stmtAddPermissions->bindValue(":_uid", $document->getId());
if($this->sharedTables) {
if ($this->sharedTables) {
$stmtAddPermissions->bindValue(":_tenant", $this->tenant);
}

Expand Down Expand Up @@ -814,7 +814,7 @@ public function updateDocuments(string $collection, array $documents, int $batch
$attributes['_updatedAt'] = $document->getUpdatedAt();
$attributes['_permissions'] = json_encode($document->getPermissions());

if($this->sharedTables) {
if ($this->sharedTables) {
$attributes['_tenant'] = $this->tenant;
}

Expand Down Expand Up @@ -1012,7 +1012,7 @@ public function updateDocuments(string $collection, array $documents, int $batch
$stmtAddPermissions->bindValue($key, $value, $this->getPDOType($value));
}

if($this->sharedTables) {
if ($this->sharedTables) {
$stmtAddPermissions->bindValue(':_tenant', $this->tenant);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -4331,7 +4331,7 @@ public function increaseDocumentAttribute(string $collection, string $id, string
/* @var $document Document */
$document = Authorization::skip(fn () => $this->silent(fn () => $this->getDocument($collection, $id))); // Skip ensures user does not need read permission for this

if($document->isEmpty()) {
if ($document->isEmpty()) {
return false;
}

Expand Down Expand Up @@ -4426,7 +4426,7 @@ public function decreaseDocumentAttribute(string $collection, string $id, string
/* @var $document Document */
$document = Authorization::skip(fn () => $this->silent(fn () => $this->getDocument($collection, $id))); // Skip ensures user does not need read permission for this

if($document->isEmpty()) {
if ($document->isEmpty()) {
return false;
}

Expand Down Expand Up @@ -4521,7 +4521,7 @@ public function deleteDocument(string $collection, string $id): bool
$this->getDocument($collection->getId(), $id, forUpdate: true)
));

if($document->isEmpty()) {
if ($document->isEmpty()) {
return false;
}

Expand Down Expand Up @@ -5190,7 +5190,7 @@ public function find(string $collection, array $queries = []): array

$results = $skipAuth ? Authorization::skip($getResults) : $getResults();

foreach ($results as &$node) {
foreach ($results as &$node) {
if ($this->resolveRelationships && (empty($selects) || !empty($nestedSelections))) {
$node = $this->silent(fn () => $this->populateDocumentRelationships($collection, $node, $nestedSelections));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Exception extends \Exception
{
public function __construct(string $message, int|string $code = 0, Throwable $previous = null)
{
if(\is_string($code)) {
if (\is_string($code)) {
if (\is_numeric($code)) {
$code = (int) $code;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function toArray(): array
{
$array = ['method' => $this->method];

if(!empty($this->attribute)) {
if (!empty($this->attribute)) {
$array['attribute'] = $this->attribute;
}

Expand Down Expand Up @@ -690,7 +690,7 @@ public static function groupByType(array $queries): array
*/
public function isNested(): bool
{
if(in_array($this->getMethod(), self::LOGICAL_TYPES)) {
if (in_array($this->getMethod(), self::LOGICAL_TYPES)) {
return true;
}

Expand Down
Loading

0 comments on commit 4f3e91e

Please sign in to comment.