refactor-laravel_skill

This skill refactors Laravel PHP code to improve maintainability and aligns with modern PHP 8.3+/8.4+ and Laravel 11+ patterns.

6

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill snakeo/claude-debug-and-refactor-skills-plugin --skill refactor-laravel

  • SKILL.md23.0 KB

Overview

This skill refactors PHP/Laravel code to improve maintainability, readability, and alignment with modern PHP 8.3+/8.4+ and Laravel 11+ practices. It converts legacy patterns into Actions, services, typed DTOs, and concise controllers while enforcing SOLID principles. The result is predictable, testable, and easier-to-evolve code.

How this skill works

I inspect controllers, models, form requests, services, and tests to find fat controllers, duplicated logic, missing type declarations, N+1 query risks, and legacy PHP constructs. Changes include extracting single-purpose Actions or Services, introducing typed constants, property hooks, virtual properties, readonly DTOs, and using Laravel features like scoped queries, eager loading, and FormRequest-to-DTO conversions. I also recommend and implement pest-style tests and event-based side effects where appropriate.

When to use it

  • When controllers contain business logic or long methods
  • When you see repeated code across controllers or models
  • If there are missing type hints, untyped constants, or legacy getters/setters
  • When eager loading is absent and N+1 queries might occur
  • Before adding new features to fragile, hard-to-test code

Best practices

  • Make controllers thin: delegate validation to FormRequests and logic to Actions/Services
  • Apply SRP: split methods over 20–25 lines into focused helpers
  • Use typed class constants, readonly DTOs, and property hooks where supported
  • Move side effects to events/listeners and use Actions for orchestration
  • Prefer query scopes and eager loading to avoid N+1; use collection helpers over manual loops

Example use cases

  • Refactor a payments controller that validates, charges, updates inventory, and emails — split into StorePaymentRequest, ChargePaymentAction, and event listeners
  • Convert duplicated query logic across controllers into an OrderRepository or Eloquent scopes with eager loading
  • Migrate legacy getters/setters to property hooks and readonly value objects for immutability
  • Introduce typed enums and casts for status fields and replace stringly-typed constants
  • Replace long controller methods with single-action controllers and injected Actions for clearer routing and testing

FAQ

No — the goal is behavior-preserving refactors. I keep public APIs stable and add tests or update existing ones to assert unchanged behavior.

Do you upgrade PHP/Laravel versions as part of refactor?

I target modern PHP/Laravel features available in your runtime. If your app can be upgraded safely, I outline the minimal version bump required and the benefits.

How do you prevent regressions?

I add or update automated tests (Pest/PHPUnit), use small commits per concern, and run static analysis and type checks to catch issues early.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
refactor-laravel skill by snakeo/claude-debug-and-refactor-skills-plugin | VeilStrat