QA Analysis and Refactoring Plans¶
Analysis Date: 2025-11-08 Status: Planning Phase - No Code Changes Made
This directory contains comprehensive analysis and refactoring plans based on QA tool output (phpcs, phpmd, phpstan, rector).
Quick Start¶
Immediate Action Required 🔴¶
CRITICAL BUG DETECTED: Start with this plan immediately:
- fix-missing-default-instruction-method.md - Runtime error in production code
This Week (High Priority) 🟠¶
Execute these plans for maximum impact with minimal effort:
- add-doctrine-collection-generics.md - Quick win, fixes 69 errors
- apply-rector-safe-rules.md - Automated modernization
- refactor-html-cleaner-god-object.md - Worst complexity violation
Overview Documents¶
Master Analysis Documents¶
- qa-analysis-overview.md - Complexity & design issues (phpmd, phpcs)
- phpstan-rector-analysis-overview.md - Type safety & modernization
These provide executive summaries, statistics, and prioritization.
Plans by Priority¶
🔴 Critical Priority (Week 1)¶
Type Safety (PHPStan):
- fix-missing-default-instruction-method.md - Runtime error bug
- fix-undefined-methods.md - 24 potential runtime errors (To be created)
- fix-uninitialized-properties.md - Null reference bugs (To be created)
Complexity (PHPMD):
- refactor-html-cleaner-god-object.md - Complexity 107/60
- refactor-filter-service-god-object.md - Complexity 83/60
- simplify-operational-commands.md - Critical ops commands
🟠High Priority (Week 2-3)¶
Type Safety:
- add-doctrine-collection-generics.md - 69 errors, quick win
- apply-rector-safe-rules.md - Automated modernization
Complexity:
- simplify-domain-entities.md - CoffeeBean & mapper
- refactor-coffee-bean-persister.md - Data ingestion
- refactor-dto-parameter-lists.md - 22 parameters!
- simplify-variety-repository.md - Query complexity
🟡 Medium Priority (Week 4-6)¶
Type Safety:
- add-array-type-hints-entities.md - 294 errors (To be created)
- add-array-type-hints-services.md (To be created)
- add-array-type-hints-repositories.md (To be created)
- fix-return-type-mismatches.md (To be created)
Complexity:
- refactor-crawler-commands.md - Command complexity
- refactor-url-services.md - URL handling
🟢 Low Priority (Opportunistic)¶
- exclude-deploy-from-phpstan.md - Config cleanup (To be created)
- Fixture complexity - Low priority (test data)
- PSR-1 violations - Config scripts
Plans by Category¶
God Objects & Complexity¶
- refactor-html-cleaner-god-object.md - 🔴 Critical
- refactor-filter-service-god-object.md - 🔴 Critical
- simplify-domain-entities.md - 🟠High
- simplify-operational-commands.md - 🔴 Critical
Type Safety & PHPStan¶
- fix-missing-default-instruction-method.md - 🔴 Critical
- add-doctrine-collection-generics.md - 🟠High (Quick Win)
- apply-rector-safe-rules.md - 🟠High (Quick Win)
Data Layer¶
- refactor-coffee-bean-persister.md - 🟠High
- simplify-variety-repository.md - 🟠High
API Layer¶
- refactor-dto-parameter-lists.md - 🟠High
Crawler¶
- refactor-crawler-commands.md - 🟡 Medium
- refactor-url-services.md - 🟡 Medium
Statistics¶
Current State (2025-11-08)¶
-
PHPMD Violations: 29
- God Objects: 4 (complexity 63-107)
- Excessive Complexity: 18 methods
- Excessive Parameters: 5 DTOs/classes
- Long Methods: 3 (150-229 lines)
-
PHPStan Errors: 635
- Missing array types: 294 (46%)
- Missing generics: 69 (11%)
- Undefined methods: 24 (4%)
- Uninitialized properties: 18 (3%)
- deploy.php errors: 115 (18% - can ignore)
-
Rector Suggestions: 53 files
- Safe modernizations available
Target State (1 Month)¶
- PHPMD: <15 violations
- PHPStan: <200 errors (68% reduction)
- Critical Errors: 0
- Type Coverage: ~70%
Target State (3 Months)¶
- PHPMD: <5 violations
- PHPStan: <50 errors (92% reduction)
- Type Coverage: ~90%
- PHPStan Level: 8
Quick Wins (High Impact, Low Effort)¶
Execute these first for maximum return on investment:
-
add-doctrine-collection-generics.md
- Effort: 2-3 hours
- Impact: Fixes 69 PHPStan errors
- Automated: 95% via Rector
-
- Effort: 2-3 hours
- Impact: Fixes ~100 errors, modernizes code
- Automated: 90% via Rector
-
fix-missing-default-instruction-method.md
- Effort: 2-3 hours
- Impact: Prevents production crashes
- Critical: Runtime bug
Recommended Execution Order¶
Week 1: Critical Bugs¶
- Fix missing getDefaultInstruction() method (P0)
- Investigate undefined method errors (P0)
- Fix uninitialized properties (P1)
Week 2: Quick Wins¶
- Add Doctrine Collection generics (automated)
- Apply safe Rector rules (automated)
- Start on HtmlCleaner god object
Week 3-4: Major Refactoring¶
- Complete HtmlCleaner refactoring
- Refactor FilterService god object
- Simplify operational commands
- Refactor DTOs with excessive parameters
Week 5-6: Medium Priority¶
- Domain entity simplification
- Coffee bean persister refactoring
- Repository query builders
- Array type hints (entities first)
Week 7+: Cleanup & Optimization¶
- Remaining array type hints
- Command simplification
- URL service refactoring
- Configuration cleanup
Tools Used¶
- phpcs - Code style (PSR-1, PSR-12)
- phpmd - Complexity and design violations
- phpstan - Static analysis and type safety (Level 7)
- rector - Code modernization and type hints
Notes¶
- All plans are in planning phase - no code has been changed
- Plans are independent where possible - can be executed in parallel
- Some plans have dependencies - check individual plan files
- Type safety and complexity refactoring can be done in parallel
- Quick wins should be prioritized for morale and momentum
- Critical bugs must be fixed before deployment
Getting Started¶
-
Read the overview documents:
-
Start with critical priority items:
-
Get some quick wins:
-
Tackle the big refactorings:
Contributing¶
When implementing these plans:
- Create a feature branch for each plan
- Follow the implementation steps in the plan
- Run all tests and QA tools
- Update the plan with any discoveries
- Mark plan as "Implemented" when complete
- Update this README with new metrics
Questions?¶
Review the detailed analysis and architect recommendations in the overview documents.