-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add make command #40
Add make command #40
Conversation
ADD LaravelBackedEnumMakeCommand.php MOD LaravelBackedEnumsServiceProvider.php to register make command
Update README.md
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughSweet as! This pull request is all about making it easier for devs to create and manage backed enums in Laravel. We've added a new Artisan command Changes
Sequence DiagramsequenceDiagram
participant Dev as Developer
participant CLI as Artisan CLI
participant Generator as EnumMakeCommand
participant Stub as Enum Stub Template
Dev->>CLI: php artisan make:laravel-backed-enum VolumeUnitEnum
CLI->>Generator: Invoke command
Generator->>Generator: Validate/Process Arguments
Generator->>Stub: Load Stub Template
Generator-->>Dev: Generate Enum File
Crikey, this diagram shows how a dev can now create an enum faster than a possum crossing the road! Just run the command, and Bob's your uncle - you've got a shiny new enum ready to go. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/LaravelBackedEnumMakeCommand.php (2)
55-58
: Reckon we could make this match expression more robust.The match expression could handle more edge cases, like when someone chucks in unexpected values.
- match (strtolower($this->argument('enumType'))) { - 'int' => 'int', - default => 'string', - }, + match (strtolower($this->argument('enumType'))) { + 'int', 'integer' => 'int', + 'str', 'string' => 'string', + default => throw new \InvalidArgumentException('Enum type must be either "int" or "string"'), + },
66-70
: Choice idea with the name handling, but could be more bulletproof.The name handling is sweet as, but we should probably validate the name format before adding 'Enum' suffix.
- $name = trim($this->argument('name') . 'Enum'); + $name = trim($this->argument('name')); + if (!preg_match('/^[A-Za-z_\x7f-\xff][A-Za-z0-9_\x7f-\xff]*$/', $name)) { + throw new \InvalidArgumentException('Invalid enum name format'); + } + $name = $name . 'Enum';README.md (1)
18-29
: Mean as documentation, but could use a bit more detail.The command docs are sweet as, but reckon we could add a section about customizing the stub template? Would be choice for teams wanting to add their own bits and bobs to the generated enums.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
README.md
(3 hunks)src/LaravelBackedEnumMakeCommand.php
(1 hunks)src/LaravelBackedEnumsServiceProvider.php
(1 hunks)src/stubs/laravel-backed-enum.stub
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/stubs/laravel-backed-enum.stub
🔇 Additional comments (4)
src/LaravelBackedEnumsServiceProvider.php (1)
21-23
: Choice as, mate! The command registration looks mint.The command registration is properly implemented using Spatie's package tools. Ka pai!
src/LaravelBackedEnumMakeCommand.php (2)
13-17
: Sweet as! The command setup looks good.The command signature and description are clear as. The type is properly set for the generator.
24-29
: Chur! But let's make the stub path handling more robust.The stub path resolution could use a bit more error handling, eh? What if the file doesn't exist at either location?
README.md (1)
364-380
: Choice JSON example formatting!The JSON example is properly formatted and easy to read. Ka pai!
Tests are also failing. |
Fix command. Fix PR comments
# Conflicts: # .github/workflows/run-tests.yml
@Jim-Webfox you need to tell the test setup to actually install the listed version of Laravel. |
# Conflicts: # .github/workflows/phpstan.yml
Adds convenient way to create new Enums
Summary by CodeRabbit
Release Notes
New Features
make:laravel-backed-enum
for creating Laravel backed enumsDocumentation
Improvements
The update provides developers with a more intuitive way to create and manage backed enums in Laravel applications.