From 7807734c40ac72a3fec858f3932393beb6a85caa Mon Sep 17 00:00:00 2001 From: Shift Date: Mon, 30 Jan 2023 23:52:14 +0000 Subject: [PATCH 01/11] Bump dependencies for Laravel 10 --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 12a5b7eeb..e3c58d032 100644 --- a/composer.json +++ b/composer.json @@ -19,17 +19,17 @@ ], "license": "MIT", "require": { - "illuminate/support": "^9.0", - "illuminate/container": "^9.0", - "illuminate/database": "^9.0", - "illuminate/events": "^9.0", - "mongodb/mongodb": "^1.11" + "illuminate/support": "^10.0", + "illuminate/container": "^10.0", + "illuminate/database": "^10.0", + "illuminate/events": "^10.0", + "mongodb/mongodb": "^1.15" }, "require-dev": { - "phpunit/phpunit": "^9.5.8", - "orchestra/testbench": "^7.0", - "mockery/mockery": "^1.3.1", - "doctrine/dbal": "^2.13.3|^3.1.4" + "phpunit/phpunit": "^9.5.10", + "orchestra/testbench": "^8.0", + "mockery/mockery": "^1.4.4", + "doctrine/dbal": "^3.5" }, "autoload": { "psr-4": { From 37236c08b103731d8ae4c70e87531fcececdbd8f Mon Sep 17 00:00:00 2001 From: Divine <48183131+divine@users.noreply.github.com> Date: Tue, 31 Jan 2023 10:36:45 +0300 Subject: [PATCH 02/11] chore: update minimum stability --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e3c58d032..24fb26658 100644 --- a/composer.json +++ b/composer.json @@ -54,5 +54,6 @@ "Jenssegers\\Mongodb\\MongodbQueueServiceProvider" ] } - } + }, + "minimum-stability": "dev" } From 452a0bbb7f6e15cd3301508bc3e54b433059ac08 Mon Sep 17 00:00:00 2001 From: Divine <48183131+divine@users.noreply.github.com> Date: Tue, 31 Jan 2023 10:39:19 +0300 Subject: [PATCH 03/11] chore: disable php 8.0 in gh builds --- .github/workflows/build-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index f081e3273..905c4d2de 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -41,7 +41,6 @@ jobs: - '4.4' - '5.0' php: - - '8.0' - '8.1' services: mysql: From 2ea1a7c0aee085c382349613d399be79a0bd1f1a Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 7 Feb 2023 14:02:03 +0100 Subject: [PATCH 04/11] Update handling of dates for Laravel 10 --- README.md | 4 +- src/Eloquent/Model.php | 83 +++++++++++++++++++++++++++++++++++------- tests/ModelTest.php | 3 +- tests/models/Soft.php | 2 +- tests/models/User.php | 5 ++- 5 files changed, 77 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index f201b2514..59a22c12c 100644 --- a/README.md +++ b/README.md @@ -256,8 +256,6 @@ use Jenssegers\Mongodb\Eloquent\SoftDeletes; class User extends Model { use SoftDeletes; - - protected $dates = ['deleted_at']; } ``` @@ -279,7 +277,7 @@ use Jenssegers\Mongodb\Eloquent\Model; class User extends Model { - protected $dates = ['birthday']; + protected $casts = ['birthday' => 'datetime']; } ``` diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php index e123391dc..9f8d7f90a 100644 --- a/src/Eloquent/Model.php +++ b/src/Eloquent/Model.php @@ -2,18 +2,23 @@ namespace Jenssegers\Mongodb\Eloquent; +use function array_key_exists; use DateTimeInterface; +use function explode; use Illuminate\Contracts\Queue\QueueableCollection; use Illuminate\Contracts\Queue\QueueableEntity; +use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Model as BaseModel; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Date; use Illuminate\Support\Str; +use function in_array; use Jenssegers\Mongodb\Query\Builder as QueryBuilder; use MongoDB\BSON\Binary; use MongoDB\BSON\ObjectID; use MongoDB\BSON\UTCDateTime; +use function uniqid; abstract class Model extends BaseModel { @@ -94,7 +99,7 @@ public function fromDateTime($value) $value = parent::asDateTime($value); } - return new UTCDateTime($value->format('Uv')); + return new UTCDateTime($value); } /** @@ -191,13 +196,14 @@ public function setAttribute($key, $value) $value = $builder->convertKey($value); } // Support keys in dot notation. elseif (Str::contains($key, '.')) { - if (in_array($key, $this->getDates()) && $value) { - $value = $this->fromDateTime($value); - } + // Store to a temporary key, then move data to the actual key + $uniqueKey = uniqid($key); + parent::setAttribute($uniqueKey, $value); - Arr::set($this->attributes, $key, $value); + Arr::set($this->attributes, $key, $this->attributes[$uniqueKey] ?? null); + unset($this->attributes[$uniqueKey]); - return; + return $this; } return parent::setAttribute($key, $value); @@ -222,13 +228,6 @@ public function attributesToArray() } } - // Convert dot-notation dates. - foreach ($this->getDates() as $key) { - if (Str::contains($key, '.') && Arr::has($attributes, $key)) { - Arr::set($attributes, $key, (string) $this->asDateTime(Arr::get($attributes, $key))); - } - } - return $attributes; } @@ -515,4 +514,62 @@ public function __call($method, $parameters) return parent::__call($method, $parameters); } + + /** + * Add the casted attributes to the attributes array. + * + * @param array $attributes + * @param array $mutatedAttributes + * @return array + */ + protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes) + { + foreach ($this->getCasts() as $key => $castType) { + if (! Arr::has($attributes, $key) || Arr::has($mutatedAttributes, $key)) { + continue; + } + + $originalValue = Arr::get($attributes, $key); + + // Here we will cast the attribute. Then, if the cast is a date or datetime cast + // then we will serialize the date for the array. This will convert the dates + // to strings based on the date format specified for these Eloquent models. + $castValue = $this->castAttribute( + $key, $originalValue + ); + + // If the attribute cast was a date or a datetime, we will serialize the date as + // a string. This allows the developers to customize how dates are serialized + // into an array without affecting how they are persisted into the storage. + if ($castValue !== null && in_array($castType, ['date', 'datetime', 'immutable_date', 'immutable_datetime'])) { + $castValue = $this->serializeDate($castValue); + } + + if ($castValue !== null && ($this->isCustomDateTimeCast($castType) || + $this->isImmutableCustomDateTimeCast($castType))) { + $castValue = $castValue->format(explode(':', $castType, 2)[1]); + } + + if ($castValue instanceof DateTimeInterface && + $this->isClassCastable($key)) { + $castValue = $this->serializeDate($castValue); + } + + if ($castValue !== null && $this->isClassSerializable($key)) { + $castValue = $this->serializeClassCastableAttribute($key, $castValue); + } + + if ($this->isEnumCastable($key) && (! $castValue instanceof Arrayable)) { + $castValue = $castValue !== null ? $this->getStorableEnumValue($attributes[$key]) : null; + } + + if ($castValue instanceof Arrayable) { + $castValue = $castValue->toArray(); + } + + Arr::set($attributes, $key, $castValue); + } + + return $attributes; + } } diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 22e06baee..5d94920b9 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -577,8 +577,7 @@ public function testDates(): void $this->assertInstanceOf(Carbon::class, $user->getAttribute('entry.date')); $data = $user->toArray(); - $this->assertNotInstanceOf(UTCDateTime::class, $data['entry']['date']); - $this->assertEquals((string) $user->getAttribute('entry.date')->format('Y-m-d H:i:s'), $data['entry']['date']); + $this->assertIsString($data['entry']['date']); } public function testCarbonDateMockingWorks() diff --git a/tests/models/Soft.php b/tests/models/Soft.php index c4571e6b0..30711e61d 100644 --- a/tests/models/Soft.php +++ b/tests/models/Soft.php @@ -17,5 +17,5 @@ class Soft extends Eloquent protected $connection = 'mongodb'; protected $collection = 'soft'; protected static $unguarded = true; - protected $dates = ['deleted_at']; + protected $casts = ['deleted_at' => 'datetime']; } diff --git a/tests/models/User.php b/tests/models/User.php index f9360f545..8bf3c9410 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -33,7 +33,10 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword use Notifiable; protected $connection = 'mongodb'; - protected $dates = ['birthday', 'entry.date']; + protected $casts = [ + 'birthday' => 'datetime', + 'entry.date' => 'datetime', + ]; protected static $unguarded = true; public function books() From 8bb0199a14035f285a0d6209c20d1e64cb67cc5d Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 7 Feb 2023 14:02:34 +0100 Subject: [PATCH 05/11] Remove deprecated PHPUnit call --- tests/QueryBuilderTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index c169071d0..235784829 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -146,8 +146,6 @@ public function commandStarted(CommandStartedEvent $event) return; } - Assert::assertObjectHasAttribute('maxTimeMS', $event->getCommand()); - // Expect the timeout to be converted to milliseconds Assert::assertSame(1000, $event->getCommand()->maxTimeMS); } From a141614909d3c3f85668465a0ca9a7e510fb5bf1 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 9 Feb 2023 08:29:09 +0100 Subject: [PATCH 06/11] Rename getBaseQuery method to toBase --- src/Relations/EmbedsMany.php | 6 +++--- src/Relations/EmbedsOne.php | 6 +++--- src/Relations/EmbedsOneOrMany.php | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Relations/EmbedsMany.php b/src/Relations/EmbedsMany.php index ba1513255..9797acaa7 100644 --- a/src/Relations/EmbedsMany.php +++ b/src/Relations/EmbedsMany.php @@ -52,7 +52,7 @@ public function performInsert(Model $model) } // Push the new model to the database. - $result = $this->getBaseQuery()->push($this->localKey, $model->getAttributes(), true); + $result = $this->toBase()->push($this->localKey, $model->getAttributes(), true); // Attach the model to its parent. if ($result) { @@ -83,7 +83,7 @@ public function performUpdate(Model $model) $values = $this->getUpdateValues($model->getDirty(), $this->localKey.'.$.'); // Update document in database. - $result = $this->getBaseQuery()->where($this->localKey.'.'.$model->getKeyName(), $foreignKey) + $result = $this->toBase()->where($this->localKey.'.'.$model->getKeyName(), $foreignKey) ->update($values); // Attach the model to its parent. @@ -112,7 +112,7 @@ public function performDelete(Model $model) // Get the correct foreign key value. $foreignKey = $this->getForeignKeyValue($model); - $result = $this->getBaseQuery()->pull($this->localKey, [$model->getKeyName() => $foreignKey]); + $result = $this->toBase()->pull($this->localKey, [$model->getKeyName() => $foreignKey]); if ($result) { $this->dissociate($model); diff --git a/src/Relations/EmbedsOne.php b/src/Relations/EmbedsOne.php index ba2a41dfc..f50454080 100644 --- a/src/Relations/EmbedsOne.php +++ b/src/Relations/EmbedsOne.php @@ -50,7 +50,7 @@ public function performInsert(Model $model) return $this->parent->save() ? $model : false; } - $result = $this->getBaseQuery()->update([$this->localKey => $model->getAttributes()]); + $result = $this->toBase()->update([$this->localKey => $model->getAttributes()]); // Attach the model to its parent. if ($result) { @@ -76,7 +76,7 @@ public function performUpdate(Model $model) $values = $this->getUpdateValues($model->getDirty(), $this->localKey.'.'); - $result = $this->getBaseQuery()->update($values); + $result = $this->toBase()->update($values); // Attach the model to its parent. if ($result) { @@ -101,7 +101,7 @@ public function performDelete() } // Overwrite the local key with an empty array. - $result = $this->getBaseQuery()->update([$this->localKey => null]); + $result = $this->toBase()->update([$this->localKey => null]); // Detach the model from its parent. if ($result) { diff --git a/src/Relations/EmbedsOneOrMany.php b/src/Relations/EmbedsOneOrMany.php index 2e5215377..4cb71d595 100644 --- a/src/Relations/EmbedsOneOrMany.php +++ b/src/Relations/EmbedsOneOrMany.php @@ -246,7 +246,7 @@ protected function getForeignKeyValue($id) } // Convert the id to MongoId if necessary. - return $this->getBaseQuery()->convertKey($id); + return $this->toBase()->convertKey($id); } /** @@ -322,7 +322,7 @@ public function getQuery() /** * @inheritdoc */ - public function getBaseQuery() + public function toBase() { // Because we are sharing this relation instance to models, we need // to make sure we use separate query instances. From e5f3571ad0b162b5b92160e50eec0d5a98353fee Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 9 Feb 2023 08:30:16 +0100 Subject: [PATCH 07/11] Remove dependency on doctrine/dbal --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 24fb26658..b2dba6529 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,7 @@ "require-dev": { "phpunit/phpunit": "^9.5.10", "orchestra/testbench": "^8.0", - "mockery/mockery": "^1.4.4", - "doctrine/dbal": "^3.5" + "mockery/mockery": "^1.4.4" }, "autoload": { "psr-4": { From 02df6cbd5aae85679d2f2f80020eaf6b2114ecdf Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 9 Feb 2023 08:34:10 +0100 Subject: [PATCH 08/11] Update tested PHP versions --- .github/workflows/build-ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 905c4d2de..c3e22c23f 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -14,10 +14,10 @@ jobs: strategy: matrix: php: - - '8.0' + - '8.1' steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -42,6 +42,7 @@ jobs: - '5.0' php: - '8.1' + - '8.2' services: mysql: image: mysql:5.7 @@ -53,7 +54,7 @@ jobs: MYSQL_ROOT_PASSWORD: steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Create MongoDB Replica Set run: | docker run --name mongodb -p 27017:27017 -e MONGO_INITDB_DATABASE=unittest --detach mongo:${{ matrix.mongodb }} mongod --replSet rs --setParameter transactionLifetimeLimitSeconds=5 From ba66a4ef8757095127ce9fc27b1686eb07d34575 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 9 Feb 2023 09:47:26 +0100 Subject: [PATCH 09/11] Fix auth test for Laravel 10 --- src/Auth/PasswordBrokerManager.php | 3 +- src/Auth/PasswordResetServiceProvider.php | 23 ------------ tests/AuthTest.php | 46 +++++++++++------------ 3 files changed, 25 insertions(+), 47 deletions(-) diff --git a/src/Auth/PasswordBrokerManager.php b/src/Auth/PasswordBrokerManager.php index 281f8af75..bfb87874b 100644 --- a/src/Auth/PasswordBrokerManager.php +++ b/src/Auth/PasswordBrokerManager.php @@ -16,7 +16,8 @@ protected function createTokenRepository(array $config) $this->app['hash'], $config['table'], $this->app['config']['app.key'], - $config['expire'] + $config['expire'], + $config['throttle'] ?? 0 ); } } diff --git a/src/Auth/PasswordResetServiceProvider.php b/src/Auth/PasswordResetServiceProvider.php index ba4e32e62..74e5953c0 100644 --- a/src/Auth/PasswordResetServiceProvider.php +++ b/src/Auth/PasswordResetServiceProvider.php @@ -6,29 +6,6 @@ class PasswordResetServiceProvider extends BasePasswordResetServiceProvider { - /** - * Register the token repository implementation. - * - * @return void - */ - protected function registerTokenRepository() - { - $this->app->singleton('auth.password.tokens', function ($app) { - $connection = $app['db']->connection(); - - // The database token repository is an implementation of the token repository - // interface, and is responsible for the actual storing of auth tokens and - // their e-mail addresses. We will inject this table and hash key to it. - $table = $app['config']['auth.password.table']; - - $key = $app['config']['app.key']; - - $expire = $app['config']->get('auth.password.expire', 60); - - return new DatabaseTokenRepository($connection, $table, $key, $expire); - }); - } - /** * @inheritdoc */ diff --git a/tests/AuthTest.php b/tests/AuthTest.php index 912cc9061..86261696e 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -1,7 +1,6 @@ truncate(); + DB::collection('password_reset_tokens')->truncate(); } public function testAuthAttempt() { User::create([ 'name' => 'John Doe', - 'email' => 'john@doe.com', + 'email' => 'john.doe@example.com', 'password' => Hash::make('foobar'), ]); - $this->assertTrue(Auth::attempt(['email' => 'john@doe.com', 'password' => 'foobar'], true)); + $this->assertTrue(Auth::attempt(['email' => 'john.doe@example.com', 'password' => 'foobar'], true)); $this->assertTrue(Auth::check()); } public function testRemindOld() { - if (Application::VERSION >= '5.2') { - $this->expectNotToPerformAssertions(); - - return; - } - - $mailer = Mockery::mock('Illuminate\Mail\Mailer'); - $tokens = $this->app->make('auth.password.tokens'); - $users = $this->app['auth']->driver()->getProvider(); - - $broker = new PasswordBroker($tokens, $users, $mailer, ''); + $broker = $this->app->make('auth.password.broker'); $user = User::create([ 'name' => 'John Doe', - 'email' => 'john@doe.com', + 'email' => 'john.doe@example.com', 'password' => Hash::make('foobar'), ]); - $mailer->shouldReceive('send')->once(); - $broker->sendResetLink(['email' => 'john@doe.com']); + $token = null; + + $this->assertSame( + PasswordBroker::RESET_LINK_SENT, + $broker->sendResetLink( + ['email' => 'john.doe@example.com'], + function ($actualUser, $actualToken) use ($user, &$token) { + $this->assertEquals($user->_id, $actualUser->_id); + // Store token for later use + $token = $actualToken; + } + ) + ); - $this->assertEquals(1, DB::collection('password_resets')->count()); - $reminder = DB::collection('password_resets')->first(); - $this->assertEquals('john@doe.com', $reminder['email']); + $this->assertEquals(1, DB::collection('password_reset_tokens')->count()); + $reminder = DB::collection('password_reset_tokens')->first(); + $this->assertEquals('john.doe@example.com', $reminder['email']); $this->assertNotNull($reminder['token']); $this->assertInstanceOf(UTCDateTime::class, $reminder['created_at']); $credentials = [ - 'email' => 'john@doe.com', + 'email' => 'john.doe@example.com', 'password' => 'foobar', 'password_confirmation' => 'foobar', - 'token' => $reminder['token'], + 'token' => $token, ]; $response = $broker->reset($credentials, function ($user, $password) { From 4da2a9225a01b243bfbc90f25b675555643b2954 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 9 Feb 2023 10:39:10 +0100 Subject: [PATCH 10/11] Fix styleCI issues --- src/Relations/EmbedsOne.php | 10 ++++---- src/Relations/EmbedsOneOrMany.php | 38 +++++++++++++++---------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Relations/EmbedsOne.php b/src/Relations/EmbedsOne.php index f50454080..8bd573b3e 100644 --- a/src/Relations/EmbedsOne.php +++ b/src/Relations/EmbedsOne.php @@ -33,7 +33,7 @@ public function getEager() /** * Save a new model and attach it to the parent model. * - * @param Model $model + * @param Model $model * @return Model|bool */ public function performInsert(Model $model) @@ -63,7 +63,7 @@ public function performInsert(Model $model) /** * Save an existing model and attach it to the parent model. * - * @param Model $model + * @param Model $model * @return Model|bool */ public function performUpdate(Model $model) @@ -114,7 +114,7 @@ public function performDelete() /** * Attach the model to its parent. * - * @param Model $model + * @param Model $model * @return Model */ public function associate(Model $model) @@ -145,8 +145,8 @@ public function delete() /** * Get the name of the "where in" method for eager loading. * - * @param \Illuminate\Database\Eloquent\Model $model - * @param string $key + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key * @return string */ protected function whereInMethod(EloquentModel $model, $key) diff --git a/src/Relations/EmbedsOneOrMany.php b/src/Relations/EmbedsOneOrMany.php index 4cb71d595..dedae591b 100644 --- a/src/Relations/EmbedsOneOrMany.php +++ b/src/Relations/EmbedsOneOrMany.php @@ -34,12 +34,12 @@ abstract class EmbedsOneOrMany extends Relation /** * Create a new embeds many relationship instance. * - * @param Builder $query - * @param Model $parent - * @param Model $related - * @param string $localKey - * @param string $foreignKey - * @param string $relation + * @param Builder $query + * @param Model $parent + * @param Model $related + * @param string $localKey + * @param string $foreignKey + * @param string $relation */ public function __construct(Builder $query, Model $parent, Model $related, $localKey, $foreignKey, $relation) { @@ -95,7 +95,7 @@ public function match(array $models, Collection $results, $relation) /** * Shorthand to get the results of the relationship. * - * @param array $columns + * @param array $columns * @return Collection */ public function get($columns = ['*']) @@ -116,7 +116,7 @@ public function count() /** * Attach a model instance to the parent model. * - * @param Model $model + * @param Model $model * @return Model|bool */ public function save(Model $model) @@ -129,7 +129,7 @@ public function save(Model $model) /** * Attach a collection of models to the parent instance. * - * @param Collection|array $models + * @param Collection|array $models * @return Collection|array */ public function saveMany($models) @@ -144,7 +144,7 @@ public function saveMany($models) /** * Create a new instance of the related model. * - * @param array $attributes + * @param array $attributes * @return Model */ public function create(array $attributes = []) @@ -164,7 +164,7 @@ public function create(array $attributes = []) /** * Create an array of new instances of the related model. * - * @param array $records + * @param array $records * @return array */ public function createMany(array $records) @@ -181,7 +181,7 @@ public function createMany(array $records) /** * Transform single ID, single Model or array of Models into an array of IDs. * - * @param mixed $ids + * @param mixed $ids * @return array */ protected function getIdsArrayFrom($ids) @@ -236,7 +236,7 @@ protected function setEmbedded($records) /** * Get the foreign key value for the relation. * - * @param mixed $id + * @param mixed $id * @return mixed */ protected function getForeignKeyValue($id) @@ -252,7 +252,7 @@ protected function getForeignKeyValue($id) /** * Convert an array of records to a Collection. * - * @param array $records + * @param array $records * @return Collection */ protected function toCollection(array $records = []) @@ -273,7 +273,7 @@ protected function toCollection(array $records = []) /** * Create a related model instanced. * - * @param array $attributes + * @param array $attributes * @return Model */ protected function toModel($attributes = []) @@ -342,7 +342,7 @@ protected function isNested() /** * Get the fully qualified local key name. * - * @param string $glue + * @param string $glue * @return string */ protected function getPathHierarchy($glue = '.') @@ -380,7 +380,7 @@ protected function getParentKey() * Return update values. * * @param $array - * @param string $prepend + * @param string $prepend * @return array */ public static function getUpdateValues($array, $prepend = '') @@ -407,8 +407,8 @@ public function getQualifiedForeignKeyName() /** * Get the name of the "where in" method for eager loading. * - * @param \Illuminate\Database\Eloquent\Model $model - * @param string $key + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key * @return string */ protected function whereInMethod(EloquentModel $model, $key) From 226a7098c31e282dd33b539d2d9003fc4d40a7cd Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 9 Feb 2023 10:40:03 +0100 Subject: [PATCH 11/11] Add missing return types --- src/Eloquent/Model.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php index 9f8d7f90a..e12f68f82 100644 --- a/src/Eloquent/Model.php +++ b/src/Eloquent/Model.php @@ -187,7 +187,7 @@ protected function getAttributeFromArray($key) /** * @inheritdoc */ - public function setAttribute($key, $value) + public function setAttribute($key, $value): static { // Convert _id to ObjectID. if ($key == '_id' && is_string($value)) { @@ -516,13 +516,9 @@ public function __call($method, $parameters) } /** - * Add the casted attributes to the attributes array. - * - * @param array $attributes - * @param array $mutatedAttributes - * @return array + * @inheritdoc */ - protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes) + protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes): array { foreach ($this->getCasts() as $key => $castType) { if (! Arr::has($attributes, $key) || Arr::has($mutatedAttributes, $key)) {