Skip to content

Chemaclass/satscribe / .claude/skills/refactor

refactor

Verified

Refactor code safely — establish a green baseline, change in small steps, keep tests passing

Refactor

Refactoring changes structure, never behavior. If behavior must change, that's a feature — use /tdd instead.

Before touching anything

  1. Tests must exist for the code being changed. If they don't, write characterization tests first — capture what the code does today, not what it should do.
  2. Establish a green baseline:
    composer test
    
    Never refactor on red.

Steps

  1. Name the smell before choosing a technique.

    SmellMove
    Long methodExtract method
    Large class (> 200 lines)Extract collaborator
    Long parameter list (> 3)Introduce a Transfer object
    Duplicated logicExtract to a shared method or Domain value object
    Feature envyMove the method to the data's owner
    Primitive obsession (string $txid everywhere)Value object in Domain/Data/
    Growing switch on a typeInterface + implementations, bound in the provider
    new inside business logicInject the interface, bind in the ServiceProvider
    Query in an ActionMove it into the repository
    Comment explaining whatRename until the comment is redundant
  2. One refactoring at a time. Run the narrow test after each:

    vendor/bin/phpunit tests/Unit/<Module>/
    
  3. Watch the layer boundaries while moving code — extracting a class is the moment things drift. Interfaces land in Domain/, policy in Application/, adapters in Infrastructure/. Anything extracted from Domain must stay Laravel-free.

  4. Update the binding if an extraction introduced a new interface.

  5. Full gate + style:

    composer fix
    composer test
    
  6. Commit with ref: — small and atomic, one refactoring per commit.

Constraints

  • Public behavior stays identical — tests must pass unchanged. Editing a test to make a refactor pass means the behavior changed.
  • Do not mix a refactor with a feature or a fix in the same commit.
  • Extracting a class for its own sake is not an improvement — name the smell it removes.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 319kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 319kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 319kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 196kUpdated Claude CodeCodexVerifiedInstall