.claude/skills/refactor/SKILL.md
Elite Laravel and Livewire refactoring skill for 2024-2025, covering modern tooling (Laravel Pint, PHPStan/Larastan, Pest, Rector), automated quality gates, CI/CD practices, static analysis adoption, and comprehensive code refactoring. Use for modernizing legacy code, setting up quality toolchains, eliminating anti-patterns, optimizing performance, implementing automated testing, configuring CI/CD pipelines, or upgrading to Laravel 11 patterns. Handles fat controllers, N+1 queries, security issues, Livewire optimization, static analysis setup, mutation testing, and architecture tests.
npx skillsauth add vlados/lawdiff laravel-refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Expert guidance for refactoring Laravel and Livewire applications to modern best practices, eliminating anti-patterns, and improving code quality.
Use this skill when the user:
The Laravel ecosystem has matured around a standardized quality toolchain:
Laravel Pint - Official code formatter (ships with Laravel)
./vendor/bin/pint to format, ./vendor/bin/pint --test for CI validationPHPStan + Larastan - Static analysis standard
./vendor/bin/phpstan analyse --generate-baselinePest - Modern testing framework with mutation testing
arch() helperRector - Automated refactoring via AST transformations
Setting up new projects: Configure Pint + PHPStan level 5 + Pest + architecture tests from day one
Modernizing legacy projects: See references/modern_tooling.md for comprehensive setup guide including:
Quick tooling decisions:
For detailed tooling setup, configuration examples, and production-proven CI/CD patterns, consult references/modern_tooling.md.
User provides Laravel/Livewire code to refactor
│
├─→ Is this a quick fix or specific pattern?
│ ├─→ YES: Identify the pattern in references/laravel_patterns.md or references/livewire_patterns.md
│ └─→ NO: Continue to comprehensive analysis
│
├─→ Is this a full codebase or directory?
│ ├─→ YES: Run scripts/analyze_code.py to identify all issues
│ └─→ NO: Manual analysis
│
├─→ What type of refactoring is needed?
│ ├─→ Controllers: Extract to Actions/Services, Form Requests
│ ├─→ Database: Fix N+1, add eager loading, optimize queries
│ ├─→ Livewire: Component optimization, Forms, computed properties
│ ├─→ Architecture: Repository pattern, service layer
│ ├─→ Security: Mass assignment, validation, authorization
│ └─→ General: Type hints, code organization, modern patterns
│
└─→ Apply refactoring patterns and provide refactored code
When: Controller methods > 20 lines, complex business logic
// BEFORE: Fat controller
public function store(Request $request)
{
$validated = $request->validate([...]);
$user = User::create($validated);
Mail::to($user)->send(new WelcomeEmail($user));
event(new UserRegistered($user));
return redirect()->route('dashboard');
}
// AFTER: Thin controller with action
public function store(StoreUserRequest $request, RegisterUserAction $action)
{
$user = $action->execute($request->validated());
return redirect()->route('dashboard');
}
When: Accessing relationships in loops, slow query counts
// BEFORE: N+1 problem
$posts = Post::all();
foreach ($posts as $post) {
echo $post->user->name; // Query per post!
}
// AFTER: Eager loading
$posts = Post::with('user')->get();
foreach ($posts as $post) {
echo $post->user->name; // Uses preloaded data
}
When: Validation rules > 5 fields, repeated validation
// BEFORE: Inline validation
public function store(Request $request)
{
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users',
// 10+ more fields...
]);
}
// AFTER: Form Request class
public function store(StoreUserRequest $request)
{
$validated = $request->validated();
}
When: Direct model binding in Livewire components
// BEFORE: Security risk
class EditUser extends Component
{
public User $user; // Exposes entire model!
}
// AFTER: Specific properties
class EditUser extends Component
{
public string $name;
public string $email;
private User $user;
public function mount(User $user)
{
$this->user = $user;
$this->name = $user->name;
$this->email = $user->email;
}
}
For specific code snippets:
For full directories/codebases:
python3 scripts/analyze_code.py <directory>Group identified issues by type:
Follow this priority order:
Security issues (HIGH priority)
Performance issues (HIGH priority)
Architecture improvements (MEDIUM priority)
Code quality (MEDIUM/LOW priority)
Consult the detailed reference files for specific patterns:
Laravel patterns: See references/laravel_patterns.md for:
Livewire patterns: See references/livewire_patterns.md for:
Comprehensive checklist: See references/refactoring_checklist.md for:
After refactoring:
Use the code analyzer for comprehensive analysis:
# Analyze controllers
python3 scripts/analyze_code.py app/Http/Controllers
# Analyze Livewire components
python3 scripts/analyze_code.py app/Http/Livewire
# Analyze entire app directory
python3 scripts/analyze_code.py app
# Generate JSON report
python3 scripts/analyze_code.py app --json
The analyzer detects:
DO:
DON'T:
This skill includes comprehensive reference documentation:
The analyzer script provides automated detection of common issues across your codebase.
development
Elite SEO expertise covering technical optimization, Core Web Vitals, E-E-A-T, topic clusters, entity-based SEO, semantic search, advanced link building, AI/ML integration, and sustainable ranking strategies for 2025. Use for comprehensive SEO audits, strategy development, content optimization, and technical implementation.
testing
Elite B2C sales strategies focused on consumer psychology, behavioral economics, e-commerce conversion optimization, DTC brand tactics, subscription model optimization, and high-ticket consumer sales. Covers digital commerce, retail psychology, consultative selling, objection handling, and revenue optimization for consumer-facing businesses.
development
Elite marketing strategy combining Brian Balfour's growth loops, Jobs-to-be-Done framework, Blue Ocean Strategy, attribution modeling, product-led growth, and community-driven tactics. Use for comprehensive marketing strategy, channel selection, growth experimentation, attribution analysis, and sustainable competitive advantages.
development
Elite copywriting skill combining legendary frameworks from Eugene Schwartz, Gary Halbert, and modern conversion experts. Use for persuasive copy across all formats - sales letters, landing pages, emails, ads, VSLs. Specializes in audience awareness matching, psychological persuasion, conversion optimization, and AI-augmented workflows.