TomasVotruba / laratyped

Bunch of PHPStan rules to make sure the Laravel project is clean, typed and reliable
3 stars 0 forks source link

Add PHPStan rule to call repository methods only in *Repository class #1

Open TomasVotruba opened 1 year ago

TomasVotruba commented 1 year ago

No :no_entry_sign:

class SomeController
{
    public function __invoke()
    {
         $user = User::get(...);
    }
}

Yes :heavy_check_mark:

class SomeController
{
     public function __construct(
          private readonly UserRepository $userRepository
     ) {
     }

    public function __invoke()
     {
         $user = $this->userRepository->get(...);
     }
}
class UserRepository
{
     public function get(int $id): User
     {
          return User::get($id);
     }     
}
szepeviktor commented 1 year ago

Maybe you are interested in/want to cooperate with https://github.com/smortexa/laravel-arkitect There are many Laravel design rules there.

TomasVotruba commented 1 year ago

Thanks for the link! I've checked it and it seems this can be easily done with PHPStan. As Ocamms' razor says: less tools for the same job is better :)