Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 25, 2024

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
38 checks passed
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