pint check

This commit is contained in:
fogelito committed 2022-11-08 11:09:34 +02:00
1 parent 5596830d21
commit 8b5f9cab33
7 files changed
+43 -34

No files matched your search

+1 -4
View File
@@ -1,6 +1,3 @@
{
"preset": "psr12",
"exclude": [
"tests/"
]
"preset": "psr12"
}
-1
View File
@@ -6,7 +6,6 @@ use Utopia\Mongo\Adapter;
class SwooleClient extends Adapter
{
public function isConnected(): bool
{
// TODO: Implement isConnected() method.
+1 -2
View File
@@ -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.
}
}
}
+2 -2
View File
@@ -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));
}
}
}
+26 -16
View File
@@ -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;
}
+2 -1
View File
@@ -1,6 +1,7 @@
<?php
namespace Utopia\Mongo;
class Exception extends \Exception
{
}
}
+11 -8
View File
@@ -4,18 +4,17 @@ namespace Utopia\Tests;
use MongoDB\BSON\ObjectId;
use PHPUnit\Framework\TestCase;
use Utopia\Mongo\Adapter\SwooleClient;
use Utopia\Mongo\Client;
use Utopia\Mongo\Exception;
class MongoTest extends TestCase
{
static ?Client $db = null;
public static ?Client $db = null;
/**
* @throws Exception
*/
static function getDatabase(): Client
public static function getDatabase(): Client
{
if (!is_null(self::$db)) {
return self::$db;
@@ -53,7 +52,9 @@ class MongoTest extends TestCase
public function testCreateDocument()
{
$doc = $this->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']);
}
}