Analyzes PHP code for smells, SOLID violations, testability issues, readability problems, and provides prioritized refactoring roadmap with generation commands.
From accnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin acc<path> [-- additional instructions]opusPerform comprehensive code analysis and guide through safe, incremental refactoring with pattern application.
Parse $ARGUMENTS to extract path and optional meta-instructions:
Format: <path> [-- <meta-instructions>]
Examples:
- /acc:refactor ./src/Domain/OrderService.php
- /acc:refactor ./src/Application -- focus on SOLID violations
- /acc:refactor ./src -- extract value objects only
- /acc:refactor ./src/Service -- analyze testability, skip style
Parsing rules:
$ARGUMENTS by -- (space-dash-dash-space)$ARGUMENTS (before --)--) — customize refactoring focusIf meta-instructions provided, adjust analysis to:
Verify the path exists:
$ARGUMENTS is empty, ask user for the target pathVerify it's a PHP project:
*.php filesCheck Git status:
Use the acc:refactor-coordinator agent to perform guided refactoring:
Task tool with subagent_type="acc:refactor-coordinator"
prompt: "Perform refactoring analysis on [PATH]. [META-INSTRUCTIONS if provided]
Analysis scope:
1. CODE SMELLS — God Class, Long Method, Primitive Obsession, Feature Envy, Data Clump
2. SOLID VIOLATIONS — SRP, OCP, LSP, ISP, DIP
3. READABILITY — Naming, complexity, nesting, magic values
4. TESTABILITY — DI issues, side effects, coverage gaps
Provide:
- Prioritized issue list (Critical/High/Medium)
- Refactoring techniques for each issue
- Generator commands for automated fixes
- Safety warnings and prerequisites
- Interactive prompts for execution"
| Smell | Detection | Refactoring |
|---|---|---|
| God Class | >300 lines, >10 methods | Extract Class |
| Long Method | >30 lines | Extract Method |
| Primitive Obsession | String email, int price | Value Object |
| Feature Envy | Chain calls to other objects | Move Method |
| Data Clump | Same params in multiple methods | DTO/VO |
| Long Parameter List | >4 parameters | Builder/DTO |
| Duplicate Code | Similar code blocks | Extract Method |
| Dead Code | Unused methods/classes | Delete |
| Principle | Violation | Fix | Generator |
|---|---|---|---|
| SRP | Multiple responsibilities | Extract classes | acc:ddd-generator, acc:cqrs-generator |
| OCP | Type switches, if/else chains | Strategy pattern | /acc:generate-patterns strategy |
| LSP | Exceptions in overrides | Redesign hierarchy | Manual |
| ISP | Unused interface methods | Split interface | Manual |
| DIP | new in constructors | DI, Factories | acc:create-factory |
| Issue | Detection | Fix |
|---|---|---|
| Hard coupling | new in business logic | Inject dependencies |
| Static calls | SomeClass::method() | Inject instance |
| Global state | $_SESSION, $_GET | Request object |
| Side effects | File I/O, HTTP in logic | Infrastructure layer |
| No interfaces | Concrete dependencies | Extract interface |
Refactoring Analysis: src/Application/Service/OrderService.php
| Category | Issues | Critical | High | Medium |
|----------|--------|----------|------|--------|
| Code Smells | 8 | 2 | 4 | 2 |
| SOLID | 5 | 1 | 3 | 1 |
| Testability | 4 | 2 | 2 | 0 |
| Readability | 6 | 0 | 2 | 4 |
Overall Score: 45/100 (Needs Significant Refactoring)
For each critical issue:
### God Class: OrderService
**Location:** `src/Application/Service/OrderService.php`
**Metrics:**
- Lines: 523 (target: <300)
- Methods: 28 (target: <10)
- Dependencies: 12 (target: <5)
**Responsibilities Found:**
1. Order processing
2. Payment handling
3. Email notifications
4. Inventory updates
5. Logging
**Refactoring Plan:**
1. Extract `PaymentProcessor` (methods: processPayment, refundPayment)
2. Extract `OrderNotifier` (methods: sendConfirmation, sendShipment)
3. Extract `InventoryUpdater` (methods: reserveStock, releaseStock)
4. Keep `OrderService` as orchestrator
**Generator Commands:**
```bash
acc:create-domain-service PaymentProcessor
acc:create-domain-service OrderNotifier
/acc:generate-patterns mediator OrderWorkflow
Prerequisites:
### 3. Refactoring Roadmap
| Priority | Issue | File | Refactoring | Command |
|----------|-------|------|-------------|---------|
| P1 | God Class | OrderService.php | Extract classes | `acc:create-domain-service` |
| P1 | No DI | PaymentHandler.php | Add constructor DI | Manual |
| P2 | Primitive | User.php | Value Object | `acc:create-value-object Email` |
| P2 | Type Switch | DiscountHandler.php | Strategy | `/acc:generate-patterns strategy` |
| P3 | Magic values | Config.php | Constants | Manual |
| P3 | Long method | ReportGenerator.php | Extract method | Manual |
### 4. Quick Wins
Safe refactorings that can be applied immediately:
```markdown
1. **Rename variable** `$d` → `$orderDate` at OrderService.php:123
2. **Extract constant** `3` → `MAX_RETRY_COUNT` at ApiClient.php:45
3. **Add return type** `process(): Order` at OrderProcessor.php:78
4. **Remove dead code** `unusedMethod()` at Helper.php:200
⚠️ Before refactoring, add tests:
| File | Current | Required | Gap |
|------|---------|----------|-----|
| OrderService.php | 45% | 90% | 45% |
| PaymentHandler.php | 72% | 90% | 18% |
Run: /acc:generate-test ./src/Application/Service/OrderService.php
# Value Objects
acc:create-value-object EmailAddress
acc:create-value-object Money
acc:create-value-object OrderId
# Domain Services
acc:create-domain-service PaymentProcessor
acc:create-domain-service OrderNotifier
# Patterns
/acc:generate-patterns strategy DiscountCalculator
/acc:generate-patterns builder UserProfile
# Tests (run first!)
/acc:generate-test ./src/Application/Service/OrderService.php
/acc:refactor ./src/Domain/Order
Analyzes and provides recommendations without applying changes.
/acc:refactor ./src -- focus on SOLID violations
/acc:refactor ./src -- extract value objects only
/acc:refactor ./src -- analyze testability
/acc:refactor ./src -- apply quick wins only
Shows only safe, low-risk refactorings.
/acc:refactor ./src/Service/PaymentHandler.php -- apply Strategy pattern
Analyzes and generates recommended pattern.
# Full analysis of a file
/acc:refactor ./src/Domain/OrderService.php
# Directory analysis with focus
/acc:refactor ./src/Application -- focus on SOLID violations
# Quick wins only
/acc:refactor ./src -- quick wins only
# Specific pattern extraction
/acc:refactor ./src/Service/Payment -- extract Strategy pattern
# Testability focus
/acc:refactor ./src -- analyze testability, generate test suggestions
/refactorOrchestrates refactoring for specified scope: assesses architecture and issues, plans incremental transformations with risk mitigation, provides code change guides with examples, validation tests, and monitoring plan.
/refactorPerforms safe incremental refactoring on code, scores SOLID principles compliance (0-100 total), detects smells via grep/bash, visualizes technical debt, and prioritizes fixes with examples.
/refactorPerforms safe incremental refactoring on identified code issues; scores SOLID compliance (0-100 per principle); visualizes technical debt and prioritizes fixes.