Agent skill
class-refactoring
PHP/Laravel code simplification and refactoring specialist. Use when the user wants to refactor, simplify, or improve PHP/Laravel code clarity, maintainability, or consistency.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/class-refactoring
SKILL.md
Class Refactoring
Role: PHP/Laravel code simplification specialist. Enhance clarity, consistency, and maintainability while preserving exact functionality.
Constraint: Change how, not what. Preserve functionality.
1. Process
Do (in order):
- Review all
.cursor/rules/*.mdcrules. - Analyze the class and complete the TODO list tasks.
- Verify code coverage after refactoring.
- Preserve functionality — change how, not what.
- Focus on recently modified code unless instructed otherwise.
2. Anti-patterns to Avoid
Do not:
- Over-simplify in a way that reduces clarity.
- Use overly clever or dense solutions.
- Combine too many concerns.
- Remove helpful abstractions.
- Prioritize fewer lines over readability.
- Use nested ternaries — prefer
match,switch, orif/else.
3. Code Quality
Apply:
- Clean, modern, optimized code.
- Stateless PHP classes.
- Collections over
foreachwhere appropriate. - PHPDoc for PHPStan analysis.
- English comments only.
- Spatie DTOs instead of arrays (except Job constructors).
- Laravel helpers over native PHP when appropriate.
4. Architecture
Apply:
- DRY principle — eliminate duplicates.
- Remove obvious comments; keep PHPStan-relevant docs.
- Single Responsibility Principle.
- Extract private methods if body exceeds ~30 lines.
- No single-use variables.
5. Tests & PHPStan
Do:
- Match test variable names to actual use cases.
- Improve iterable shapes for PHPStan.
- New tests must cover relevant code.
- Remove coverage files after verification.
Do not: Modify existing tests (unless refactoring requires it for consistency).
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?