Skip to content

Commit 7c82328

Browse files
committed
-
1 parent 61adb96 commit 7c82328

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1943
-1457
lines changed

phpcs.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<exclude name="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
2525
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
2626
<exclude name="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"/>
27+
<exclude name="SlevomatCodingStandard.Functions.StaticClosure"/>
28+
29+
<!-- Type changes needs to be synchronized with laravel/framework -->
2730
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
31+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
32+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
2833
</rule>
2934
</ruleset>

src/Auth/DatabaseTokenRepository.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MongoDB\Laravel\Auth;
46

57
use DateTime;
@@ -8,11 +10,12 @@
810
use Illuminate\Support\Facades\Date;
911
use MongoDB\BSON\UTCDateTime;
1012

13+
use function date_default_timezone_get;
14+
use function is_array;
15+
1116
class DatabaseTokenRepository extends BaseDatabaseTokenRepository
1217
{
13-
/**
14-
* @inheritdoc
15-
*/
18+
/** @inheritdoc */
1619
protected function getPayload($email, $token)
1720
{
1821
return [
@@ -22,19 +25,15 @@ protected function getPayload($email, $token)
2225
];
2326
}
2427

25-
/**
26-
* @inheritdoc
27-
*/
28+
/** @inheritdoc */
2829
protected function tokenExpired($createdAt)
2930
{
3031
$createdAt = $this->convertDateTime($createdAt);
3132

3233
return parent::tokenExpired($createdAt);
3334
}
3435

35-
/**
36-
* @inheritdoc
37-
*/
36+
/** @inheritdoc */
3837
protected function tokenRecentlyCreated($createdAt)
3938
{
4039
$createdAt = $this->convertDateTime($createdAt);
@@ -50,7 +49,7 @@ private function convertDateTime($createdAt)
5049
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
5150
$createdAt = $date->format('Y-m-d H:i:s');
5251
} elseif (is_array($createdAt) && isset($createdAt['date'])) {
53-
$date = new DateTime($createdAt['date'], new DateTimeZone(isset($createdAt['timezone']) ? $createdAt['timezone'] : 'UTC'));
52+
$date = new DateTime($createdAt['date'], new DateTimeZone($createdAt['timezone'] ?? 'UTC'));
5453
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
5554
$createdAt = $date->format('Y-m-d H:i:s');
5655
}

src/Auth/PasswordBrokerManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MongoDB\Laravel\Auth;
46

57
use Illuminate\Auth\Passwords\PasswordBrokerManager as BasePasswordBrokerManager;
68

79
class PasswordBrokerManager extends BasePasswordBrokerManager
810
{
9-
/**
10-
* @inheritdoc
11-
*/
11+
/** @inheritdoc */
1212
protected function createTokenRepository(array $config)
1313
{
1414
return new DatabaseTokenRepository(
@@ -17,7 +17,7 @@ protected function createTokenRepository(array $config)
1717
$config['table'],
1818
$this->app['config']['app.key'],
1919
$config['expire'],
20-
$config['throttle'] ?? 0
20+
$config['throttle'] ?? 0,
2121
);
2222
}
2323
}

src/Auth/PasswordResetServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MongoDB\Laravel\Auth;
46

57
use Illuminate\Auth\Passwords\PasswordResetServiceProvider as BasePasswordResetServiceProvider;
68

79
class PasswordResetServiceProvider extends BasePasswordResetServiceProvider
810
{
9-
/**
10-
* @inheritdoc
11-
*/
11+
/** @inheritdoc */
1212
protected function registerPasswordBroker()
1313
{
1414
$this->app->singleton('auth.password', function ($app) {

src/Auth/User.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MongoDB\Laravel\Auth;
46

57
use Illuminate\Auth\Authenticatable;
@@ -16,5 +18,8 @@ class User extends Model implements
1618
AuthorizableContract,
1719
CanResetPasswordContract
1820
{
19-
use Authenticatable, Authorizable, CanResetPassword, MustVerifyEmail;
21+
use Authenticatable;
22+
use Authorizable;
23+
use CanResetPassword;
24+
use MustVerifyEmail;
2025
}

src/Collection.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MongoDB\Laravel;
46

57
use Exception;
68
use MongoDB\BSON\ObjectID;
79
use MongoDB\Collection as MongoCollection;
810

9-
/**
10-
* @mixin MongoCollection
11-
*/
11+
use function array_walk_recursive;
12+
use function implode;
13+
use function json_encode;
14+
use function microtime;
15+
16+
/** @mixin MongoCollection */
1217
class Collection
1318
{
1419
/**
@@ -25,10 +30,6 @@ class Collection
2530
*/
2631
protected $collection;
2732

28-
/**
29-
* @param Connection $connection
30-
* @param MongoCollection $collection
31-
*/
3233
public function __construct(Connection $connection, MongoCollection $collection)
3334
{
3435
$this->connection = $connection;
@@ -38,13 +39,14 @@ public function __construct(Connection $connection, MongoCollection $collection)
3839
/**
3940
* Handle dynamic method calls.
4041
*
41-
* @param string $method
42+
* @param string $method
4243
* @param array $parameters
44+
*
4345
* @return mixed
4446
*/
4547
public function __call(string $method, array $parameters)
4648
{
47-
$start = microtime(true);
49+
$start = microtime(true);
4850
$result = $this->collection->$method(...$parameters);
4951

5052
// Once we have run the query we will calculate the time that it took to run and
@@ -56,21 +58,23 @@ public function __call(string $method, array $parameters)
5658

5759
// Convert the query parameters to a json string.
5860
array_walk_recursive($parameters, function (&$item, $key) {
59-
if ($item instanceof ObjectID) {
60-
$item = (string) $item;
61+
if (! ($item instanceof ObjectID)) {
62+
return;
6163
}
64+
65+
$item = (string) $item;
6266
});
6367

6468
// Convert the query parameters to a json string.
6569
foreach ($parameters as $parameter) {
6670
try {
6771
$query[] = json_encode($parameter);
68-
} catch (Exception $e) {
72+
} catch (Exception) {
6973
$query[] = '{...}';
7074
}
7175
}
7276

73-
$queryString = $this->collection->getCollectionName().'.'.$method.'('.implode(',', $query).')';
77+
$queryString = $this->collection->getCollectionName() . '.' . $method . '(' . implode(',', $query) . ')';
7478

7579
$this->connection->logQuery($queryString, [], $time);
7680

src/Concerns/ManagesTransactions.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MongoDB\Laravel\Concerns;
46

57
use Closure;
68
use MongoDB\Client;
79
use MongoDB\Driver\Exception\RuntimeException;
810
use MongoDB\Driver\Session;
9-
use function MongoDB\with_transaction;
1011
use Throwable;
1112

12-
/**
13-
* @see https://docs.mongodb.com/manual/core/transactions/
14-
*/
13+
use function MongoDB\with_transaction;
14+
15+
/** @see https://docs.mongodb.com/manual/core/transactions/ */
1516
trait ManagesTransactions
1617
{
17-
protected ?Session $session = null;
18+
protected Session|null $session = null;
1819

1920
protected $transactions = 0;
2021

21-
/**
22-
* @return Client
23-
*/
22+
/** @return Client */
2423
abstract public function getMongoClient();
2524

26-
public function getSession(): ?Session
25+
public function getSession(): Session|null
2726
{
2827
return $this->session;
2928
}
@@ -78,13 +77,13 @@ public function rollBack($toLevel = null): void
7877
/**
7978
* Static transaction function realize the with_transaction functionality provided by MongoDB.
8079
*
81-
* @param int $attempts
80+
* @param int $attempts
8281
*/
8382
public function transaction(Closure $callback, $attempts = 1, array $options = []): mixed
8483
{
85-
$attemptsLeft = $attempts;
84+
$attemptsLeft = $attempts;
8685
$callbackResult = null;
87-
$throwable = null;
86+
$throwable = null;
8887

8988
$callbackFunction = function (Session $session) use ($callback, &$attemptsLeft, &$callbackResult, &$throwable) {
9089
$attemptsLeft--;

0 commit comments

Comments
 (0)