class-refactoring

Refactor PHP/Laravel code with behavior-preserving changes and PHPDoc enhancements.

5|Updated Aug 22, 2025
One-click install
npx skills add https://github.com/pekral/cursor-rules --skill class-refactoring
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: class-refactoring
Source: https://github.com/pekral/cursor-rules/tree/main/skills/class-refactoring
Command: npx skills add https://github.com/pekral/cursor-rules --skill class-refactoring

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

PHP/Laravel projects often accumulate complexity and duplication, making maintenance and onboarding painful. This Skill enables safe, behavior-preserving refactoring to improve readability, consistency, and maintainability without altering external functionality.

Core Features & Use Cases

  • Analyze and identify refactoring opportunities across controllers, models, services, and tests to enforce SRP and DRY.
  • Apply clean, PHPDoc-enhanced changes and typed properties to improve static analysis and maintainability.
  • Ensure tests remain green and functionality preserved after refactoring, with clear documentation of changes for teammates.

Quick Start

To start refactoring, point the Skill at your PHP/Laravel project and instruct it to review the codebase for simplification and clarity.

Frequently Asked Questions about class-refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor PHP code to enforce SRP and DRY without breaking functionality?

To refactor PHP code safely, apply behavior-preserving changes that enforce SRP and DRY principles while validating all modifications against your project's existing test suite. This ensures readability and maintainability improve without altering external functionality.

What's the best way to reduce code duplication in Laravel controllers and services?

Reducing code duplication in Laravel controllers and services involves analyzing the codebase to identify refactoring opportunities and applying DRY principles. This process improves maintainability and consistency while ensuring tests remain green and functionality is preserved.

Can I improve PHPDoc and type hints in my Laravel project during refactoring?

Yes, you can improve PHPDoc and type hints during refactoring by applying clean, PHPDoc-enhanced changes and typed properties. This improves static analysis and maintainability across controllers, models, services, and tests without changing functionality.

Does behavior-preserving refactoring work with existing Laravel test suites?

Behavior-preserving refactoring relies on your existing Laravel test suite to validate that changes do not alter external functionality. It enforces tests remain green throughout the refactoring process, ensuring safe improvements to readability and consistency.

How to identify refactoring opportunities across PHP models and tests?

Identifying refactoring opportunities across PHP models and tests requires analyzing the codebase for simplification and clarity. The process guides developers through behavior-preserving changes that enforce SRP and DRY while improving documentation and type consistency.

Why does refactoring PHP code require validating against the project test suite?

Validating refactoring against the project test suite is required because behavior-preserving changes must not alter external functionality. Running tests ensures that improvements to readability, maintainability, and consistency remain safe and do not introduce regressions.