From 280829074506a28c1eb3cc66d3eb4b416bde54b1 Mon Sep 17 00:00:00 2001 From: Kay Wei Date: Thu, 12 Sep 2024 16:40:04 +0800 Subject: [PATCH] Fix incorrect PHPDoc for Builder relation --- src/Illuminate/Database/Eloquent/Builder.php | 6 ++--- .../Database/Eloquent/Collection.php | 22 +++++++++---------- types/Database/Eloquent/Builder.php | 7 ++++++ types/Database/Eloquent/Collection.php | 5 ++++- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index ff31cd8e4ae3..a8d4a7cb4ab6 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1537,8 +1537,8 @@ protected function createNestedWhere($whereSlice, $boolean = 'and') /** * Set the relationships that should be eager loaded. * - * @param array): mixed)|string>|string $relations - * @param (\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string|null $callback + * @param array): mixed)|string>|string $relations + * @param (\Closure(covariant \Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string|null $callback * @return $this */ public function with($relations, $callback = null) @@ -1572,7 +1572,7 @@ public function without($relations) /** * Set the relationships that should be eager loaded while removing any previously added eager loading specifications. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @return $this */ public function withOnly($relations) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index bdce34b0352e..db434f277777 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -84,7 +84,7 @@ public function findOrFail($key) /** * Load a set of relationships onto the collection. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @return $this */ public function load($relations) @@ -105,7 +105,7 @@ public function load($relations) /** * Load a set of aggregations over relationship's column onto the collection. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @param string $column * @param string|null $function * @return $this @@ -142,7 +142,7 @@ public function loadAggregate($relations, $column, $function = null) /** * Load a set of relationship counts onto the collection. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @return $this */ public function loadCount($relations) @@ -153,7 +153,7 @@ public function loadCount($relations) /** * Load a set of relationship's max column values onto the collection. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @param string $column * @return $this */ @@ -165,7 +165,7 @@ public function loadMax($relations, $column) /** * Load a set of relationship's min column values onto the collection. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @param string $column * @return $this */ @@ -177,7 +177,7 @@ public function loadMin($relations, $column) /** * Load a set of relationship's column summations onto the collection. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @param string $column * @return $this */ @@ -189,7 +189,7 @@ public function loadSum($relations, $column) /** * Load a set of relationship's average column values onto the collection. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @param string $column * @return $this */ @@ -201,7 +201,7 @@ public function loadAvg($relations, $column) /** * Load a set of related existences onto the collection. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @return $this */ public function loadExists($relations) @@ -212,7 +212,7 @@ public function loadExists($relations) /** * Load a set of relationships onto the collection if they are not already eager loaded. * - * @param array): mixed)|string>|string $relations + * @param array): mixed)|string>|string $relations * @return $this */ public function loadMissing($relations) @@ -284,7 +284,7 @@ protected function loadMissingRelation(self $models, array $path) * Load a set of relationships onto the mixed relationship collection. * * @param string $relation - * @param array): mixed)|string> $relations + * @param array): mixed)|string> $relations * @return $this */ public function loadMorph($relation, $relations) @@ -301,7 +301,7 @@ public function loadMorph($relation, $relations) * Load a set of relationship counts onto the mixed relationship collection. * * @param string $relation - * @param array): mixed)|string> $relations + * @param array): mixed)|string> $relations * @return $this */ public function loadMorphCount($relation, $relations) diff --git a/types/Database/Eloquent/Builder.php b/types/Database/Eloquent/Builder.php index a31d0dcacdcf..37e8f36cddf9 100644 --- a/types/Database/Eloquent/Builder.php +++ b/types/Database/Eloquent/Builder.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\HasBuilder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Query\Builder as QueryBuilder; use User; @@ -27,11 +28,17 @@ function test( assertType('Illuminate\Database\Eloquent\Builder', $query->with(['relation' => function ($query) { // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); }])); + assertType('Illuminate\Database\Eloquent\Builder', $query->with(['relation' => function (HasMany $query) :void { + assertType('Illuminate\Database\Eloquent\Relations\HasMany', $query); + }])); assertType('Illuminate\Database\Eloquent\Builder', $query->without('relation')); assertType('Illuminate\Database\Eloquent\Builder', $query->withOnly(['relation'])); assertType('Illuminate\Database\Eloquent\Builder', $query->withOnly(['relation' => function ($query) { // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); }])); + assertType('Illuminate\Database\Eloquent\Builder', $query->withOnly(['relation' => function (HasOne $query) :void { + assertType('Illuminate\Database\Eloquent\Relations\HasOne', $query); + }])); assertType('array', $query->getModels()); assertType('array', $query->eagerLoadRelations([])); assertType('Illuminate\Database\Eloquent\Collection', $query->get()); diff --git a/types/Database/Eloquent/Collection.php b/types/Database/Eloquent/Collection.php index 1d74831ce6f5..b67527330982 100644 --- a/types/Database/Eloquent/Collection.php +++ b/types/Database/Eloquent/Collection.php @@ -1,5 +1,6 @@ ', $collection->load('string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->load(['string'])); assertType('Illuminate\Database\Eloquent\Collection', $collection->load(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); + //assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); }])); +assertType('array{string: Closure(Illuminate\Database\Eloquent\Relations\MorphTo): void}',['string' => function (MorphTo $query):void {}]); +assertType('Illuminate\Database\Eloquent\Collection', $collection->load(['string' => function (MorphTo $query):void {}])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAggregate('string', 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAggregate(['string'], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAggregate(['string'], 'string', 'string'));