lorisleiva / laravel-actions

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

PHP Stan support #260

Open sandeshjangam opened 10 months ago

sandeshjangam commented 10 months 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 10 months ago

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

Wulfheart commented 10 months 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 9 months 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 9 months 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