From 8b5f9cab339d0ecd76b59de0db67a00948492f82 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 8 Nov 2022 11:09:34 +0200 Subject: [PATCH] pint check --- pint.json | 5 +--- src/Adapter/SwooleClient.php | 1 - src/Adapter/SwooleCoroutineClient.php | 3 +- src/Auth.php | 4 +-- src/Client.php | 42 +++++++++++++++++---------- src/Exception.php | 3 +- tests/MongoTest.php | 19 +++++++----- 7 files changed, 43 insertions(+), 34 deletions(-) diff --git a/pint.json b/pint.json index 940cc35bf1..ef654c64d1 100644 --- a/pint.json +++ b/pint.json @@ -1,6 +1,3 @@ { - "preset": "psr12", - "exclude": [ - "tests/" - ] + "preset": "psr12" } \ No newline at end of file diff --git a/src/Adapter/SwooleClient.php b/src/Adapter/SwooleClient.php index 9dce323acd..c1a86f24ac 100644 --- a/src/Adapter/SwooleClient.php +++ b/src/Adapter/SwooleClient.php @@ -6,7 +6,6 @@ use Utopia\Mongo\Adapter; class SwooleClient extends Adapter { - public function isConnected(): bool { // TODO: Implement isConnected() method. diff --git a/src/Adapter/SwooleCoroutineClient.php b/src/Adapter/SwooleCoroutineClient.php index 783c0dfe93..07d5f5eca2 100644 --- a/src/Adapter/SwooleCoroutineClient.php +++ b/src/Adapter/SwooleCoroutineClient.php @@ -6,7 +6,6 @@ use Utopia\Mongo\Adapter; class SwooleCoroutineClient extends Adapter { - public function isConnected(): bool { // TODO: Implement isConnected() method. @@ -26,4 +25,4 @@ class SwooleCoroutineClient extends Adapter { // TODO: Implement recv() method. } -} \ No newline at end of file +} diff --git a/src/Auth.php b/src/Auth.php index 352a296207..047959bc39 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -285,8 +285,8 @@ class Auth /** * @return string */ - static function encodeCredentials($username, $password): string + public static function encodeCredentials($username, $password): string { return \md5(\utf8_encode($username . ':mongo:' . $password)); } -} \ No newline at end of file +} diff --git a/src/Client.php b/src/Client.php index 74d7d48304..d224c655fd 100644 --- a/src/Client.php +++ b/src/Client.php @@ -73,7 +73,7 @@ class Client string $user, string $password, bool $useCoroutine = true - ){ + ) { $this->id = uniqid('utopia.mongo.client'); $this->database = $database; $this->host = $host; @@ -96,7 +96,9 @@ class Client */ public function connect(): self { - if($this->client->isConnected()) return $this; + if ($this->client->isConnected()) { + return $this; + } $this->client->connect($this->host, $this->port); [$payload, $db] = $this->auth->start(); @@ -332,7 +334,6 @@ class Client */ public function listCollectionNames(array $filter = [], array $options = []): stdClass { - $qry = array_merge( [ "listCollections" => 1.0, @@ -420,7 +421,9 @@ class Client $docObj = new stdClass(); foreach ($document as $key => $value) { - if(\is_null($value)) continue; + if (\is_null($value)) { + continue; + } $docObj->{$key} = $value; } @@ -468,11 +471,12 @@ class Client */ public function update(string $collection, array $where = [], array $updates = [], array $options = []): self { - $cleanUpdates = []; - foreach($updates as $k => $v) { - if(\is_null($v)) continue; + foreach ($updates as $k => $v) { + if (\is_null($v)) { + continue; + } $cleanUpdates[$k] = $v; } @@ -510,8 +514,10 @@ class Client { $cleanUpdates = []; - foreach($updates as $k => $v) { - if(\is_null($v)) continue; + foreach ($updates as $k => $v) { + if (\is_null($v)) { + continue; + } $cleanUpdates[$k] = $v; } @@ -555,7 +561,6 @@ class Client 'filter' => $this->toObject($filters), ], $options) ); - } /** @@ -701,7 +706,9 @@ class Client */ public function toArray(mixed $obj): ?array { - if(\is_null($obj)) return null; + if (\is_null($obj)) { + return null; + } if (is_object($obj) || is_array($obj)) { $ret = (array) $obj; @@ -715,17 +722,20 @@ class Client return [$obj]; } - private function cleanFilters($filters):array { + private function cleanFilters($filters): array + { $cleanedFilters = []; - foreach($filters as $k => $v) { + foreach ($filters as $k => $v) { $value = $v; - if(in_array($k, ['$and', '$or', '$nor']) && is_array($v)) { + if (in_array($k, ['$and', '$or', '$nor']) && is_array($v)) { $values = []; - foreach($v as $item) { - if(is_null($item)) continue; + foreach ($v as $item) { + if (is_null($item)) { + continue; + } $values[] = is_array($item) ? $this->toObject($item) : $item; } diff --git a/src/Exception.php b/src/Exception.php index ddc141f147..7d0cf47979 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -1,6 +1,7 @@ getDatabase()->insert('movies', [ + $doc = $this->getDatabase()->insert( + 'movies', + [ 'name' => 'Armageddon', 'country' => 'USA', 'language' => 'English' @@ -73,14 +74,18 @@ class MongoTest extends TestCase $id = (string)$doc['_id']; self::assertEquals(24, strlen($id)); - $doc = $this->getDatabase()->insert('movies', [ + $doc = $this->getDatabase()->insert( + 'movies', + [ 'name' => 300, 'country' => 'USA', 'language' => 'English' ] ); - $doc = $this->getDatabase()->insert('movies', [ + $doc = $this->getDatabase()->insert( + 'movies', + [ '_id' => 999, 'array' => ['USA', 'UK', 'India'], 'language' => 'English', @@ -105,7 +110,5 @@ class MongoTest extends TestCase self::expectException(Exception::class); self::expectExceptionCode(11000); $this->getDatabase()->insert('movies', ['_id' => 999, 'b' => 'Duplication']); - } - }