# RSpade Code Quality System ## Overview The Code Quality system is a modular, extensible framework for enforcing coding standards and best practices across the RSpade codebase. It replaces a monolithic 1921-line checker with a clean, maintainable architecture using Manifest-based auto-discovery. ## Architecture ### Core Components 1. **CodeQualityChecker** (`CodeQualityChecker.php`) - Main orchestrator that discovers and runs all rules - Auto-discovers rules via RuleDiscovery::discover_rules() - Handles file scanning, caching, and violation collection - Performs syntax linting for PHP, JavaScript, and JSON files 2. **CodeQualityRule_Abstract** (`Rules/CodeQualityRule_Abstract.php`) - Base class for all code quality rules - Defines the interface: `get_id()`, `get_name()`, `check()`, etc. - Provides `add_violation()` helper method - Rules self-register by extending this class 3. **Violation** (`Violation.php`) - Data class representing a code violation - Contains: rule_id, file_path, line_number, message, severity, code_snippet, suggestion - Provides `to_array()` for serialization ### Support Classes - **ViolationCollector** - Aggregates violations from all rules - **CacheManager** - Caches sanitized file contents to improve performance - **FileSanitizer** - Removes comments and strings for accurate code analysis ## Rule Categories ### PHP Rules (`Rules/PHP/`) 1. **NamingConventionRule** (PHP-NAMING-01) - Enforces underscore_case for methods and variables - Excludes Laravel framework methods (toArray, firstOrCreate, etc.) - Severity: Medium 2. **MassAssignmentRule** (PHP-MASS-01) - Prohibits use of $fillable property - Ensures $guarded = ['*'] or removal - Severity: High 3. **PhpFallbackLegacyRule** (PHP-FALLBACK-01) - Detects "fallback" or "legacy" in comments/function names - Enforces fail-loud principle - Severity: Critical 4. **DbTableUsageRule** (PHP-DB-01) - Prohibits DB::table() usage - Requires ORM models for database access - Severity: High 5. **FunctionExistsRule** (PHP-FUNC-01) - Prohibits function_exists() checks - Enforces predictable runtime environment - Severity: High ### Jqhtml Rules (`Rules/Jqhtml/`) 1. **JqhtmlInlineScriptRule** (JQHTML-INLINE-01) - Prohibits inline