acc-find-logic-errors
Logic Error Detection
Analyze PHP code for logic errors that cause incorrect behavior.
Detection Patterns
1. Incorrect Comparison Operators
// BUG: Assignment instead of comparison
if ($status = 'active') { } // Should be ===
// BUG: Wrong comparison type
if ($count == '0') { } // '0' is truthy in string comparison
// BUG: Yoda condition error
if ('active' = $status) { } // Assignment error
2. Inverted Logic
// BUG: Double negation confusion
if (!$user->isNotActive()) { } // Hard to reason about
// BUG: Wrong negation placement
if (!$a && $b) { } // vs if (!($a && $b))
// BUG: DeMorgan's law violation
if (!$a || !$b) { } // When meaning !($a && $b)
3. Missing Switch/Match Cases
// BUG: Missing enum case
match ($status) {
Status::Active => 'active',
Status::Inactive => 'inactive',
// Missing: Status::Pending, Status::Deleted
};
// BUG: Missing default
switch ($type) {
case 'A': return 1;
case 'B': return 2;
// No default - undefined behavior for other values
}
4. Short-Circuit Evaluation Issues
// BUG: Side effect in short-circuit
if ($valid && $this->save()) { } // save() not called if !$valid
// BUG: Order matters
if ($obj->method() && $obj !== null) { } // Null check too late
5. Off-by-One in Comparisons
// BUG: Fence post error
if ($index < count($array)) { } // vs <=
// BUG: Wrong boundary
for ($i = 0; $i <= $length; $i++) { } // Off by one
6. Boolean Expression Errors
// BUG: Always true/false
if ($age > 0 || $age <= 0) { } // Always true
// BUG: Unreachable condition
if ($x > 10 && $x < 5) { } // Always false
// BUG: Redundant condition
if ($status === 'active' && $status !== 'inactive') { } // Second part redundant
7. Return Value Ignorance
// BUG: Ignoring important return
array_push($items, $new); // Returns count, not array
$string->trim(); // String is immutable, returns new string
Grep Patterns
# Assignment in condition
Grep: "if\s*\([^=]*[^!=<>]=[^=][^)]*\)" --glob "**/*.php"
# Double negation
Grep: "!\$\w+->isNot|!!\$" --glob "**/*.php"
# Empty switch without default
Grep: "switch\s*\([^)]+\)\s*\{[^}]*\}" --glob "**/*.php"
Output Format
### Logic Error: [Description]
**Severity:** π΄/π /π‘
**Location:** `file.php:line`
**Type:** [Incorrect Operator|Inverted Logic|Missing Case|...]
**Issue:**
[Description]
**Code:**
```php
// Current code
Fix:
// Corrected code
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