diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ece647c..009336c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,7 +4,7 @@ includes: - ./vendor/phpstan/phpstan-phpunit/extension.neon - ./vendor/phpstan/phpstan-phpunit/rules.neon parameters: - level: 5 + level: 6 paths: - src - tests diff --git a/src/Eloquent/CompositeKey.php b/src/Eloquent/CompositeKey.php index a2a98da..dac3179 100644 --- a/src/Eloquent/CompositeKey.php +++ b/src/Eloquent/CompositeKey.php @@ -4,8 +4,14 @@ class CompositeKey { + /** + * @var list $columns + */ public array $columns; + /** + * @param string ...$columns + */ public function __construct(...$columns) { $this->columns = $columns; diff --git a/src/Eloquent/Relations/ThirdParty/LaravelHasManyMerged/HasManyMerged.php b/src/Eloquent/Relations/ThirdParty/LaravelHasManyMerged/HasManyMerged.php index 8a690c9..afbb5c3 100644 --- a/src/Eloquent/Relations/ThirdParty/LaravelHasManyMerged/HasManyMerged.php +++ b/src/Eloquent/Relations/ThirdParty/LaravelHasManyMerged/HasManyMerged.php @@ -10,6 +10,10 @@ /** * @copyright Based on package by Constantin Graf (korridor): https://github.com/korridor/laravel-has-many-merged + * + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * + * @extends \Korridor\LaravelHasManyMerged\HasManyMerged */ class HasManyMerged extends Base implements ConcatenableRelation { @@ -17,10 +21,14 @@ class HasManyMerged extends Base implements ConcatenableRelation * Append the relation's through parents, foreign and local keys to a deep relationship. * * @param list<\Illuminate\Database\Eloquent\Model> $through - * @param array $foreignKeys - * @param array $localKeys + * @param list $foreignKeys + * @param list $localKeys * @param int $position - * @return array + * @return array{0: list, + * 1: list, + * 2: list} */ public function appendToDeepRelationship(array $through, array $foreignKeys, array $localKeys, int $position): array { @@ -55,7 +63,7 @@ function (JoinClause $join) { * Get the custom through key for an eager load of the relation. * * @param string $alias - * @return array + * @return list */ public function getThroughKeyForDeepRelationships(string $alias): array { @@ -71,8 +79,8 @@ public function getThroughKeyForDeepRelationships(string $alias): array /** * Set the constraints for an eager load of the deep relation. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $models + * @param \Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model> $query + * @param list<\Illuminate\Database\Eloquent\Model> $models * @return void */ public function addEagerConstraintsToDeepRelationship(Builder $query, array $models): void @@ -85,10 +93,10 @@ public function addEagerConstraintsToDeepRelationship(Builder $query, array $mod /** * Match the eagerly loaded results for a deep relationship to their parents. * - * @param array $models - * @param \Illuminate\Database\Eloquent\Collection $results + * @param list<\Illuminate\Database\Eloquent\Model> $models + * @param \Illuminate\Database\Eloquent\Collection $results * @param string $relation - * @return array + * @return list<\Illuminate\Database\Eloquent\Model> */ public function matchResultsForDeepRelationship(array $models, Collection $results, string $relation): array { @@ -109,8 +117,8 @@ public function matchResultsForDeepRelationship(array $models, Collection $resul /** * Build the model dictionary for a deep relation. * - * @param \Illuminate\Database\Eloquent\Collection $results - * @return array + * @param \Illuminate\Database\Eloquent\Collection $results + * @return array> */ protected function buildDictionaryForDeepRelationship(Collection $results): array { @@ -124,6 +132,7 @@ protected function buildDictionaryForDeepRelationship(Collection $results): arra foreach ($results as $result) { foreach ($foreignKeyNames as $foreignKeyName) { $foreignKeyValue = $result->{$foreignKeyName}; + if (!isset($dictionary[$foreignKeyValue])) { $dictionary[$foreignKeyValue] = []; } @@ -138,7 +147,7 @@ protected function buildDictionaryForDeepRelationship(Collection $results): arra /** * Create a new instance of the relation from a base relation instance. * - * @param \Korridor\LaravelHasManyMerged\HasManyMerged $relation + * @param \Korridor\LaravelHasManyMerged\HasManyMerged $relation * @return static */ public static function fromBaseRelation(Base $relation): static diff --git a/src/Eloquent/Relations/Traits/ExecutesQueries.php b/src/Eloquent/Relations/Traits/ExecutesQueries.php index 62bb5c3..6a1745d 100644 --- a/src/Eloquent/Relations/Traits/ExecutesQueries.php +++ b/src/Eloquent/Relations/Traits/ExecutesQueries.php @@ -26,8 +26,8 @@ public function getResults() /** * Execute the query as a "select" statement. * - * @param array $columns - * @return \Illuminate\Database\Eloquent\Collection + * @param string|list $columns + * @return \Illuminate\Database\Eloquent\Collection */ public function get($columns = ['*']) { @@ -46,10 +46,10 @@ public function get($columns = ['*']) * Get a paginator for the "select" statement. * * @param int $perPage - * @param array $columns + * @param list $columns * @param string $pageName * @param int $page - * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator<\Illuminate\Database\Eloquent\Model> */ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) { @@ -69,10 +69,10 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', * Paginate the given query into a simple paginator. * * @param int $perPage - * @param array $columns + * @param list $columns * @param string $pageName * @param int|null $page - * @return \Illuminate\Contracts\Pagination\Paginator + * @return \Illuminate\Contracts\Pagination\Paginator<\Illuminate\Database\Eloquent\Model> */ public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) { @@ -92,10 +92,10 @@ public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'p * Paginate the given query into a cursor paginator. * * @param int|null $perPage - * @param array $columns + * @param list $columns * @param string $cursorName * @param string|null $cursor - * @return \Illuminate\Contracts\Pagination\CursorPaginator + * @return \Illuminate\Contracts\Pagination\CursorPaginator<\Illuminate\Database\Eloquent\Model> */ public function cursorPaginate($perPage = null, $columns = ['*'], $cursorName = 'cursor', $cursor = null) { diff --git a/src/Eloquent/Relations/Traits/HasEagerLoading.php b/src/Eloquent/Relations/Traits/HasEagerLoading.php index 838dc07..63cddf4 100644 --- a/src/Eloquent/Relations/Traits/HasEagerLoading.php +++ b/src/Eloquent/Relations/Traits/HasEagerLoading.php @@ -6,12 +6,7 @@ trait HasEagerLoading { - /** - * Set the constraints for an eager load of the relation. - * - * @param array $models - * @return void - */ + /** @inheritDoc */ public function addEagerConstraints(array $models) { if ($this->customEagerConstraintsCallback) { @@ -34,14 +29,7 @@ public function addEagerConstraints(array $models) } } - /** - * Match the eagerly loaded results to their parents. - * - * @param array $models - * @param \Illuminate\Database\Eloquent\Collection $results - * @param string $relation - * @return array - */ + /** @inheritDoc */ public function match(array $models, Collection $results, $relation) { if ($this->customEagerMatchingCallbacks) { diff --git a/src/Eloquent/Relations/Traits/HasExistenceQueries.php b/src/Eloquent/Relations/Traits/HasExistenceQueries.php index 80a9337..551553e 100644 --- a/src/Eloquent/Relations/Traits/HasExistenceQueries.php +++ b/src/Eloquent/Relations/Traits/HasExistenceQueries.php @@ -9,14 +9,7 @@ trait HasExistenceQueries { - /** - * Add the constraints for a relationship query. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param \Illuminate\Database\Eloquent\Builder $parentQuery - * @param array|mixed $columns - * @return \Illuminate\Database\Eloquent\Builder - */ + /** @inheritDoc */ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*']) { $this->setRelationExistenceQueryAlias($parentQuery); @@ -44,14 +37,7 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, return $query; } - /** - * Add the constraints for a relationship query on the same table. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param \Illuminate\Database\Eloquent\Builder $parentQuery - * @param array|mixed $columns - * @return \Illuminate\Database\Eloquent\Builder - */ + /** @inheritDoc */ public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*']) { $hash = $this->getRelationCountHash(); @@ -72,7 +58,7 @@ public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder /** * Set the table alias for a relation existence query if necessary. * - * @param \Illuminate\Database\Eloquent\Builder $parentQuery + * @param \Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model> $parentQuery * @return void */ protected function setRelationExistenceQueryAlias(Builder $parentQuery): void diff --git a/src/Eloquent/Relations/Traits/IsConcatenable.php b/src/Eloquent/Relations/Traits/IsConcatenable.php index c87dbd6..a592368 100644 --- a/src/Eloquent/Relations/Traits/IsConcatenable.php +++ b/src/Eloquent/Relations/Traits/IsConcatenable.php @@ -10,10 +10,12 @@ trait IsConcatenable * Append the relation's through parents, foreign and local keys to a deep relationship. * * @param list<\Illuminate\Database\Eloquent\Model> $through - * @param array $foreignKeys - * @param array $localKeys + * @param list $foreignKeys + * @param list $localKeys * @param int $position - * @return array + * @return array{0: list, + * 1: list, + * 2: list} */ public function appendToDeepRelationship(array $through, array $foreignKeys, array $localKeys, int $position): array { diff --git a/src/Eloquent/Relations/Traits/JoinsThroughParents.php b/src/Eloquent/Relations/Traits/JoinsThroughParents.php index d6a5608..2a9579b 100644 --- a/src/Eloquent/Relations/Traits/JoinsThroughParents.php +++ b/src/Eloquent/Relations/Traits/JoinsThroughParents.php @@ -14,11 +14,13 @@ trait JoinsThroughParents /** * Join a through parent table. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model> $query * @param \Illuminate\Database\Eloquent\Model $throughParent * @param \Illuminate\Database\Eloquent\Model $predecessor - * @param \Staudenmeir\EloquentHasManyDeep\Eloquent\CompositeKey|array|string $foreignKey - * @param \Staudenmeir\EloquentHasManyDeep\Eloquent\CompositeKey|array|string $localKey + * @param array{0: string, + * 1: string}|callable|string|\Staudenmeir\EloquentHasManyDeep\Eloquent\CompositeKey $foreignKey + * @param array{0: string, + * 1: string}|callable|string|\Staudenmeir\EloquentHasManyDeep\Eloquent\CompositeKey $localKey * @param string $prefix * @return void */ @@ -64,12 +66,14 @@ function (JoinClause $join) use ($joins) { /** * Get the joins for a through parent table. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model> $query * @param \Illuminate\Database\Eloquent\Model $throughParent * @param \Illuminate\Database\Eloquent\Model $predecessor - * @param \Staudenmeir\EloquentHasManyDeep\Eloquent\CompositeKey|array|string $foreignKey - * @param \Staudenmeir\EloquentHasManyDeep\Eloquent\CompositeKey|array|string $localKey - * @return array + * @param array{0: string, + * 1: string}|callable|string|\Staudenmeir\EloquentHasManyDeep\Eloquent\CompositeKey $foreignKey + * @param array{0: string, + * 1: string}|callable|string|\Staudenmeir\EloquentHasManyDeep\Eloquent\CompositeKey $localKey + * @return list */ protected function throughParentJoins(Builder $query, Model $throughParent, Model $predecessor, $foreignKey, $localKey): array { diff --git a/src/Eloquent/Relations/Traits/RetrievesIntermediateTables.php b/src/Eloquent/Relations/Traits/RetrievesIntermediateTables.php index 5ee5256..eea41cf 100644 --- a/src/Eloquent/Relations/Traits/RetrievesIntermediateTables.php +++ b/src/Eloquent/Relations/Traits/RetrievesIntermediateTables.php @@ -11,15 +11,15 @@ trait RetrievesIntermediateTables /** * The intermediate tables to retrieve. * - * @var array + * @var array, class: class-string<\Illuminate\Database\Eloquent\Model>, postProcessor: list}> */ protected $intermediateTables = []; /** * Set the columns on an intermediate table to retrieve. * - * @param string $class - * @param array $columns + * @param class-string<\Illuminate\Database\Eloquent\Model> $class + * @param list $columns * @param string|null $accessor * @return $this */ @@ -37,8 +37,8 @@ public function withIntermediate($class, array $columns = ['*'], $accessor = nul * Set the columns on a pivot table to retrieve. * * @param string $table - * @param array $columns - * @param string $class + * @param list $columns + * @param class-string<\Illuminate\Database\Eloquent\Model> $class * @param string|null $accessor * @param callable|null $postProcessor * @return $this @@ -71,7 +71,7 @@ public function withPivot( /** * Get the intermediate columns for the relation. * - * @return array + * @return list */ protected function intermediateColumns() { @@ -91,7 +91,7 @@ protected function intermediateColumns() /** * Hydrate the intermediate table relationships on the models. * - * @param array $models + * @param list<\Illuminate\Database\Eloquent\Model> $models * @return void */ protected function hydrateIntermediateRelations(array $models) @@ -121,7 +121,7 @@ protected function hydrateIntermediateRelations(array $models) * Get the intermediate relationship from the query. * * @param \Illuminate\Database\Eloquent\Model $model - * @param array $intermediateTable + * @param array{table: string, columns: list, class: class-string<\Illuminate\Database\Eloquent\Model>, postProcessor: list} $intermediateTable * @param string $prefix * @return \Illuminate\Database\Eloquent\Model */ @@ -154,7 +154,7 @@ protected function intermediateRelation(Model $model, array $intermediateTable, * * @param \Illuminate\Database\Eloquent\Model $model * @param string $prefix - * @return array + * @return array */ protected function intermediateAttributes(Model $model, $prefix) { @@ -185,7 +185,7 @@ protected function prefix($accessor) /** * Get the intermediate tables. * - * @return array + * @return array, class: class-string<\Illuminate\Database\Eloquent\Model>, postProcessor: list}> */ public function getIntermediateTables(): array { diff --git a/src/Eloquent/Relations/Traits/SupportsCompositeKeys.php b/src/Eloquent/Relations/Traits/SupportsCompositeKeys.php index 7bdff01..ed64108 100644 --- a/src/Eloquent/Relations/Traits/SupportsCompositeKeys.php +++ b/src/Eloquent/Relations/Traits/SupportsCompositeKeys.php @@ -41,7 +41,7 @@ protected function addConstraintsWithCompositeKey(): void /** * Set the constraints for an eager load of the relation for a leading composite key. * - * @param array $models + * @param list<\Illuminate\Database\Eloquent\Model> $models * @return void */ protected function addEagerConstraintsWithCompositeKey(array $models): void @@ -77,10 +77,10 @@ function (Builder $query) use ($key) { /** * Match the eagerly loaded results to their parents for a leading composite key. * - * @param array $models - * @param \Illuminate\Database\Eloquent\Collection $results + * @param list<\Illuminate\Database\Eloquent\Model> $models + * @param \Illuminate\Database\Eloquent\Collection $results * @param string $relation - * @return array + * @return list<\Illuminate\Database\Eloquent\Model> */ protected function matchWithCompositeKey(array $models, Collection $results, string $relation): array { @@ -111,8 +111,8 @@ protected function matchWithCompositeKey(array $models, Collection $results, str /** * Build model dictionary keyed by the relation's composite foreign key. * - * @param \Illuminate\Database\Eloquent\Collection $results - * @return array + * @param \Illuminate\Database\Eloquent\Collection $results + * @return array> */ protected function buildDictionaryWithCompositeKey(Collection $results): array { @@ -138,7 +138,7 @@ protected function buildDictionaryWithCompositeKey(Collection $results): array /** * Get the columns to select for a leading composite key. * - * @return array + * @return list */ protected function shouldSelectWithCompositeKey(): array { @@ -154,7 +154,7 @@ protected function shouldSelectWithCompositeKey(): array /** * Add the constraints for a relationship query for a leading composite key. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model> $query * @return void */ public function getRelationExistenceQueryWithCompositeKey(Builder $query): void diff --git a/src/Eloquent/Traits/ConcatenatesNativeRelationships.php b/src/Eloquent/Traits/ConcatenatesNativeRelationships.php index b57d16c..d33a959 100644 --- a/src/Eloquent/Traits/ConcatenatesNativeRelationships.php +++ b/src/Eloquent/Traits/ConcatenatesNativeRelationships.php @@ -18,11 +18,13 @@ trait ConcatenatesNativeRelationships /** * Prepare a has-one-deep or has-many-deep relationship from an existing belongs-to relationship. * - * @param \Illuminate\Database\Eloquent\Relations\BelongsTo $relation + * @param \Illuminate\Database\Eloquent\Relations\BelongsTo<\Illuminate\Database\Eloquent\Model, \Illuminate\Database\Eloquent\Model> $relation * @param list<\Illuminate\Database\Eloquent\Model> $through - * @param array $foreignKeys - * @param array $localKeys - * @return array + * @param list $foreignKeys + * @param list $localKeys + * @return array{0: list, + * 1: list, + * 2: list} */ protected function hasOneOrManyDeepFromBelongsTo( BelongsTo $relation, @@ -51,11 +53,13 @@ protected function hasOneOrManyDeepFromBelongsTo( /** * Prepare a has-one-deep or has-many-deep relationship from an existing belongs-to-many relationship. * - * @param \Illuminate\Database\Eloquent\Relations\BelongsToMany $relation + * @param \Illuminate\Database\Eloquent\Relations\BelongsToMany<\Illuminate\Database\Eloquent\Model> $relation * @param list<\Illuminate\Database\Eloquent\Model> $through - * @param array $foreignKeys - * @param array $localKeys - * @return array + * @param list $foreignKeys + * @param list $localKeys + * @return array{0: list, + * 1: list, + * 2: list} */ protected function hasOneOrManyDeepFromBelongsToMany( BelongsToMany $relation, @@ -77,11 +81,13 @@ protected function hasOneOrManyDeepFromBelongsToMany( /** * Prepare a has-one-deep or has-many-deep relationship from an existing has-one or has-many relationship. * - * @param \Illuminate\Database\Eloquent\Relations\HasOneOrMany $relation + * @param \Illuminate\Database\Eloquent\Relations\HasOneOrMany<\Illuminate\Database\Eloquent\Model> $relation * @param list<\Illuminate\Database\Eloquent\Model> $through - * @param array $foreignKeys - * @param array $localKeys - * @return array + * @param list $foreignKeys + * @param list $localKeys + * @return array{0: list, + * 1: list, + * 2: list} */ protected function hasOneOrManyDeepFromHasOneOrMany( HasOneOrMany $relation, @@ -110,11 +116,13 @@ protected function hasOneOrManyDeepFromHasOneOrMany( /** * Prepare a has-one-deep or has-many-deep relationship from an existing has-many-through relationship. * - * @param \Illuminate\Database\Eloquent\Relations\HasManyThrough $relation + * @param \Illuminate\Database\Eloquent\Relations\HasManyThrough<\Illuminate\Database\Eloquent\Model> $relation * @param list<\Illuminate\Database\Eloquent\Model> $through - * @param array $foreignKeys - * @param array $localKeys - * @return array + * @param list $foreignKeys + * @param list $localKeys + * @return array{0: list, + * 1: list, + * 2: list} */ protected function hasOneOrManyDeepFromHasManyThrough( HasManyThrough $relation, @@ -136,11 +144,13 @@ protected function hasOneOrManyDeepFromHasManyThrough( /** * Prepare a has-one-deep or has-many-deep relationship from an existing has-one-through relationship. * - * @param \Illuminate\Database\Eloquent\Relations\HasOneThrough $relation + * @param \Illuminate\Database\Eloquent\Relations\HasOneThrough<\Illuminate\Database\Eloquent\Model> $relation * @param list<\Illuminate\Database\Eloquent\Model> $through - * @param array $foreignKeys - * @param array $localKeys - * @return array + * @param list $foreignKeys + * @param list $localKeys + * @return array{0: list, + * 1: list, + * 2: list} */ protected function hasOneOrManyDeepFromHasOneThrough( HasOneThrough $relation, @@ -162,11 +172,13 @@ protected function hasOneOrManyDeepFromHasOneThrough( /** * Prepare a has-one-deep or has-many-deep relationship from an existing morph-one or morph-many relationship. * - * @param \Illuminate\Database\Eloquent\Relations\MorphOneOrMany $relation + * @param \Illuminate\Database\Eloquent\Relations\MorphOneOrMany<\Illuminate\Database\Eloquent\Model> $relation * @param list<\Illuminate\Database\Eloquent\Model> $through - * @param array $foreignKeys - * @param array $localKeys - * @return array + * @param list $foreignKeys + * @param list $localKeys + * @return array{0: list, + * 1: list, + * 2: list} */ protected function hasOneOrManyDeepFromMorphOneOrMany( MorphOneOrMany $relation, @@ -184,11 +196,13 @@ protected function hasOneOrManyDeepFromMorphOneOrMany( /** * Prepare a has-one-deep or has-many-deep relationship from an existing morph-to-many relationship. * - * @param \Illuminate\Database\Eloquent\Relations\MorphToMany $relation + * @param \Illuminate\Database\Eloquent\Relations\MorphToMany<\Illuminate\Database\Eloquent\Model> $relation * @param list<\Illuminate\Database\Eloquent\Model> $through - * @param array $foreignKeys - * @param array $localKeys - * @return array + * @param list $foreignKeys + * @param list $localKeys + * @return array{0: list, + * 1: list, + * 2: list} */ protected function hasOneOrManyDeepFromMorphToMany( MorphToMany $relation, @@ -218,7 +232,7 @@ protected function hasOneOrManyDeepFromMorphToMany( /** * Get the relationship method name. * - * @param \Illuminate\Database\Eloquent\Relations\Relation $relation + * @param \Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model> $relation * @return string */ protected function hasOneOrManyDeepRelationMethod(Relation $relation) diff --git a/src/Eloquent/Traits/ConcatenatesRelationships.php b/src/Eloquent/Traits/ConcatenatesRelationships.php index 9073d71..078a797 100644 --- a/src/Eloquent/Traits/ConcatenatesRelationships.php +++ b/src/Eloquent/Traits/ConcatenatesRelationships.php @@ -16,8 +16,8 @@ trait ConcatenatesRelationships /** * Define a has-many-deep relationship from existing relationships. * - * @param \Illuminate\Database\Eloquent\Relations\Relation|callable ...$relations - * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep + * @param callable|\Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model> ...$relations + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Illuminate\Database\Eloquent\Model, $this> */ public function hasManyDeepFromRelations(...$relations) { @@ -49,8 +49,8 @@ public function hasManyDeepFromRelations(...$relations) /** * Define a has-one-deep relationship from existing relationships. * - * @param \Illuminate\Database\Eloquent\Relations\Relation|callable ...$relations - * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep + * @param callable|\Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model> ...$relations + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Illuminate\Database\Eloquent\Model, $this> */ public function hasOneDeepFromRelations(...$relations) { @@ -81,8 +81,15 @@ public function hasOneDeepFromRelations(...$relations) /** * Prepare a has-one-deep or has-many-deep relationship from existing relationships. * - * @param list $relations - * @return array + * @param list> $relations + * @return array{0: string, + * 1: list, + * 2: list, + * 3: list, + * 4: list, + * 5: callable|null, + * 6: callable|null, + * 7: callable|null} */ protected function hasOneOrManyDeepFromRelations(array $relations) { @@ -166,8 +173,8 @@ protected function hasOneOrManyDeepFromRelations(array $relations) /** * Prepare the through parent class from an existing relationship and its successor. * - * @param \Illuminate\Database\Eloquent\Relations\Relation $relation - * @param \Illuminate\Database\Eloquent\Relations\Relation $successor + * @param \Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model> $relation + * @param \Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model> $successor * @return string */ protected function hasOneOrManyThroughParent(Relation $relation, Relation $successor) @@ -198,12 +205,15 @@ protected function hasOneOrManyThroughParent(Relation $relation, Relation $succe /** * Customize a has-one-deep or has-many-deep relationship. * - * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $relation + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model + * TODO + * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $relation * @param list $postGetCallbacks * @param callable|null $customThroughKeyCallback * @param callable|null $customEagerConstraintsCallback * @param callable|null $customEagerMatchingCallback - * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep|\Staudenmeir\EloquentHasManyDeep\HasOneDeep + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep|\Staudenmeir\EloquentHasManyDeep\HasOneDeep */ protected function customizeHasOneOrManyDeepRelationship( HasManyDeep $relation, @@ -233,7 +243,7 @@ protected function customizeHasOneOrManyDeepRelationship( * Define a has-many-deep relationship with constraints from existing relationships. * * @param callable ...$relations - * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Illuminate\Database\Eloquent\Model, $this> */ public function hasManyDeepFromRelationsWithConstraints(...$relations): HasManyDeep { @@ -248,7 +258,7 @@ public function hasManyDeepFromRelationsWithConstraints(...$relations): HasManyD * Define a has-one-deep relationship with constraints from existing relationships. * * @param callable ...$relations - * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Illuminate\Database\Eloquent\Model, $this> */ public function hasOneDeepFromRelationsWithConstraints(...$relations): HasOneDeep { @@ -262,9 +272,12 @@ public function hasOneDeepFromRelationsWithConstraints(...$relations): HasOneDee /** * Add the constraints from existing relationships to a has-one-deep or has-many-deep relationship. * - * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $deepRelation + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model + * TODO + * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $deepRelation * @param list $relations - * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep|\Staudenmeir\EloquentHasManyDeep\HasOneDeep + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep|\Staudenmeir\EloquentHasManyDeep\HasOneDeep */ protected function addConstraintsToHasOneOrManyDeepRelationship( HasManyDeep $deepRelation, @@ -293,8 +306,11 @@ protected function addConstraintsToHasOneOrManyDeepRelationship( /** * Add the removed scopes from an existing relationship to a has-one-deep or has-many-deep relationship. * - * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $deepRelation - * @param \Illuminate\Database\Eloquent\Relations\Relation $relation + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model + * TODO + * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $deepRelation + * @param \Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model> $relation * @param bool $isLastRelation * @return void */ @@ -339,8 +355,8 @@ protected function addRemovedScopesToHasOneOrManyDeepRelationship( /** * Normalize the relations from a variadic parameter. * - * @param array $relations - * @return array + * @param list>|\Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model>> $relations + * @return list> */ protected function normalizeVariadicRelations(array $relations): array { diff --git a/src/Eloquent/Traits/ReversesRelationships.php b/src/Eloquent/Traits/ReversesRelationships.php index 767b41c..b94a985 100644 --- a/src/Eloquent/Traits/ReversesRelationships.php +++ b/src/Eloquent/Traits/ReversesRelationships.php @@ -12,30 +12,46 @@ trait ReversesRelationships /** * Define a has-many-deep relationship by reversing an existing deep relationship. * - * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $relation - * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model + * TODO + * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $relation + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep */ public function hasManyDeepFromReverse(HasManyDeep $relation): HasManyDeep { - return $this->hasManyDeep(...$this->hasOneOrManyDeepFromReverse($relation)); + return $this->hasManyDeep( + ...$this->hasOneOrManyDeepFromReverse($relation) + ); } /** * Define a has-one-deep relationship by reversing an existing deep relationship. * - * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $relation - * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model + * TODO + * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $relation + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep */ public function hasOneDeepFromReverse(HasManyDeep $relation): HasOneDeep { - return $this->hasOneDeep(...$this->hasOneOrManyDeepFromReverse($relation)); + return $this->hasOneDeep( + ...$this->hasOneOrManyDeepFromReverse($relation) + ); } /** * Prepare a has-one-deep or has-many-deep relationship by reversing an existing deep relationship. * - * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $relation - * @return array + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model + * TODO + * @param \Staudenmeir\EloquentHasManyDeep\HasManyDeep $relation + * @return array{0: class-string, + * 1: list, + * 2: list, + * 3: list} */ protected function hasOneOrManyDeepFromReverse(HasManyDeep $relation): array { diff --git a/src/HasManyDeep.php b/src/HasManyDeep.php index e563298..f959269 100644 --- a/src/HasManyDeep.php +++ b/src/HasManyDeep.php @@ -18,6 +18,7 @@ /** * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model * * @extends \Illuminate\Database\Eloquent\Relations\HasManyThrough */ @@ -42,25 +43,25 @@ class HasManyDeep extends HasManyThrough implements ConcatenableRelation /** * The foreign keys on the relationship. * - * @var array + * @var list */ protected $foreignKeys; /** * The local keys on the relationship. * - * @var array + * @var list */ protected $localKeys; /** * Create a new has many deep relationship instance. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Model $farParent * @param list<\Illuminate\Database\Eloquent\Model> $throughParents - * @param array $foreignKeys - * @param array $localKeys + * @param list $foreignKeys + * @param list $localKeys * @return void */ public function __construct(Builder $query, Model $farParent, array $throughParents, array $foreignKeys, array $localKeys) @@ -78,11 +79,7 @@ public function __construct(Builder $query, Model $farParent, array $throughPare parent::__construct($query, $farParent, $throughParents[0], $firstKey, $foreignKeys[1], $localKey, $localKeys[1]); } - /** - * Set the base constraints on the relation query. - * - * @return void - */ + /** @inheritDoc */ public function addConstraints() { if ($this->firstKey instanceof Closure || $this->localKey instanceof Closure) { @@ -108,12 +105,7 @@ public function addConstraints() } } - /** - * Set the join clauses on the query. - * - * @param \Illuminate\Database\Eloquent\Builder|null $query - * @return void - */ + /** @inheritDoc */ protected function performJoin(?Builder $query = null) { $query = $query ?: $this->query; @@ -138,8 +130,8 @@ protected function performJoin(?Builder $query = null) /** * Set the select clause for the relation query. * - * @param array $columns - * @return array + * @param list $columns + * @return list */ protected function shouldSelect(array $columns = ['*']) { @@ -174,7 +166,7 @@ protected function shouldSelect(array $columns = ['*']) /** * Restore soft-deleted models. * - * @param array|string ...$columns + * @param string|list ...$columns * @return $this */ public function withTrashed(...$columns) @@ -220,7 +212,7 @@ public function getThroughParents() /** * Get the foreign keys on the relationship. * - * @return array + * @return list */ public function getForeignKeys() { @@ -230,7 +222,7 @@ public function getForeignKeys() /** * Get the local keys on the relationship. * - * @return array + * @return list */ public function getLocalKeys() { diff --git a/src/HasOneDeep.php b/src/HasOneDeep.php index 25ef901..73df9a0 100644 --- a/src/HasOneDeep.php +++ b/src/HasOneDeep.php @@ -8,30 +8,21 @@ /** * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model * - * @extends \Staudenmeir\EloquentHasManyDeep\HasManyDeep + * @extends \Staudenmeir\EloquentHasManyDeep\HasManyDeep */ class HasOneDeep extends HasManyDeep { use SupportsDefaultModels; - /** - * Get the results of the relationship. - * - * @return mixed - */ + /** @inheritDoc */ public function getResults() { return $this->first() ?: $this->getDefaultFor(end($this->throughParents)); } - /** - * Initialize the relation on a set of models. - * - * @param array $models - * @param string $relation - * @return array - */ + /** @inheritDoc */ public function initRelation(array $models, $relation) { foreach ($models as $model) { @@ -41,14 +32,7 @@ public function initRelation(array $models, $relation) return $models; } - /** - * Match the eagerly loaded results to their parents. - * - * @param array $models - * @param \Illuminate\Database\Eloquent\Collection $results - * @param string $relation - * @return array - */ + /** @inheritDoc */ public function match(array $models, Collection $results, $relation) { if ($this->customEagerMatchingCallbacks) { diff --git a/src/HasRelationships.php b/src/HasRelationships.php index a51c58a..b003e9b 100644 --- a/src/HasRelationships.php +++ b/src/HasRelationships.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Pivot; +use Laravel\Prompts\Themes\Default\TableRenderer; use Staudenmeir\EloquentHasManyDeep\Eloquent\Traits\ConcatenatesRelationships; use Staudenmeir\EloquentHasManyDeep\Eloquent\Traits\ReversesRelationships; @@ -16,39 +17,51 @@ trait HasRelationships /** * Define a has-many-deep relationship. * - * @param string $related - * @param array $through - * @param array $foreignKeys - * @param array $localKeys - * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * + * @param class-string $related TODO + * @param list $through + * @param list $foreignKeys + * @param list $localKeys + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep */ public function hasManyDeep($related, array $through, array $foreignKeys = [], array $localKeys = []) { - return $this->newHasManyDeep(...$this->hasOneOrManyDeep($related, $through, $foreignKeys, $localKeys)); + return $this->newHasManyDeep( + ...$this->hasOneOrManyDeep($related, $through, $foreignKeys, $localKeys) + ); } /** * Define a has-one-deep relationship. * - * @param string $related - * @param array $through - * @param array $foreignKeys - * @param array $localKeys - * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * + * @param class-string $related TODO + * @param list $through + * @param list $foreignKeys + * @param list $localKeys + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep */ public function hasOneDeep($related, array $through, array $foreignKeys = [], array $localKeys = []) { - return $this->newHasOneDeep(...$this->hasOneOrManyDeep($related, $through, $foreignKeys, $localKeys)); + return $this->newHasOneDeep( + ...$this->hasOneOrManyDeep($related, $through, $foreignKeys, $localKeys) + ); } /** * Prepare a has-one-deep or has-many-deep relationship. * * @param string $related - * @param array $through - * @param array $foreignKeys - * @param array $localKeys - * @return array + * @param list $through + * @param list $foreignKeys + * @param list $localKeys + * @return array{0: \Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model>, + * 1: $this, + * 2: list<\Illuminate\Database\Eloquent\Model>, + * 3: list, + * 4: list} */ protected function hasOneOrManyDeep($related, array $through, array $foreignKeys, array $localKeys) { @@ -73,8 +86,8 @@ protected function hasOneOrManyDeep($related, array $through, array $foreignKeys /** * Prepare the through parents for a has-one-deep or has-many-deep relationship. * - * @param array $through - * @return array + * @param list $through + * @return list<\Illuminate\Database\Eloquent\Model> */ protected function hasOneOrManyDeepThroughParents(array $through) { @@ -113,8 +126,8 @@ protected function newRelatedDeepThroughInstance(string $class): Model * * @param \Illuminate\Database\Eloquent\Model $related * @param list<\Illuminate\Database\Eloquent\Model> $throughParents - * @param array $foreignKeys - * @return array + * @param list $foreignKeys + * @return list */ protected function hasOneOrManyDeepForeignKeys(Model $related, array $throughParents, array $foreignKeys) { @@ -137,8 +150,8 @@ protected function hasOneOrManyDeepForeignKeys(Model $related, array $throughPar * * @param \Illuminate\Database\Eloquent\Model $related * @param list<\Illuminate\Database\Eloquent\Model> $throughParents - * @param array $localKeys - * @return array + * @param list $localKeys + * @return list */ protected function hasOneOrManyDeepLocalKeys(Model $related, array $throughParents, array $localKeys) { @@ -159,12 +172,15 @@ protected function hasOneOrManyDeepLocalKeys(Model $related, array $throughParen /** * Instantiate a new HasManyDeep relationship. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param \Illuminate\Database\Eloquent\Model $farParent + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param TDeclaringModel $farParent * @param list<\Illuminate\Database\Eloquent\Model> $throughParents - * @param array $foreignKeys - * @param array $localKeys - * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep + * @param list $foreignKeys + * @param list $localKeys + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep */ protected function newHasManyDeep(Builder $query, Model $farParent, array $throughParents, array $foreignKeys, array $localKeys) { @@ -174,12 +190,15 @@ protected function newHasManyDeep(Builder $query, Model $farParent, array $throu /** * Instantiate a new HasOneDeep relationship. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param \Illuminate\Database\Eloquent\Model $farParent + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param TDeclaringModel $farParent * @param list<\Illuminate\Database\Eloquent\Model> $throughParents - * @param array $foreignKeys - * @param array $localKeys - * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep + * @param list $foreignKeys + * @param list $localKeys + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep */ protected function newHasOneDeep(Builder $query, Model $farParent, array $throughParents, array $foreignKeys, array $localKeys) { diff --git a/src/HasTableAlias.php b/src/HasTableAlias.php index a3d2d34..d544688 100644 --- a/src/HasTableAlias.php +++ b/src/HasTableAlias.php @@ -4,12 +4,7 @@ trait HasTableAlias { - /** - * Qualify the given column name by the model's table. - * - * @param string $column - * @return string - */ + /** @inheritDoc */ public function qualifyColumn($column) { if (str_contains($column, '.')) { diff --git a/src/IdeHelper/DeepRelationsHook.php b/src/IdeHelper/DeepRelationsHook.php index e2e0452..7c03091 100644 --- a/src/IdeHelper/DeepRelationsHook.php +++ b/src/IdeHelper/DeepRelationsHook.php @@ -45,6 +45,9 @@ public function run(ModelsCommand $command, Model $model): void } } + /** + * @param \Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model> $relationship + */ protected function addRelationship(ModelsCommand $command, ReflectionMethod $method, Relation $relationship): void { $manyRelation = !$relationship instanceof HasOneDeep; diff --git a/src/IdeHelperServiceProvider.php b/src/IdeHelperServiceProvider.php index 7763be1..6dc8ef0 100644 --- a/src/IdeHelperServiceProvider.php +++ b/src/IdeHelperServiceProvider.php @@ -21,6 +21,9 @@ public function register(): void $this->registerIdeHelperHook(); } + /** + * @return list + */ public function provides(): array { return [ diff --git a/tests/CompositeKeyTest.php b/tests/CompositeKeyTest.php index b6f3eaf..09282ec 100644 --- a/tests/CompositeKeyTest.php +++ b/tests/CompositeKeyTest.php @@ -7,21 +7,21 @@ class CompositeKeyTest extends TestCase { - public function testLazyLoadingWithLeadingKey() + public function testLazyLoadingWithLeadingKey(): void { $projects = Employee::find(131)->projects; $this->assertEquals([101, 102], $projects->pluck('id')->all()); } - public function testLazyLoadingWithIntermediateKey() + public function testLazyLoadingWithIntermediateKey(): void { $employees = Project::find(101)->employees; $this->assertEquals([131, 132], $employees->pluck('id')->all()); } - public function testEagerLoadingWithLeadingKey() + public function testEagerLoadingWithLeadingKey(): void { $employees = Employee::with('projects')->get(); @@ -29,7 +29,7 @@ public function testEagerLoadingWithLeadingKey() $this->assertEquals([103], $employees[2]->projects->pluck('id')->all()); } - public function testEagerLoadingWithIntermediateKey() + public function testEagerLoadingWithIntermediateKey(): void { $projects = Project::with('employees')->get(); @@ -37,7 +37,7 @@ public function testEagerLoadingWithIntermediateKey() $this->assertEquals([133], $projects[2]->employees->pluck('id')->all()); } - public function testLazyEagerLoadingWithLeadingKey() + public function testLazyEagerLoadingWithLeadingKey(): void { $employees = Employee::all()->load('projects'); @@ -45,7 +45,7 @@ public function testLazyEagerLoadingWithLeadingKey() $this->assertEquals([103], $employees[2]->projects->pluck('id')->all()); } - public function testLazyEagerLoadingWithIntermediateKey() + public function testLazyEagerLoadingWithIntermediateKey(): void { $projects = Project::all()->load('employees'); @@ -53,21 +53,21 @@ public function testLazyEagerLoadingWithIntermediateKey() $this->assertEquals([133], $projects[2]->employees->pluck('id')->all()); } - public function testExistenceQueryWithLeadingKey() + public function testExistenceQueryWithLeadingKey(): void { $employees = Employee::has('projects')->get(); $this->assertEquals([131, 132, 133], $employees->pluck('id')->all()); } - public function testExistenceQueryWithIntermediateKey() + public function testExistenceQueryWithIntermediateKey(): void { $projects = Project::has('employees')->get(); $this->assertEquals([101, 102, 103], $projects->pluck('id')->all()); } - public function testPaginateWithLeadingKey() + public function testPaginateWithLeadingKey(): void { $projects = Employee::find(131)->projects()->paginate(); @@ -75,7 +75,7 @@ public function testPaginateWithLeadingKey() $this->assertArrayNotHasKey('laravel_through_key_1', $projects[0]); } - public function testSimplePaginateWithLeadingKey() + public function testSimplePaginateWithLeadingKey(): void { $projects = Employee::find(131)->projects()->simplePaginate(); @@ -83,7 +83,7 @@ public function testSimplePaginateWithLeadingKey() $this->assertArrayNotHasKey('laravel_through_key_1', $projects[0]); } - public function testCursorPaginateWithLeadingKey() + public function testCursorPaginateWithLeadingKey(): void { $projects = Employee::find(131)->projects()->cursorPaginate(); diff --git a/tests/Concatenation/ConcatenationTest.php b/tests/Concatenation/ConcatenationTest.php index 9a16333..f6ad42e 100644 --- a/tests/Concatenation/ConcatenationTest.php +++ b/tests/Concatenation/ConcatenationTest.php @@ -13,63 +13,63 @@ class ConcatenationTest extends TestCase { - public function testHasManyDeep() + public function testHasManyDeep(): void { $comments = Country::find(1)->commentsFromRelations; $this->assertEquals([31, 32], $comments->pluck('id')->all()); } - public function testWithBelongsToMany() + public function testWithBelongsToMany(): void { $permissions = User::first()->permissionsFromRelations; $this->assertEquals([71], $permissions->pluck('id')->all()); } - public function testWithMorphManyAndBelongsTo() + public function testWithMorphManyAndBelongsTo(): void { $users = Post::first()->usersFromRelations; $this->assertEquals([11], $users->pluck('id')->all()); } - public function testWithMorphToMany() + public function testWithMorphToMany(): void { $tags = User::first()->tagsFromRelations; $this->assertEquals([91], $tags->pluck('id')->all()); } - public function testWithMorphedByMany() + public function testWithMorphedByMany(): void { $comments = Tag::first()->commentsFromRelations; $this->assertEquals([31], $comments->pluck('id')->all()); } - public function testWithHasManyDeepWithPivot() + public function testWithHasManyDeepWithPivot(): void { $permissions = Country::find(1)->permissionsFromRelations; $this->assertEquals([71], $permissions->pluck('id')->all()); } - public function testWithHasManyDeepWithPivotAlias() + public function testWithHasManyDeepWithPivotAlias(): void { $permissions = Country::find(1)->permissionsWithPivotAliasFromRelations; $this->assertEquals([71], $permissions->pluck('id')->all()); } - public function testWithAlias() + public function testWithAlias(): void { $comments = Post::find(24)->commentRepliesFromRelations; $this->assertEquals([35, 36], $comments->pluck('id')->all()); } - public function testWithCustomRelatedTable() + public function testWithCustomRelatedTable(): void { Schema::rename('comments', 'my_comments'); @@ -78,7 +78,7 @@ public function testWithCustomRelatedTable() $this->assertEquals([31, 32], $comments->pluck('id')->all()); } - public function testWithCustomThroughTable() + public function testWithCustomThroughTable(): void { Schema::rename('users', 'my_users'); @@ -87,63 +87,63 @@ public function testWithCustomThroughTable() $this->assertEquals([31, 32], $comments->pluck('id')->all()); } - public function testWithConstraints() + public function testWithConstraints(): void { $comments = Country::find(1)->commentsFromRelationsWithConstraints; $this->assertEquals([31], $comments->pluck('id')->all()); } - public function testWithTrashedFinalRelatedModel() + public function testWithTrashedFinalRelatedModel(): void { $comments = Country::find(1)->commentsFromRelationsWithTrashedFinalRelatedModel; $this->assertEquals([31, 32, 37], $comments->pluck('id')->all()); } - public function testWithTrashedIntermediateRelatedModel() + public function testWithTrashedIntermediateRelatedModel(): void { $comments = Country::find(1)->commentsFromRelationsWithTrashedIntermediateRelatedModel; $this->assertEquals([31, 32, 33], $comments->pluck('id')->all()); } - public function testWithTrashedParents() + public function testWithTrashedParents(): void { $comments = Country::find(1)->commentsFromRelationsWithTrashedParents; $this->assertEquals([31, 32, 33], $comments->pluck('id')->all()); } - public function testWithTrashedIntermediateDeepModel() + public function testWithTrashedIntermediateDeepModel(): void { $comments = Country::find(1)->commentsFromRelationsWithTrashedIntermediateDeepModel; $this->assertEquals([31, 32, 33], $comments->pluck('id')->all()); } - public function testLeadingCompositeKey() + public function testLeadingCompositeKey(): void { $projects = Employee::find(131)->projectsFromRelations; $this->assertEquals([101, 102], $projects->pluck('id')->all()); } - public function testIntermediateCompositeKey() + public function testIntermediateCompositeKey(): void { $employees = Project::find(101)->employeesFromRelations; $this->assertEquals([131, 132], $employees->pluck('id')->all()); } - public function testHasOneDeep() + public function testHasOneDeep(): void { $comment = Country::find(1)->commentFromRelations; $this->assertEquals(31, $comment->id); } - public function testHasOneDeepWithConstraints() + public function testHasOneDeepWithConstraints(): void { $comment = Country::find(1)->commentFromRelationsWithConstraints; diff --git a/tests/Concatenation/EloquentJsonRelations/BelongsToJson/FirstPositionTest.php b/tests/Concatenation/EloquentJsonRelations/BelongsToJson/FirstPositionTest.php index fee16e9..80ce877 100644 --- a/tests/Concatenation/EloquentJsonRelations/BelongsToJson/FirstPositionTest.php +++ b/tests/Concatenation/EloquentJsonRelations/BelongsToJson/FirstPositionTest.php @@ -16,14 +16,14 @@ protected function setUp(): void } } - public function testLazyLoading() + public function testLazyLoading(): void { $permissions = User::find(21)->permissions; $this->assertEquals([81, 82, 83], $permissions->pluck('id')->all()); } - public function testLazyLoadingWithObjects() + public function testLazyLoadingWithObjects(): void { $permissions = User::find(21)->permissions2; diff --git a/tests/Concatenation/EloquentJsonRelations/HasManyThroughJsonTest.php b/tests/Concatenation/EloquentJsonRelations/HasManyThroughJsonTest.php index c785254..65c47b0 100644 --- a/tests/Concatenation/EloquentJsonRelations/HasManyThroughJsonTest.php +++ b/tests/Concatenation/EloquentJsonRelations/HasManyThroughJsonTest.php @@ -10,14 +10,14 @@ class HasManyThroughJsonTest extends TestCase { - public function testLazyLoading() + public function testLazyLoading(): void { $projects = Role::find(2)->projects; $this->assertEquals([71, 73], $projects->pluck('id')->all()); } - public function testLazyLoadingWithObjects() + public function testLazyLoadingWithObjects(): void { $projects = Role::find(2)->projects2; @@ -28,14 +28,14 @@ public function testLazyLoadingWithObjects() $this->assertEquals(['role' => ['active' => false]], $pivot->getAttributes()); } - public function testLazyLoadingWithReverseRelationship() + public function testLazyLoadingWithReverseRelationship(): void { $roles = Project::find(71)->roles; $this->assertEquals([1, 2], $roles->pluck('id')->all()); } - public function testLazyLoadingWithReverseRelationshipAndObjects() + public function testLazyLoadingWithReverseRelationshipAndObjects(): void { $roles = Project::find(71)->roles2; @@ -46,14 +46,14 @@ public function testLazyLoadingWithReverseRelationshipAndObjects() $this->assertEquals(['role' => ['active' => true]], $pivot->getAttributes()); } - public function testEmptyLazyLoading() + public function testEmptyLazyLoading(): void { $projects = (new Role())->projects()->get(); $this->assertEmpty($projects); } - public function testEmptyLazyLoadingWithReverseRelationship() + public function testEmptyLazyLoadingWithReverseRelationship(): void { DB::connection()->enableQueryLog(); @@ -63,7 +63,7 @@ public function testEmptyLazyLoadingWithReverseRelationship() $this->assertEmpty(DB::connection()->getQueryLog()); } - public function testEagerLoading() + public function testEagerLoading(): void { $roles = Role::with('projects')->get(); @@ -73,7 +73,7 @@ public function testEagerLoading() $this->assertEquals([], $roles[3]->projects->pluck('id')->all()); } - public function testEagerLoadingWithObjects() + public function testEagerLoadingWithObjects(): void { $roles = Role::with('projects2')->get(); @@ -87,7 +87,7 @@ public function testEagerLoadingWithObjects() $this->assertEquals(['role' => ['active' => false]], $pivot->getAttributes()); } - public function testEagerLoadingWithReverseRelationship() + public function testEagerLoadingWithReverseRelationship(): void { $projects = Project::with('roles')->get(); @@ -96,7 +96,7 @@ public function testEagerLoadingWithReverseRelationship() $this->assertEquals([2, 3], $projects[2]->roles->pluck('id')->all()); } - public function testEagerLoadingWithReverseRelationshipAndObjects() + public function testEagerLoadingWithReverseRelationshipAndObjects(): void { $projects = Project::with('roles2')->get(); @@ -109,28 +109,28 @@ public function testEagerLoadingWithReverseRelationshipAndObjects() $this->assertEquals(['role' => ['active' => true]], $pivot->getAttributes()); } - public function testExistenceQuery() + public function testExistenceQuery(): void { $roles = Role::has('projects')->get(); $this->assertEquals([1, 2, 3], $roles->pluck('id')->all()); } - public function testExistenceQueryWithObjects() + public function testExistenceQueryWithObjects(): void { $roles = Role::has('projects2')->get(); $this->assertEquals([1, 2, 3], $roles->pluck('id')->all()); } - public function testExistenceQueryWithReverseRelationship() + public function testExistenceQueryWithReverseRelationship(): void { $projects = Project::has('roles')->get(); $this->assertEquals([71, 73], $projects->pluck('id')->all()); } - public function testExistenceQueryWithReverseRelationshipAndObjects() + public function testExistenceQueryWithReverseRelationshipAndObjects(): void { $projects = Project::has('roles2')->get(); diff --git a/tests/Concatenation/EloquentJsonRelations/Models/Project.php b/tests/Concatenation/EloquentJsonRelations/Models/Project.php index dddf379..952d315 100644 --- a/tests/Concatenation/EloquentJsonRelations/Models/Project.php +++ b/tests/Concatenation/EloquentJsonRelations/Models/Project.php @@ -13,6 +13,9 @@ class Project extends Model { use HasRelationships; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\EloquentJsonRelations\Models\Role, $this> + */ public function roles(): HasManyDeep { return $this->hasManyThroughJson( @@ -25,6 +28,9 @@ public function roles(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\EloquentJsonRelations\Models\Role, $this> + */ public function roles2(): HasManyDeep { return $this->hasManyThroughJson( diff --git a/tests/Concatenation/EloquentJsonRelations/Models/Role.php b/tests/Concatenation/EloquentJsonRelations/Models/Role.php index d4503e1..0bef317 100644 --- a/tests/Concatenation/EloquentJsonRelations/Models/Role.php +++ b/tests/Concatenation/EloquentJsonRelations/Models/Role.php @@ -14,16 +14,25 @@ class Role extends Model { use HasRelationships; + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Concatenation\EloquentJsonRelations\Models\Permission> + */ public function permissions(): HasMany { return $this->hasMany(Permission::class); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\EloquentJsonRelations\Models\Project, $this> + */ public function projects(): HasManyDeep { return $this->hasManyThroughJson(Project::class, User::class, new JsonKey('options->role_ids')); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\EloquentJsonRelations\Models\Project, $this> + */ public function projects2(): HasManyDeep { return $this->hasManyThroughJson(Project::class, User::class, new JsonKey('options->roles[]->role->id')); diff --git a/tests/Concatenation/EloquentJsonRelations/Models/User.php b/tests/Concatenation/EloquentJsonRelations/Models/User.php index eb2f006..dbc42c8 100644 --- a/tests/Concatenation/EloquentJsonRelations/Models/User.php +++ b/tests/Concatenation/EloquentJsonRelations/Models/User.php @@ -14,11 +14,17 @@ class User extends Model 'options' => 'json', ]; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\EloquentJsonRelations\Models\Permission, $this> + */ public function permissions(): HasManyDeep { return $this->hasManyDeepFromRelations($this->roles(), (new Role())->permissions()); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\EloquentJsonRelations\Models\Permission, $this> + */ public function permissions2(): HasManyDeep { return $this->hasManyDeepFromRelations($this->roles2(), (new Role())->permissions()); diff --git a/tests/Concatenation/LaravelAdjacencyList/AncestorsTest.php b/tests/Concatenation/LaravelAdjacencyList/AncestorsTest.php index 960b710..8c4c31e 100644 --- a/tests/Concatenation/LaravelAdjacencyList/AncestorsTest.php +++ b/tests/Concatenation/LaravelAdjacencyList/AncestorsTest.php @@ -8,28 +8,28 @@ class AncestorsTest extends TestCase { - public function testLazyLoading() + public function testLazyLoading(): void { $posts = User::find(8)->ancestorPosts()->orderBy('id')->get(); $this->assertEquals([10, 20, 50], $posts->pluck('id')->all()); } - public function testLazyLoadingAndSelf() + public function testLazyLoadingAndSelf(): void { $posts = User::find(8)->ancestorAndSelfPosts()->orderBy('id')->get(); $this->assertEquals([10, 20, 50, 80], $posts->pluck('id')->all()); } - public function testLazyLoadingWithoutParentKey() + public function testLazyLoadingWithoutParentKey(): void { $posts = (new User())->ancestorPosts()->get(); $this->assertEmpty($posts); } - public function testEagerLoading() + public function testEagerLoading(): void { $users = User::with([ 'ancestorPosts' => fn (HasManyDeep $query) => $query->orderBy('id'), @@ -41,7 +41,7 @@ public function testEagerLoading() $this->assertEquals([], $users[10]->ancestorPosts->pluck('id')->all()); } - public function testEagerLoadingAndSelf() + public function testEagerLoadingAndSelf(): void { $users = User::with('ancestorAndSelfPosts')->get(); @@ -51,7 +51,7 @@ public function testEagerLoadingAndSelf() $this->assertEquals([100, 110], $users[10]->ancestorAndSelfPosts->pluck('id')->all()); } - public function testEagerLoadingWithHasOneDeep() + public function testEagerLoadingWithHasOneDeep(): void { $users = User::with([ 'ancestorPost' => fn (HasManyDeep $query) => $query->orderBy('id'), @@ -63,7 +63,7 @@ public function testEagerLoadingWithHasOneDeep() $this->assertNull($users[10]->ancestorPost); } - public function testLazyEagerLoading() + public function testLazyEagerLoading(): void { $users = User::all()->load([ 'ancestorPosts' => fn (Relation $query) => $query->getQuery()->orderBy('id'), @@ -75,7 +75,7 @@ public function testLazyEagerLoading() $this->assertEquals([], $users[10]->ancestorPosts->pluck('id')->all()); } - public function testLazyEagerLoadingAndSelf() + public function testLazyEagerLoadingAndSelf(): void { $users = User::all()->load('ancestorAndSelfPosts'); @@ -85,7 +85,7 @@ public function testLazyEagerLoadingAndSelf() $this->assertEquals([100, 110], $users[10]->ancestorAndSelfPosts->pluck('id')->all()); } - public function testExistenceQuery() + public function testExistenceQuery(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); @@ -96,7 +96,7 @@ public function testExistenceQuery() $this->assertEquals([5, 6, 7, 8, 9], $users->pluck('id')->all()); } - public function testExistenceQueryAndSelf() + public function testExistenceQueryAndSelf(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); @@ -107,7 +107,7 @@ public function testExistenceQueryAndSelf() $this->assertEquals([5, 6, 7, 8, 9], $users->pluck('id')->all()); } - public function testExistenceQueryForSelfRelation() + public function testExistenceQueryForSelfRelation(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); @@ -118,7 +118,7 @@ public function testExistenceQueryForSelfRelation() $this->assertEquals([5, 6, 7, 8, 9], $users->pluck('id')->all()); } - public function testExistenceQueryForSelfRelationAndSelf() + public function testExistenceQueryForSelfRelationAndSelf(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); diff --git a/tests/Concatenation/LaravelAdjacencyList/BloodlineTest.php b/tests/Concatenation/LaravelAdjacencyList/BloodlineTest.php index 939eb3c..fdb3e86 100644 --- a/tests/Concatenation/LaravelAdjacencyList/BloodlineTest.php +++ b/tests/Concatenation/LaravelAdjacencyList/BloodlineTest.php @@ -8,21 +8,21 @@ class BloodlineTest extends TestCase { - public function testLazyLoading() + public function testLazyLoading(): void { $posts = User::find(5)->bloodlinePosts()->orderBy('id')->get(); $this->assertEquals([10, 20, 50, 80], $posts->pluck('id')->all()); } - public function testLazyLoadingWithoutParentKey() + public function testLazyLoadingWithoutParentKey(): void { $posts = (new User())->bloodlinePosts()->get(); $this->assertEmpty($posts); } - public function testEagerLoading() + public function testEagerLoading(): void { $users = User::with([ 'bloodlinePosts' => fn (HasManyDeep $query) => $query->orderBy('id'), @@ -33,7 +33,7 @@ public function testEagerLoading() $this->assertEquals([10, 20, 50, 80], $users[4]->bloodlinePosts->pluck('id')->all()); } - public function testLazyEagerLoading() + public function testLazyEagerLoading(): void { $users = User::all()->load([ 'bloodlinePosts' => fn (Relation $query) => $query->getQuery()->orderBy('id'), @@ -44,7 +44,7 @@ public function testLazyEagerLoading() $this->assertEquals([10, 20, 50, 80], $users[4]->bloodlinePosts->pluck('id')->all()); } - public function testExistenceQuery() + public function testExistenceQuery(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); @@ -55,7 +55,7 @@ public function testExistenceQuery() $this->assertEquals([5, 2], $users->pluck('id')->all()); } - public function testExistenceQueryForSelfRelation() + public function testExistenceQueryForSelfRelation(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); diff --git a/tests/Concatenation/LaravelAdjacencyList/DescendantsTest.php b/tests/Concatenation/LaravelAdjacencyList/DescendantsTest.php index 9922f47..337198c 100644 --- a/tests/Concatenation/LaravelAdjacencyList/DescendantsTest.php +++ b/tests/Concatenation/LaravelAdjacencyList/DescendantsTest.php @@ -6,28 +6,28 @@ class DescendantsTest extends TestCase { - public function testLazyLoading() + public function testLazyLoading(): void { $posts = User::find(2)->descendantPosts; $this->assertEquals([50, 80], $posts->pluck('id')->all()); } - public function testLazyLoadingAndSelf() + public function testLazyLoadingAndSelf(): void { $posts = User::find(2)->descendantPostsAndSelf; $this->assertEquals([20, 50, 80], $posts->pluck('id')->all()); } - public function testLazyLoadingWithoutParentKey() + public function testLazyLoadingWithoutParentKey(): void { $posts = (new User())->descendantPosts()->get(); $this->assertEmpty($posts); } - public function testEagerLoading() + public function testEagerLoading(): void { $users = User::with('descendantPosts')->get(); @@ -37,7 +37,7 @@ public function testEagerLoading() $this->assertEquals([100, 110], $users[9]->descendantPosts->pluck('id')->all()); } - public function testEagerLoadingAndSelf() + public function testEagerLoadingAndSelf(): void { $users = User::with('descendantPostsAndSelf')->get(); @@ -47,7 +47,7 @@ public function testEagerLoadingAndSelf() $this->assertEquals([100, 110], $users[9]->descendantPostsAndSelf->pluck('id')->all()); } - public function testEagerLoadingWithHasOneDeep() + public function testEagerLoadingWithHasOneDeep(): void { $users = User::with('descendantPost')->get(); @@ -57,7 +57,7 @@ public function testEagerLoadingWithHasOneDeep() $this->assertEquals(100, $users[9]->descendantPost->id); } - public function testLazyEagerLoading() + public function testLazyEagerLoading(): void { $users = User::all()->load('descendantPosts'); @@ -67,7 +67,7 @@ public function testLazyEagerLoading() $this->assertEquals([100, 110], $users[9]->descendantPosts->pluck('id')->all()); } - public function testLazyEagerLoadingAndSelf() + public function testLazyEagerLoadingAndSelf(): void { $users = User::all()->load('descendantPostsAndSelf'); @@ -77,7 +77,7 @@ public function testLazyEagerLoadingAndSelf() $this->assertEquals([100, 110], $users[9]->descendantPostsAndSelf->pluck('id')->all()); } - public function testExistenceQuery() + public function testExistenceQuery(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); @@ -88,7 +88,7 @@ public function testExistenceQuery() $this->assertEquals([2, 1], $users->pluck('id')->all()); } - public function testExistenceQueryAndSelf() + public function testExistenceQueryAndSelf(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); @@ -99,7 +99,7 @@ public function testExistenceQueryAndSelf() $this->assertEquals([2, 1], $users->pluck('id')->all()); } - public function testExistenceQueryForSelfRelation() + public function testExistenceQueryForSelfRelation(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); @@ -110,7 +110,7 @@ public function testExistenceQueryForSelfRelation() $this->assertEquals([1, 2, 11], $users->pluck('id')->all()); } - public function testExistenceQueryForSelfRelationAndSelf() + public function testExistenceQueryForSelfRelationAndSelf(): void { if (in_array($this->connection, ['mariadb', 'sqlsrv'])) { $this->markTestSkipped(); diff --git a/tests/Concatenation/LaravelAdjacencyList/Models/User.php b/tests/Concatenation/LaravelAdjacencyList/Models/User.php index 0f7bc98..29d89a1 100644 --- a/tests/Concatenation/LaravelAdjacencyList/Models/User.php +++ b/tests/Concatenation/LaravelAdjacencyList/Models/User.php @@ -9,6 +9,7 @@ use Staudenmeir\EloquentHasManyDeep\HasRelationships; use Staudenmeir\EloquentHasManyDeep\HasTableAlias; use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships; +use Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants; /** * @property-read \Tests\Concatenation\LaravelAdjacencyList\Models\Post $ancestorPost @@ -21,6 +22,9 @@ class User extends Model use HasTableAlias; use SoftDeletes; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\Concatenation\LaravelAdjacencyList\Models\Post, $this> + */ public function ancestorPost(): HasOneDeep { return $this->hasOneDeepFromRelations( @@ -29,6 +33,9 @@ public function ancestorPost(): HasOneDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\LaravelAdjacencyList\Models\Post, $this> + */ public function ancestorPosts(): HasManyDeep { return $this->hasManyDeepFromRelations( @@ -37,6 +44,9 @@ public function ancestorPosts(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\LaravelAdjacencyList\Models\Post, $this> + */ public function ancestorAndSelfPosts(): HasManyDeep { return $this->hasManyDeepFromRelations( @@ -45,6 +55,9 @@ public function ancestorAndSelfPosts(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\LaravelAdjacencyList\Models\Post, $this> + */ public function bloodlinePosts(): HasManyDeep { return $this->hasManyDeepFromRelations( @@ -53,6 +66,9 @@ public function bloodlinePosts(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\Concatenation\LaravelAdjacencyList\Models\Post, $this> + */ public function descendantPost(): HasOneDeep { return $this->hasOneDeepFromRelations( @@ -61,6 +77,9 @@ public function descendantPost(): HasOneDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\LaravelAdjacencyList\Models\Post, $this> + */ public function descendantPosts(): HasManyDeep { return $this->hasManyDeepFromRelations( @@ -69,6 +88,9 @@ public function descendantPosts(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\LaravelAdjacencyList\Models\Post, $this> + */ public function descendantPostsAndSelf(): HasManyDeep { return $this->hasManyDeepFromRelations( @@ -77,7 +99,10 @@ public function descendantPostsAndSelf(): HasManyDeep ); } - public function posts() + /** + * @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<\Tests\Concatenation\LaravelAdjacencyList\Models\Post> + */ + public function posts(): HasManyOfDescendants { return $this->hasManyOfDescendants(Post::class); } diff --git a/tests/Concatenation/LaravelHasManyMerged/HasManyMergedTest.php b/tests/Concatenation/LaravelHasManyMerged/HasManyMergedTest.php index 56e0471..fc055f0 100644 --- a/tests/Concatenation/LaravelHasManyMerged/HasManyMergedTest.php +++ b/tests/Concatenation/LaravelHasManyMerged/HasManyMergedTest.php @@ -7,28 +7,28 @@ class HasManyMergedTest extends TestCase { - public function testLazyLoadingWithLeadingKey() + public function testLazyLoadingWithLeadingKey(): void { $messages = User::find(11)->attachments; $this->assertEquals([31, 33], $messages->pluck('id')->all()); } - public function testLazyLoadingWithIntermediateKey() + public function testLazyLoadingWithIntermediateKey(): void { $attachments = Country::find(1)->attachments; $this->assertEquals([31, 31, 32, 33], $attachments->pluck('id')->all()); } - public function testLazyLoadingWithTrailingKey() + public function testLazyLoadingWithTrailingKey(): void { $messages = Country::find(1)->messages; $this->assertEquals([21, 21, 22, 23], $messages->pluck('id')->all()); } - public function testEagerLoadingWithLeadingKey() + public function testEagerLoadingWithLeadingKey(): void { $users = User::with('attachments')->get(); @@ -37,7 +37,7 @@ public function testEagerLoadingWithLeadingKey() $this->assertEquals([], $users[4]->attachments->pluck('id')->all()); } - public function testEagerLoadingWithIntermediateKey() + public function testEagerLoadingWithIntermediateKey(): void { $countries = Country::with('attachments')->get(); @@ -46,7 +46,7 @@ public function testEagerLoadingWithIntermediateKey() $this->assertEquals([], $countries[3]->attachments->pluck('id')->all()); } - public function testEagerLoadingWithTrailingKey() + public function testEagerLoadingWithTrailingKey(): void { $countries = Country::with('messages')->get(); @@ -55,7 +55,7 @@ public function testEagerLoadingWithTrailingKey() $this->assertEquals([], $countries[3]->messages->pluck('id')->all()); } - public function testLazyEagerLoadingWithLeadingKey() + public function testLazyEagerLoadingWithLeadingKey(): void { $users = User::all()->load('attachments'); @@ -64,7 +64,7 @@ public function testLazyEagerLoadingWithLeadingKey() $this->assertEquals([], $users[4]->attachments->pluck('id')->all()); } - public function testLazyEagerLoadingWithIntermediateKey() + public function testLazyEagerLoadingWithIntermediateKey(): void { $countries = Country::all()->load('attachments'); @@ -73,7 +73,7 @@ public function testLazyEagerLoadingWithIntermediateKey() $this->assertEquals([], $countries[3]->attachments->pluck('id')->all()); } - public function testLazyEagerLoadingWithTrailingKey() + public function testLazyEagerLoadingWithTrailingKey(): void { $countries = Country::all()->load('messages'); @@ -82,28 +82,28 @@ public function testLazyEagerLoadingWithTrailingKey() $this->assertEquals([], $countries[3]->messages->pluck('id')->all()); } - public function testExistenceQueryWithLeadingKey() + public function testExistenceQueryWithLeadingKey(): void { $users = User::has('attachments')->get(); $this->assertEquals([11, 12, 13], $users->pluck('id')->all()); } - public function testExistenceQueryWithIntermediateKey() + public function testExistenceQueryWithIntermediateKey(): void { $countries = Country::has('attachments')->get(); $this->assertEquals([1, 2], $countries->pluck('id')->all()); } - public function testExistenceQueryWithTrailingKey() + public function testExistenceQueryWithTrailingKey(): void { $messages = Country::has('messages')->get(); $this->assertEquals([1, 2, 3], $messages->pluck('id')->all()); } - public function testPaginateWithLeadingKey() + public function testPaginateWithLeadingKey(): void { $users = User::find(11)->attachments()->paginate(); @@ -111,7 +111,7 @@ public function testPaginateWithLeadingKey() $this->assertArrayNotHasKey('laravel_through_key_1', $users[0]); } - public function testSimplePaginateWithLeadingKey() + public function testSimplePaginateWithLeadingKey(): void { $attachments = User::find(11)->attachments()->simplePaginate(); @@ -119,7 +119,7 @@ public function testSimplePaginateWithLeadingKey() $this->assertArrayNotHasKey('laravel_through_key_1', $attachments[0]); } - public function testCursorPaginateWithLeadingKey() + public function testCursorPaginateWithLeadingKey(): void { $attachments = User::find(11)->attachments()->cursorPaginate(); diff --git a/tests/Concatenation/LaravelHasManyMerged/Models/Country.php b/tests/Concatenation/LaravelHasManyMerged/Models/Country.php index 5824d90..85b3842 100644 --- a/tests/Concatenation/LaravelHasManyMerged/Models/Country.php +++ b/tests/Concatenation/LaravelHasManyMerged/Models/Country.php @@ -11,6 +11,9 @@ class Country extends Model { use HasRelationships; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\LaravelHasManyMerged\Models\Attachment, $this> + */ public function attachments(): HasManyDeep { return $this->hasManyDeepFromRelations( @@ -20,11 +23,17 @@ public function attachments(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\LaravelHasManyMerged\Models\Message, $this> + */ public function messages(): HasManyDeep { return $this->hasManyDeepFromRelations($this->users(), (new User())->messages()); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Concatenation\LaravelHasManyMerged\Models\User> + */ public function users(): HasMany { return $this->hasMany(User::class); diff --git a/tests/Concatenation/LaravelHasManyMerged/Models/Message.php b/tests/Concatenation/LaravelHasManyMerged/Models/Message.php index 64e6dce..0fd8db8 100644 --- a/tests/Concatenation/LaravelHasManyMerged/Models/Message.php +++ b/tests/Concatenation/LaravelHasManyMerged/Models/Message.php @@ -7,6 +7,9 @@ class Message extends Model { + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Concatenation\LaravelHasManyMerged\Models\Attachment> + */ public function attachments(): HasMany { return $this->hasMany(Attachment::class); diff --git a/tests/Concatenation/LaravelHasManyMerged/Models/User.php b/tests/Concatenation/LaravelHasManyMerged/Models/User.php index 2edea95..ce8c968 100644 --- a/tests/Concatenation/LaravelHasManyMerged/Models/User.php +++ b/tests/Concatenation/LaravelHasManyMerged/Models/User.php @@ -13,11 +13,17 @@ class User extends Model use HasManyMergedRelation; use HasRelationships; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Concatenation\LaravelHasManyMerged\Models\Attachment, $this> + */ public function attachments(): HasManyDeep { return $this->hasManyDeepFromRelations($this->messages(), (new Message())->attachments()); } + /** + * @return \Korridor\LaravelHasManyMerged\HasManyMerged<\Tests\Concatenation\LaravelHasManyMerged\Models\Message> + */ public function messages(): HasManyMerged { return $this->hasManyMerged(Message::class, ['sender_id', 'recipient_id']); diff --git a/tests/HasManyDeepTest.php b/tests/HasManyDeepTest.php index 92ee847..490d09e 100644 --- a/tests/HasManyDeepTest.php +++ b/tests/HasManyDeepTest.php @@ -11,63 +11,63 @@ class HasManyDeepTest extends TestCase { - public function testLazyLoading() + public function testLazyLoading(): void { $comments = Country::find(1)->comments; $this->assertEquals([31, 32], $comments->pluck('id')->all()); } - public function testLazyLoadingWithLeadingBelongsToMany() + public function testLazyLoadingWithLeadingBelongsToMany(): void { $permissions = User::first()->permissions; $this->assertEquals([71], $permissions->pluck('id')->all()); } - public function testLazyLoadingWithIntermediateBelongsToMany() + public function testLazyLoadingWithIntermediateBelongsToMany(): void { $permissions = Country::find(1)->permissions; $this->assertEquals([71], $permissions->pluck('id')->all()); } - public function testLazyLoadingWithTrailingBelongsToMany() + public function testLazyLoadingWithTrailingBelongsToMany(): void { $roles = Country::find(1)->roles; $this->assertEquals([61], $roles->pluck('id')->all()); } - public function testLazyLoadingWithLeadingMorphMany() + public function testLazyLoadingWithLeadingMorphMany(): void { $likes = Post::first()->users; $this->assertEquals([11], $likes->pluck('id')->all()); } - public function testLazyLoadingWithTrailingMorphMany() + public function testLazyLoadingWithTrailingMorphMany(): void { $likes = User::first()->likes; $this->assertEquals([81], $likes->pluck('id')->all()); } - public function testLazyLoadingWithMorphedByMany() + public function testLazyLoadingWithMorphedByMany(): void { $comments = Tag::first()->comments; $this->assertEquals([31], $comments->pluck('id')->all()); } - public function testLazyLoadingWithAlias() + public function testLazyLoadingWithAlias(): void { $comments = Post::find(24)->commentReplies; $this->assertEquals([35, 36], $comments->pluck('id')->all()); } - public function testEagerLoading() + public function testEagerLoading(): void { $countries = Country::with('comments')->get(); @@ -75,91 +75,91 @@ public function testEagerLoading() $this->assertEquals([34, 35, 36], $countries[1]->comments->pluck('id')->all()); } - public function testEagerLoadingWithLeadingMorphMany() + public function testEagerLoadingWithLeadingMorphMany(): void { $posts = Post::with('users')->get(); $this->assertEquals([11], $posts[0]->users->pluck('id')->all()); } - public function testEagerLoadingWithTrailingMorphMany() + public function testEagerLoadingWithTrailingMorphMany(): void { $users = User::with('likes')->get(); $this->assertEquals([81], $users[0]->likes->pluck('id')->all()); } - public function testEagerLoadingWithMorphedByMany() + public function testEagerLoadingWithMorphedByMany(): void { $tags = Tag::with('comments')->get(); $this->assertEquals([31], $tags[0]->comments->pluck('id')->all()); } - public function testLazyEagerLoading() + public function testLazyEagerLoading(): void { $countries = Country::all()->load('comments'); $this->assertEquals([31, 32], $countries[0]->comments->pluck('id')->all()); } - public function testExistenceQuery() + public function testExistenceQuery(): void { $countries = Country::has('comments')->get(); $this->assertEquals([1, 2], $countries->pluck('id')->all()); } - public function testExistenceQueryWithLeadingMorphMany() + public function testExistenceQueryWithLeadingMorphMany(): void { $posts = Post::has('users')->get(); $this->assertEquals([21, 23], $posts->pluck('id')->all()); } - public function testExistenceQueryWithTrailingMorphMany() + public function testExistenceQueryWithTrailingMorphMany(): void { $users = User::has('likes')->get(); $this->assertEquals([11], $users->pluck('id')->all()); } - public function testExistenceQueryWithMorphedByMany() + public function testExistenceQueryWithMorphedByMany(): void { $tags = Tag::has('comments')->get(); $this->assertEquals([91], $tags->pluck('id')->all()); } - public function testExistenceQueryForSelfRelation() + public function testExistenceQueryForSelfRelation(): void { $users = User::has('players')->get(); $this->assertEquals([11], $users->pluck('id')->all()); } - public function testExistenceQueryForSelfRelationWithLeadingMorphMany() + public function testExistenceQueryForSelfRelationWithLeadingMorphMany(): void { $posts = Post::has('posts')->get(); $this->assertEquals([21, 23], $posts->pluck('id')->all()); } - public function testExistenceQueryForThroughSelfRelation() + public function testExistenceQueryForThroughSelfRelation(): void { $users = UserWithAliasTrait::withCount('teamPosts')->get(); $this->assertEquals([2, 2, 1], $users->pluck('team_posts_count')->all()); } - public function testExistenceQueryForThroughSelfRelationWithoutAliasTrait() + public function testExistenceQueryForThroughSelfRelationWithoutAliasTrait(): void { $this->expectExceptionMessageMatches('/' . preg_quote(User::class) . '/'); User::withCount('teamPosts')->get(); } - public function testWithTrashed() + public function testWithTrashed(): void { /** @var \Tests\Models\User $user */ $user = Comment::find(33)->user() @@ -169,7 +169,7 @@ public function testWithTrashed() $this->assertEquals(13, $user->id); } - public function testWithTrashedIntermediate() + public function testWithTrashedIntermediate(): void { $comments = Country::find(1)->comments() ->withTrashed(['users.deleted_at']) @@ -178,7 +178,7 @@ public function testWithTrashedIntermediate() $this->assertEquals([31, 32, 33], $comments->pluck('id')->all()); } - public function testWithTrashedIntermediateAndWithCount() + public function testWithTrashedIntermediateAndWithCount(): void { $country = Country::withCount('commentsWithTrashedUsers as count')->first(); diff --git a/tests/HasOneDeepTest.php b/tests/HasOneDeepTest.php index f7bcbd0..337484d 100644 --- a/tests/HasOneDeepTest.php +++ b/tests/HasOneDeepTest.php @@ -7,14 +7,14 @@ class HasOneDeepTest extends TestCase { - public function testLazyLoading() + public function testLazyLoading(): void { $comment = Country::find(1)->comment; $this->assertEquals(31, $comment->id); } - public function testLazyLoadingWithDefault() + public function testLazyLoadingWithDefault(): void { $comment = Country::find(3)->comment; @@ -22,7 +22,7 @@ public function testLazyLoadingWithDefault() $this->assertFalse($comment->exists); } - public function testEagerLoading() + public function testEagerLoading(): void { $countries = Country::with('comment')->get(); @@ -31,7 +31,7 @@ public function testEagerLoading() $this->assertFalse($countries[2]->comment->exists); } - public function testLazyEagerLoading() + public function testLazyEagerLoading(): void { $countries = Country::all()->load('comment'); diff --git a/tests/IdeHelper/DeepRelationsHookTest.php b/tests/IdeHelper/DeepRelationsHookTest.php index 2dab4e0..9ea28ed 100644 --- a/tests/IdeHelper/DeepRelationsHookTest.php +++ b/tests/IdeHelper/DeepRelationsHookTest.php @@ -26,7 +26,7 @@ protected function setUp(): void $db->bootEloquent(); } - public function testRun() + public function testRun(): void { $command = Mockery::mock(ModelsCommand::class); $command->shouldReceive('setProperty')->once()->with( diff --git a/tests/IdeHelper/Models/User.php b/tests/IdeHelper/Models/User.php index ec8e822..5d788c3 100644 --- a/tests/IdeHelper/Models/User.php +++ b/tests/IdeHelper/Models/User.php @@ -11,11 +11,17 @@ class User extends Model { use HasRelationships; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\IdeHelper\Models\Comment, $this> + */ public function comment(): HasOneDeep { return $this->hasOneDeep(Comment::class, [Post::class]); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\IdeHelper\Models\Comment, $this> + */ public function comments(): HasManyDeep { return $this->hasManyDeep(Comment::class, [Post::class]); diff --git a/tests/IntermediateTableTest.php b/tests/IntermediateTableTest.php index d0669ec..e77f52c 100644 --- a/tests/IntermediateTableTest.php +++ b/tests/IntermediateTableTest.php @@ -11,7 +11,7 @@ class IntermediateTableTest extends TestCase { - public function testWithIntermediate() + public function testWithIntermediate(): void { $comments = Country::find(1)->comments() ->withIntermediate(User::class, ['id', 'deleted_at'], 'post.user') @@ -24,7 +24,7 @@ public function testWithIntermediate() $this->assertEquals(['id' => 11, 'deleted_at' => null], $post->user->getAttributes()); } - public function testWithPivot() + public function testWithPivot(): void { $permissions = User::first()->permissions() ->withPivot('role_user', ['role_id']) @@ -36,7 +36,7 @@ public function testWithPivot() $this->assertEquals(['role_id' => 61, 'user_id' => 11], $pivot->getAttributes()); } - public function testWithPivotWithClass() + public function testWithPivotWithClass(): void { $permissions = User::first()->permissions() ->withPivot('role_user', ['role_id'], RoleUser::class, 'pivot') @@ -47,7 +47,7 @@ public function testWithPivotWithClass() $this->assertEquals(['role_id' => 61], $pivot->getAttributes()); } - public function testWithPivotWithPostProcessor() + public function testWithPivotWithPostProcessor(): void { $permissions = User::first()->permissions() ->withPivot('role_user', ['role_id'], postProcessor: function (Model $model, array $attributes) { @@ -58,7 +58,7 @@ public function testWithPivotWithPostProcessor() $this->assertEquals(['role_id' => 61, 'foo' => 'bar'], $pivot->getAttributes()); } - public function testPaginate() + public function testPaginate(): void { $comments = Country::find(1)->comments() ->withIntermediate(Post::class) @@ -68,7 +68,7 @@ public function testPaginate() $this->assertArrayNotHasKey('laravel_through_key', $comments[0]); } - public function testSimplePaginate() + public function testSimplePaginate(): void { $comments = Country::find(1)->comments() ->withIntermediate(Post::class) @@ -78,7 +78,7 @@ public function testSimplePaginate() $this->assertArrayNotHasKey('laravel_through_key', $comments[0]); } - public function testCursorPaginator() + public function testCursorPaginator(): void { $comments = Country::find(1)->comments() ->withIntermediate(Post::class) @@ -88,7 +88,7 @@ public function testCursorPaginator() $this->assertArrayNotHasKey('laravel_through_key', $comments[0]); } - public function testChunk() + public function testChunk(): void { Country::find(1)->comments() ->withIntermediate(Post::class) @@ -97,7 +97,7 @@ public function testChunk() }); } - public function testGetIntermediateTables() + public function testGetIntermediateTables(): void { $comments = Country::find(1)->comments(); diff --git a/tests/Models/Comment.php b/tests/Models/Comment.php index 254c533..3081db7 100644 --- a/tests/Models/Comment.php +++ b/tests/Models/Comment.php @@ -19,6 +19,9 @@ class Comment extends Model use HasTableAlias; use SoftDeletes; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\Models\Country, $this> + */ public function country(): HasOneDeep { return $this->hasOneDeepFromReverse( @@ -26,6 +29,9 @@ public function country(): HasOneDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\Models\Country, $this> + */ public function countryWithCustomThroughTable(): HasOneDeep { return $this->hasOneDeepFromReverse( @@ -33,11 +39,17 @@ public function countryWithCustomThroughTable(): HasOneDeep ); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Models\Comment> + */ public function replies(): HasMany { - return $this->hasMany(static::class, 'parent_id'); + return $this->hasMany(Comment::class, 'parent_id'); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\Models\Post, $this> + */ public function rootPost(): HasOneDeep { return $this->hasOneDeepFromReverse( @@ -45,6 +57,9 @@ public function rootPost(): HasOneDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Tag, $this> + */ public function tags(): HasManyDeep { return $this->hasManyDeepFromReverse( @@ -52,6 +67,9 @@ public function tags(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\Models\User, $this> + */ public function user(): HasOneDeep { return $this->hasOneDeep( diff --git a/tests/Models/Country.php b/tests/Models/Country.php index 5bb3aba..e447657 100644 --- a/tests/Models/Country.php +++ b/tests/Models/Country.php @@ -14,34 +14,52 @@ */ class Country extends Model { + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\Models\Comment, $this> + */ public function comment(): HasOneDeep { return $this->hasOneDeep(Comment::class, [User::class, Post::class])->withDefault(); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\Models\Comment, $this> + */ public function commentFromRelations(): HasOneDeep { return $this->hasOneDeepFromRelations($this->posts(), (new Post())->comments()); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasOneDeep<\Tests\Models\Comment, $this> + */ public function commentFromRelationsWithConstraints(): HasOneDeep { return $this->hasOneDeepFromRelationsWithConstraints( [$this, 'postsWithConstraints'], [new Post(), 'comments'] - )->orderByDesc('comments.id'); + )->orderByDesc('comments.id'); // TODO } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function comments(): HasManyDeep { return $this->hasManyDeep(Comment::class, [User::class, Post::class]); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations([$this->posts(), (new Post())->comments()]); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsFromRelationsWithConstraints(): HasManyDeep { return $this->hasManyDeepFromRelationsWithConstraints( @@ -49,6 +67,9 @@ public function commentsFromRelationsWithConstraints(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsFromRelationsWithTrashedFinalRelatedModel(): HasManyDeep { return $this->hasManyDeepFromRelationsWithConstraints( @@ -56,11 +77,17 @@ public function commentsFromRelationsWithTrashedFinalRelatedModel(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsFromRelationsWithTrashedIntermediateDeepModel(): HasManyDeep { return $this->hasManyDeepFromRelationsWithConstraints([$this, 'commentsWithTrashedUsers']); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsFromRelationsWithTrashedIntermediateRelatedModel(): HasManyDeep { return $this->hasManyDeepFromRelationsWithConstraints( @@ -68,6 +95,9 @@ public function commentsFromRelationsWithTrashedIntermediateRelatedModel(): HasM ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsFromRelationsWithTrashedParents(): HasManyDeep { return $this->hasManyDeepFromRelationsWithConstraints( @@ -75,6 +105,9 @@ public function commentsFromRelationsWithTrashedParents(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsFromRelationsWithCustomRelatedTable(): HasManyDeep { $comment = (new Comment())->setTable('my_comments'); @@ -89,6 +122,9 @@ public function commentsFromRelationsWithCustomRelatedTable(): HasManyDeep return $this->hasManyDeepFromRelations([$this->posts(), $comments]); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsFromRelationsWithCustomThroughTable(): HasManyDeep { $user = (new User())->setTable('my_users'); @@ -103,51 +139,81 @@ public function commentsFromRelationsWithCustomThroughTable(): HasManyDeep return $this->hasManyDeepFromRelations([$users, (new User())->comments()]); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsWithTrashedUsers(): HasManyDeep { return $this->comments()->withTrashed('users.deleted_at'); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Permission, $this> + */ public function permissions(): HasManyDeep { return $this->hasManyDeep(Permission::class, [User::class, 'role_user', Role::class]); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Permission, $this> + */ public function permissionsFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations($this->permissions()); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Permission, $this> + */ public function permissionsWithPivotAlias(): HasManyDeep { return $this->hasManyDeep(Permission::class, [User::class, RoleUser::class.' as alias', Role::class]); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Permission, $this> + */ public function permissionsWithPivotAliasFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations($this->permissionsWithPivotAlias()); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough<\Tests\Models\Post> + */ public function posts(): HasManyThrough { return $this->hasManyThrough(Post::class, User::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough<\Tests\Models\Post> + */ public function postsWithConstraints(): HasManyThrough { return $this->posts()->where('posts.published', true); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough<\Tests\Models\Post> + */ public function postsWithTrashedParents(): HasManyThrough { return $this->posts()->withTrashedParents(); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Role, $this> + */ public function roles(): HasManyDeep { return $this->hasManyDeep(Role::class, [User::class, 'role_user']); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Models\User> + */ public function usersWithTrashed(): HasMany { return $this->hasMany(User::class)->withTrashed(); diff --git a/tests/Models/Employee.php b/tests/Models/Employee.php index 669a014..9eae5ab 100644 --- a/tests/Models/Employee.php +++ b/tests/Models/Employee.php @@ -13,6 +13,9 @@ class Employee extends Model use Compoships; use HasRelationships; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Project, $this> + */ public function projects(): HasManyDeep { return $this->hasManyDeep( @@ -23,11 +26,17 @@ public function projects(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Project, $this> + */ public function projectsFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations($this->tasks(), (new Task())->project()); } + /** + * @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany<\Tests\Models\Task> + */ public function tasks(): HasMany { return $this->hasMany(Task::class, ['team_id', 'work_stream_id'], ['team_id', 'work_stream_id']); diff --git a/tests/Models/Like.php b/tests/Models/Like.php index 5c5e2c0..1aff805 100644 --- a/tests/Models/Like.php +++ b/tests/Models/Like.php @@ -6,6 +6,9 @@ class Like extends Model { + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Tests\Models\User, self> + */ public function user(): BelongsTo { return $this->belongsTo(User::class); diff --git a/tests/Models/Permission.php b/tests/Models/Permission.php index b8b9bad..0ecbcaf 100644 --- a/tests/Models/Permission.php +++ b/tests/Models/Permission.php @@ -13,6 +13,9 @@ class Permission extends Model { use HasRelationships; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Country, $this> + */ public function countries(): HasManyDeep { return $this->hasManyDeepFromReverse( diff --git a/tests/Models/Post.php b/tests/Models/Post.php index 715a9e9..96cfab1 100644 --- a/tests/Models/Post.php +++ b/tests/Models/Post.php @@ -12,11 +12,17 @@ */ class Post extends Model { + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Models\Comment> + */ public function comments(): HasMany { return $this->hasMany(Comment::class); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentReplies(): HasManyDeep { return $this->hasManyDeep( @@ -26,6 +32,9 @@ public function commentReplies(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentRepliesFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations( @@ -34,16 +43,25 @@ public function commentRepliesFromRelations(): HasManyDeep ); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Models\Comment> + */ public function commentsWithTrashed(): HasMany { return $this->hasMany(Comment::class)->withTrashed(); } + /** + * @return \Illuminate\Database\Eloquent\Relations\MorphMany<\Tests\Models\Like> + */ public function likes(): MorphMany { return $this->morphMany(Like::class, 'likeable'); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function nestedCommentReplies(): HasManyDeep { return $this->hasManyDeep( @@ -53,6 +71,9 @@ public function nestedCommentReplies(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Post, $this> + */ public function posts(): HasManyDeep { return $this->hasManyDeep( @@ -63,11 +84,17 @@ public function posts(): HasManyDeep ); } + /** + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\Tests\Models\Tag> + */ public function tags(): MorphToMany { return $this->morphToMany(Tag::class, 'taggable'); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\User, $this> + */ public function users(): HasManyDeep { return $this->hasManyDeep( @@ -78,6 +105,9 @@ public function users(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\User, $this> + */ public function usersFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations($this->likes(), (new Like())->user()); diff --git a/tests/Models/Project.php b/tests/Models/Project.php index 95a8d52..d9a441c 100644 --- a/tests/Models/Project.php +++ b/tests/Models/Project.php @@ -11,6 +11,9 @@ class Project extends Model { use HasRelationships; + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Employee, $this> + */ public function employees(): HasManyDeep { return $this->hasManyDeep( @@ -21,11 +24,17 @@ public function employees(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Employee, $this> + */ public function employeesFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations($this->tasks(), (new Task())->employee()); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Models\Task> + */ public function tasks(): HasMany { return $this->hasMany(Task::class); diff --git a/tests/Models/Role.php b/tests/Models/Role.php index 34f6cd9..ed99920 100644 --- a/tests/Models/Role.php +++ b/tests/Models/Role.php @@ -6,6 +6,9 @@ class Role extends Model { + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Models\Permission> + */ public function permissions(): HasMany { return $this->hasMany(Permission::class); diff --git a/tests/Models/Tag.php b/tests/Models/Tag.php index be63149..a2bbd81 100644 --- a/tests/Models/Tag.php +++ b/tests/Models/Tag.php @@ -7,6 +7,9 @@ class Tag extends Model { + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function comments(): HasManyDeep { return $this->hasManyDeep( @@ -17,11 +20,17 @@ public function comments(): HasManyDeep ); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Comment, $this> + */ public function commentsFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations($this->posts(), (new Post())->comments()); } + /** + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\Tests\Models\Post> + */ public function posts(): MorphToMany { return $this->morphedByMany(Post::class, 'taggable'); diff --git a/tests/Models/Task.php b/tests/Models/Task.php index 6ea85a7..7dcc282 100644 --- a/tests/Models/Task.php +++ b/tests/Models/Task.php @@ -10,11 +10,17 @@ class Task extends Model { use Compoships; + /** + * @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo<\Tests\Models\Employee, self> + */ public function employee(): ComposhipsBelongsTo { return $this->belongsTo(Employee::class, ['team_id', 'work_stream_id'], ['team_id', 'work_stream_id']); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Tests\Models\Project, self> + */ public function project(): BelongsTo { return $this->belongsTo(Project::class); diff --git a/tests/Models/User.php b/tests/Models/User.php index 41678f6..947a1df 100644 --- a/tests/Models/User.php +++ b/tests/Models/User.php @@ -13,51 +13,81 @@ class User extends Model { use SoftDeletes; + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOneThrough<\Tests\Models\Comment> + */ public function comment(): HasOneThrough { return $this->hasOneThrough(Comment::class, Post::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough<\Tests\Models\Comment> + */ public function comments(): HasManyThrough { return $this->hasManyThrough(Comment::class, Post::class); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Like, $this> + */ public function likes(): HasManyDeep { return $this->hasManyDeep(Like::class, [Post::class], [null, ['likeable_type', 'likeable_id']]); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Permission, $this> + */ public function permissions(): HasManyDeep { return $this->hasManyDeep(Permission::class, ['role_user', Role::class]); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Permission, $this> + */ public function permissionsFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations($this->roles(), (new Role())->permissions()); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\User, $this> + */ public function players(): HasManyDeep { - return $this->hasManyDeep(static::class, [Club::class, Team::class]); + return $this->hasManyDeep(User::class, [Club::class, Team::class]); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Models\Post> + */ public function posts(): HasMany { return $this->hasMany(Post::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\Tests\Models\Role> + */ public function roles(): BelongsToMany { return $this->belongsToMany(Role::class); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Tag, $this> + */ public function tagsFromRelations(): HasManyDeep { return $this->hasManyDeepFromRelations($this->posts(), (new Post())->tags()); } + /** + * @return \Staudenmeir\EloquentHasManyDeep\HasManyDeep<\Tests\Models\Post, $this> + */ public function teamPosts(): HasManyDeep { return $this->hasManyDeep( diff --git a/tests/ReversingTest.php b/tests/ReversingTest.php index 1460838..6b9eb2e 100644 --- a/tests/ReversingTest.php +++ b/tests/ReversingTest.php @@ -8,35 +8,35 @@ class ReversingTest extends TestCase { - public function testHasManyDeep() + public function testHasManyDeep(): void { $tags = Comment::find(31)->tags; $this->assertEquals([91], $tags->pluck('id')->all()); } - public function testHasOneDeep() + public function testHasOneDeep(): void { $country = Comment::find(31)->country; $this->assertEquals(1, $country->id); } - public function testAlias() + public function testAlias(): void { $post = Comment::find(36)->rootPost; $this->assertEquals(24, $post->id); } - public function testPivotAlias() + public function testPivotAlias(): void { $countries = Permission::find(71)->countries; $this->assertEquals([1], $countries->pluck('id')->all()); } - public function testCustomThroughTable() + public function testCustomThroughTable(): void { Schema::rename('users', 'my_users');