lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.52k stars 124 forks source link

PHP Stan support #260

Open sandeshjangam opened 1 year ago

sandeshjangam commented 1 year ago

It doesn't throw errors in PHPStan if args type, numbers etc. mismatches...

namespace App\Authentication\Actions;

use Lorisleiva\Actions\Concerns\AsAction;

class UpdateUserPassword
{
    use AsAction;

    public function handle(User $user, string $newPassword)
    {
        $user->password = Hash::make($newPassword);
        $user->save();
    }
}
// Equivalent to "UpdateUserPassword::make()->handle($user, 'secret')".
UpdateUserPassword::run($user, 'secret');

If I use this - UpdateUserPassword::make()->handle($user, 'secret') Larstan properly check args type, count etc

For this - UpdateUserPassword::run($user, 'secret') Larstand doesn't trigger any error

How can I add support to this? I am open to creating a PR. A little head start will be good...

sandeshjangam commented 1 year ago

@lorisleiva I am open to creating a PR. A little head start will be good...

Wulfheart commented 1 year ago

I don’t think that this can be achieved in this package due to the dynamic nature of the package.

Did you try the ide-helper package yet?

sandeshjangam commented 1 year ago

I don’t think that this can be achieved in this package due to the dynamic nature of the package.

Did you try the ide-helper package yet?

Nope, I haven't yet. I am not sure how the ide-helper package will help to get it compatible with Larstan(PHPStan)?

Can you please elaborate?

Patabugen commented 1 year ago

@sandeshjangam The ide-helper package generates docblocks (or other files/annotations) based on your actual code which phpStan can use to understand your code better.

For example, it might add a docblock bit which can tell phpStan the arguments for UpdateUserPassword::run()

There's an extension for ide-helper just for laravel-actions which might help:

https://github.com/Wulfheart/laravel-actions-ide-helper

kylemilloy commented 3 months ago

I think this is possible with generics, yes? Would really like to have this since everything getting set to "mixed" isn't terribly helpful.

Wulfheart commented 1 month ago

This topic definitely needs more love.