-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Laravel integration for gksh/bitmask #1
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
Conversation
The package provides: - A `BitmaskCast` for Eloquent models to seamlessly cast integer values to and from `Bitmask` objects. - Eloquent scopes (`HasBitmaskScopes`) for querying bitmask columns with various conditions (has flag, has all flags, has any flag, etc.). - A `make:bitmask-flags` Artisan command to generate bitmask enum classes. - A `ValidBitmask` validation rule to ensure input values conform to bitmask constraints, optionally tied to an enum. - Blade directives for conditional rendering based on bitmask flags. - Custom Blueprint macros for defining bitmask columns in migrations. - Comprehensive unit tests covering all functionalities.
|
@greptile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7 files reviewed, 6 comments
Greptile's behavior is changing!From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
The package provides:
BitmaskCastfor Eloquent models to seamlessly cast integer values to and fromBitmaskobjects.HasBitmaskScopes) for querying bitmask columns with various conditions (has flag, has all flags, has any flag, etc.).make:bitmask-flagsArtisan command to generate bitmask enum classes.ValidBitmaskvalidation rule to ensure input values conform to bitmask constraints, optionally tied to an enum.Greptile Summary
This PR introduces a comprehensive Laravel integration for the
gksh/bitmaskpackage, providing Eloquent casting, query scopes, validation rules, Blade directives, and migration helpers for working with bitmask flags. The implementation is well-structured with proper type safety, comprehensive test coverage across all features, and good documentation.Key Changes:
BitmaskCast): Converts database integers to/from Bitmask objects with configurable sizes (tiny/small/medium/default)HasBitmaskScopes): Five scope methods for filtering models by bitmask flags using bitwise SQL operationsValidBitmask): Rule for validating bitmask values with optional enum-based maximum value checkingmake:bitmask-flagsfor interactive enum generation andbitmask:inspectfor debugging bitmask values@hasBitmaskFlag,@hasAnyBitmaskFlag, and@hasAllBitmaskFlagsfor conditional renderingPrevious Issues Addressed:
laravel/promptsdependency correctly moved fromrequire-devtorequireincomposer.jsonRemaining Concern:
HasBitmaskScopes.phppreviously flagged but not yet resolved - column names are interpolated directly into raw SQL without sanitization, though this is mitigated by typical usage patterns where column names are hardcodedConfidence Score: 4/5
src/Concerns/HasBitmaskScopes.phpshould be reviewed for the SQL injection concern with column name interpolation inwhereRaw()calls.Important Files Changed
Sequence Diagram
sequenceDiagram participant User participant Model participant BitmaskCast participant Bitmask participant HasBitmaskScopes participant Database Note over User,Database: Setting Bitmask Flags User->>Model: permissions = bitmask.set(Permission::Read) Model->>BitmaskCast: set(Bitmask) BitmaskCast->>BitmaskCast: Extract integer value BitmaskCast-->>Model: Returns int Model->>Database: Store integer value Note over User,Database: Retrieving Bitmask Flags User->>Model: Get user->permissions Model->>Database: Fetch integer value Database-->>Model: Returns int Model->>BitmaskCast: get(int value) BitmaskCast->>Bitmask: Create Bitmask instance Bitmask-->>BitmaskCast: Returns Bitmask BitmaskCast-->>Model: Returns Bitmask Model-->>User: Returns Bitmask object Note over User,Database: Querying with Scopes User->>Model: whereHasBitmaskFlag('permissions', Permission::Admin) Model->>HasBitmaskScopes: Apply scope HasBitmaskScopes->>Database: WHERE permissions & ? = ? Database-->>HasBitmaskScopes: Filtered results HasBitmaskScopes-->>Model: Query builder Model-->>User: Collection of models