laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.66k stars 11.04k forks source link

[11.x] Fix: Ensure generated policies return boolean values #53630

Closed Aluisio-Pires closed 3 days ago

Aluisio-Pires commented 3 days ago

Summary

This PR resolves an issue where the methods in policies generated via commands such as make:model ModelName --policy returned a bool type but lacked implementations, causing PhpStan to report type errors. The problem stems from the empty method bodies in the default policy stubs.

Changes Made

This ensures the generated methods comply with their defined return types and eliminates PhpStan type-checking errors.

How to Test

  1. Generate a new model with a policy using php artisan make:model Example --policy.
  2. Inspect the generated policy methods for default true return values.
  3. Confirm that running static analysis (e.g., PhpStan) no longer raises type errors for the generated policy.

Impact

This change improves developer experience by making generated policies immediately usable without requiring manual fixes to satisfy static analysis.

Let me know if further details are needed!

Jubeki commented 3 days ago

This would be a security issue. If this were to be changed, it should be deny by default.

taylorotwell commented 3 days ago

See above.

Aluisio-Pires commented 3 days ago

This would be a security issue. If this were to be changed, it should be deny by default.

Really good point. I was avoiding the same FormRequests behavior were we are forced to change the authorize return, but I see the issue. I will reopen de PR changing to false.

Aluisio-Pires commented 3 days ago

See above.

@taylorotwell I've created a new PR following the recommendations.