Skip to content

Commit

Permalink
Fix typing for factory
Browse files Browse the repository at this point in the history
Since repositories extend a base class, they can have method
that are not in this base class.

The issue with using `Repository<T>` as the return type is
that PHPStan cannot see those methods.

For example: https://phpstan.org/r/65389bf5-b00d-4e5d-b993-8c6f274b7545

With this change, PHPStan understands the correct class while still
forcing classes to extend `Repository`.

For example: https://phpstan.org/r/d40317b1-1834-407b-9284-ca1e7b0d3325
  • Loading branch information
Mopolo committed Jan 9, 2025
1 parent 2e99f2b commit 2525679
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Ting/Repository/RepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ public function __construct(
}

/**
* @param class-string<Repository<T>> $repositoryName
* @return Repository<T>
* @param class-string<R> $repositoryName
* @return R
* @template T of object
* @template R of Repository<T>
*/
public function get($repositoryName)
{
Expand Down

0 comments on commit 2525679

Please sign in to comment.