--- name: acc-psr-coding-style-knowledge description: PSR-1 and PSR-12 coding standards knowledge base for PHP 8.5 projects. Provides quick reference for basic coding standard and extended coding style with detection patterns, examples, and antipattern identification. Use for code style audits and compliance reviews. --- # PSR Coding Style Knowledge (PSR-1, PSR-12) ## Quick Reference | Standard | Focus | Key Rules | |----------|-------|-----------| | PSR-1 | Basic Standard | Files, namespaces, class names | | PSR-12 | Extended Style | Formatting, keywords, visibility | ## PSR-1: Basic Coding Standard ### 1. Files | Rule | Requirement | |------|-------------| | Tags | MUST use `id; } public function activate(): self { return new self( $this->id, $this->email, $this->name, true, ); } } ``` ### 5. Control Structures ```php 'First', 1, 2 => 'Second or third', default => 'Other', }; // while while ($expr) { // body } // for for ($i = 0; $i < 10; $i++) { // body } // foreach foreach ($iterable as $key => $value) { // body } // try-catch-finally try { // try body } catch (FirstThrowableType $e) { // catch body } catch (OtherThrowableType | AnotherThrowableType $e) { // multi-catch body } finally { // finally body } ``` ### 6. Operators ```php $a * $b; ``` ### 8. Anonymous Classes ```php PSR-12 coding standard src tests vendor/* ``` ## PHP-CS-Fixer Configuration ```php in([ __DIR__ . '/src', __DIR__ . '/tests', ]) ->name('*.php'); return (new Config()) ->setRiskyAllowed(true) ->setRules([ '@PSR12' => true, '@PHP84Migration' => true, 'declare_strict_types' => true, 'final_class' => true, 'class_attributes_separation' => [ 'elements' => ['method' => 'one'], ], 'ordered_imports' => [ 'sort_algorithm' => 'alpha', 'imports_order' => ['class', 'function', 'const'], ], 'no_unused_imports' => true, 'trailing_comma_in_multiline' => [ 'elements' => ['arguments', 'arrays', 'parameters'], ], ]) ->setFinder($finder); ``` ## Antipatterns | Violation | PSR | Severity | Fix | |-----------|-----|----------|-----| | Mixed declarations and side effects | PSR-1 | CRITICAL | Separate into bootstrap file | | snake_case class names | PSR-1 | CRITICAL | Rename to StudlyCaps | | Tabs for indentation | PSR-12 | WARNING | Convert to 4 spaces | | Boolean/integer type hints | PSR-12 | WARNING | Use bool/int | | Missing strict_types | - | WARNING | Add declaration | | Opening brace on same line | PSR-12 | INFO | Move to next line | | Trailing whitespace | PSR-12 | INFO | Remove whitespace | ## Integration with DDD ### Domain Layer ```php value; } } ``` ### Application Layer ```php email, $command->name, ); $this->userRepository->save($user); } } ``` ## See Also - `references/psr-1-basic.md` - Full PSR-1 specification - `references/psr-12-extended.md` - Full PSR-12 specification - `references/detection-patterns.md` - Comprehensive detection patterns - `references/antipatterns.md` - Common violations with fixes - `assets/report-template.md` - Compliance report template