Skip to content

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

Merged
taylorotwell merged 2 commits intolaravel:11.xfrom
Aluisio-Pires:fix/aluisio/policies-stub
Nov 25, 2024
Merged

[11.x] Fix: Ensure generated policies return boolean values#53632
taylorotwell merged 2 commits intolaravel:11.xfrom
Aluisio-Pires:fix/aluisio/policies-stub

Conversation

@Aluisio-Pires
Copy link
Contributor

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

  • Updated the policy stub to include default false return values for all methods:
    • viewAny
    • view
    • create
    • update
    • delete
    • restore
    • forceDelete

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 false 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!

@taylorotwell taylorotwell merged commit 77f104d into laravel:11.x Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants