acc-generate-bug-fix
Bug Fix Generator
Templates and patterns for generating minimal, safe bug fixes.
Fix Generation Principles
1. Minimal Change
- Fix only what's broken
- No refactoring
- No "improvements"
- No formatting changes
2. Safe Change
- Preserve existing behavior
- Maintain API contracts
- Keep backward compatibility
- Add, don't remove
3. Tested Change
- Reproduction test first
- Fix makes test pass
- Existing tests still pass
Fix Templates by Category
| Category | Patterns | See |
|---|---|---|
| Null Pointer | Guard clause, Null object, Optional return | templates.md |
| Logic Error | Condition correction, Boolean inversion, Missing case | templates.md |
| Boundary | Empty check, Index bounds, Range validation | templates.md |
| Race Condition | Database locking, Optimistic locking, Atomic operation | templates.md |
| Resource Leak | Try-finally, Higher-level API, Pool return | templates.md |
| Exception | Specific catch, Exception chaining, Proper re-throw | templates.md |
| Type Safety | Strict types, Type validation, Boundary coercion | templates.md |
| SQL Injection | Prepared statement, Query builder | templates.md |
| Infinite Loop | Iteration limit, Visited tracking, Depth limit | templates.md |
Quick Reference
Null Pointer → Guard Clause
$entity = $this->repository->find($id);
if ($entity === null) {
throw new EntityNotFoundException($id);
}
Logic Error → Condition Fix
// Wrong: if ($a > $b)
// Fixed: if ($a >= $b)
Boundary → Empty Check
if ($items === []) {
throw new EmptyCollectionException();
}
Race Condition → Locking
$this->em->beginTransaction();
try {
$entity = $this->repository->findWithLock($id);
// ... modify ...
$this->em->commit();
} catch (\Throwable $e) {
$this->em->rollback();
throw $e;
}
Resource Leak → Try-Finally
$resource = acquire();
try {
return process($resource);
} finally {
release($resource);
}
Fix Composition Rules
Order of Operations
- Add validation/guards at the top
- Make the minimal code change
- Keep existing code paths intact
- Add new exception types if needed
What NOT to Change
- Method signatures (unless required)
- Return types (unless fixing wrong type)
- Visibility modifiers
- Class structure
- Unrelated code
Commit Message Format
fix(<scope>): <short description>
<detailed description of what was wrong and how it's fixed>
Fixes #<issue-number>
More from dykyi-roman/awesome-claude-code
psr-overview-knowledge
PHP Standards Recommendations (PSR) overview knowledge base. Provides comprehensive reference for all accepted PSRs including PSR-1,3,4,6,7,11,12,13,14,15,16,17,18,20. Use for PSR selection decisions and compliance audits.
22detect-code-smells
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.
15clean-arch-knowledge
Clean Architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Clean Architecture and Hexagonal Architecture audits.
15ddd-knowledge
DDD architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Domain-Driven Design audits.
14testing-knowledge
Testing knowledge base for PHP 8.4 projects. Provides testing pyramid, AAA pattern, naming conventions, isolation principles, DDD testing guidelines, and PHPUnit patterns.
12bug-root-cause-finder
Root cause analysis methods for PHP bugs. Provides 5 Whys technique, fault tree analysis, git bisect guidance, and stack trace parsing.
12