| name | acc-detect-code-smells |
| description | Detects code smells in PHP codebases. Identifies God Class, Feature Envy, Data Clumps, Long Parameter List, Long Method, Primitive Obsession, Message Chains, Inappropriate Intimacy. Generates actionable reports with refactoring recommendations. |
Code Smells Detector
Overview
This skill analyzes PHP codebases for code smells (symptoms of deeper problems) and generates detailed reports with severity levels and refactoring recommendations.
Code Smells Catalog
| Smell | Description | Detection | Severity |
|---|
| God Class | Class doing too much | >500 LOC, >15 methods | CRITICAL |
| Feature Envy | Method uses another class more | Foreign calls > own calls | WARNING |
| Data Clumps | Same fields appear together | 3+ repeated params/fields | WARNING |
| Long Parameter List | Method with many params | >4 parameters | WARNING |
| Long Method | Method doing too much | >50 LOC | WARNING |
| Primitive Obsession | Primitives instead of objects | string $email, int $money | INFO |
| Message Chains | Long getter chains | ->get()->get()->get() | WARNING |
| Inappropriate Intimacy | Classes knowing too much | Direct field access | WARNING |
Detection Patterns
God Class Detection
Grep: "^class " --glob "**/*.php"
Grep: "public function " --glob "**/*.php"
Grep: "__construct" --glob "**/*.php" -A 20
Grep: "class.*Manager|class.*Handler|class.*Helper|class.*Util|class.*Processor" --glob "**/*.php"
Indicators:
- Class > 500 lines → CRITICAL
- Class > 15 public methods → CRITICAL
- Class > 8 constructor dependencies → WARNING
- Class name contains Manager, Handler, Helper, Util → INFO
Feature Envy Detection
Grep: "\$this->[a-z]+->get[A-Z]" --glob "**/*.php"
Grep: "\$[a-z]+->.*\$[a-z]+->" --glob "**/*.php"
Grep: "function [a-z]+\(" --glob "**/*.php" -A 30
Indicators:
- Method calls other object's methods > own methods → WARNING
- Multiple chained calls to foreign object → INFO
- Method only transforms data from another class → WARNING
Data Clumps Detection
Grep: "__construct\(" --glob "**/*.php" -A 10
Grep: "function [a-z]+\(" --glob "**/*.php"
Grep: "(private|readonly) (string|int|float)" --glob "**/*.php"
Common Data Clumps:
$street, $city, $zipCode, $country → Address Value Object
$startDate, $endDate → DateRange Value Object
$amount, $currency → Money Value Object
$firstName, $lastName, $email → Contact/Person Value Object
Long Parameter List Detection
Grep: "function [a-z]+\(" --glob "**/*.php"
Grep: "__construct\(" --glob "**/*.php" -A 15
Thresholds:
- 4+ parameters → INFO
- 6+ parameters → WARNING
- 8+ parameters → CRITICAL
Long Method Detection
Grep: "function [a-z]+\(" --glob "**/*.php" -A 60
Grep: "if\s*\(.*\{.*if\s*\(" --glob "**/*.php" --multiline
Thresholds:
- 30+ lines → INFO
- 50+ lines → WARNING
- 100+ lines → CRITICAL
Primitive Obsession Detection
Grep: "string \$email|string \$phone|string \$url|string \$currency|string \$country" --glob "**/*.php"
Grep: "int \$amount|int \$price|int \$total|int \$money|int \$cents" --glob "**/*.php"
Grep: "float \$amount|float \$price|float \$money" --glob "**/*.php"
Grep: "string \$status|string \$type|string \$state" --glob "**/*.php"
Grep: "=== 'pending'|=== 'active'|=== 'completed'|=== 'draft'" --glob "**/*.php"
Should be Value Objects:
- Email addresses → Email
- Phone numbers → PhoneNumber
- URLs → Url or Uri
- Money amounts → Money (with currency)
- Dates/periods → DateRange, Period
- Identifiers → UserId, OrderId, etc.
- Status/Type → Enum
Message Chains Detection
Grep: "->get[A-Z][a-z]+\(\)->get[A-Z][a-z]+\(\)" --glob "**/*.php"
Grep: "->.*->.*->" --glob "**/*.php"
Grep: "\$this->[a-z]+->get[A-Z].*->get[A-Z]" --glob "**/*.php"
Indicators:
- 2 chained getters → INFO
- 3+ chained getters → WARNING
- Chains in loops → CRITICAL
Inappropriate Intimacy Detection
Grep: "\$[a-z]+->(?!get|set|is|has|can)[a-z]+" --glob "**/*.php"
Grep: "ReflectionClass|ReflectionProperty|setAccessible" --glob "**/*.php"
Grep: "->getInternalState|->getRawData|->getFields" --glob "**/*.php"
Report Format
# Code Smells Analysis Report
## Summary
| Smell | Critical | Warning | Info |
|-------|----------|---------|------|
| God Class | X | X | - |
| Feature Envy | - | X | X |
| Data Clumps | - | X | - |
| Long Parameter List | X | X | X |
| Long Method | - | X | X |
| Primitive Obsession | - | X | X |
| Message Chains | - | X | X |
| Inappropriate Intimacy | - | X | - |
**Total Issues:** X critical, X warnings, X info
## Critical Issues
### SMELL-001: God Class
- **File:** `src/Service/OrderManager.php`
- **Lines:** 847
- **Public Methods:** 23
- **Dependencies:** 12
- **Issue:** Class has too many responsibilities
- **Refactoring:**
- Extract `OrderValidator` (validation logic)
- Extract `OrderNotifier` (notification logic)
- Extract `OrderPriceCalculator` (pricing logic)
- **Skills:** `acc-create-use-case`, `acc-create-domain-service`
### SMELL-002: Long Parameter List
- **File:** `src/Domain/Order/Order.php:45`
- **Method:** `createOrder()`
- **Parameters:** 9
- **Issue:** Too many parameters, hard to maintain
- **Refactoring:** Introduce Parameter Object
- **Skills:** `acc-create-dto`,
— $street, $city, $zipCode
— $street, $city, $zipCode
— $street, $city, $zipCode
Address fields repeated across 3 classes
Extract Address Value Object
Method makes 15 calls to User object, only 2 to own class
Move method to User or create UserReportBuilder
Email should be Value Object for validation
Create Email Value Object
Law of Demeter violation, tight coupling
Add shortcut method or delegate
45
Method approaching complexity threshold
Extract query builder or specification
God Classes blocking testing
Data Clumps causing duplication
Long Parameter Lists
Message Chains, minor smells
Remediation Skills
| Smell | Recommended Skill | Approach |
|---|
| God Class | acc-create-use-case, acc-create-domain-service | Extract focused classes |
| Feature Envy | acc-create-domain-service | Move method to data owner |
| Data Clumps | acc-create-value-object | Extract Value Object |
| Long Parameter List | acc-create-dto, acc-create-builder | Introduce Parameter Object |
| Long Method | acc-create-use-case | Extract methods |
| Primitive Obsession | acc-create-value-object | Replace with Value Object |
| Message Chains | (refactoring) | Hide delegate, extract method |
| Inappropriate Intimacy | (refactoring) | Move method, extract class |
Quick Analysis Commands
echo "=== God Classes ===" && \
find . -name "*.php" -path "*/src/*" -exec wc -l {} \; | awk '$1 > 400' && \
echo "=== Long Parameter Lists ===" && \
grep -rn "function [a-z]*(" --include="*.php" src/ | grep -E "(\$[a-z]+,\s*){5,}" && \
echo "=== Primitive Obsession ===" && \
grep -rn "string \$email\|string \$phone\|int \$amount\|float \$price" --include="*.php" src/ && \
echo "=== Message Chains ===" && \
grep -rn "->get[A-Z].*->get[A-Z].*->get[A-Z]" --include="*.php" src/ && \
echo "=== Magic Strings ===" && \
grep -rn "=== '[a-z]*'\|== '[a-z]*'" --include="*.php" src/
Integration with Other Skills
This skill works alongside:
acc-analyze-solid-violations — SOLID violations overlap with some smells
acc-structural-auditor — architectural context for smells
acc-ddd-auditor — domain model quality assessment
References
Based on Martin Fowler's "Refactoring" catalog: