Coding Standards
Phexium enforces coding standards using PHP-CS-Fixer. Configuration is in php-cs-fixer.php at the project root.
PSR-12 Compatibility
The coding standards are based on PSR-12: Extended Coding Style. PHP-CS-Fixer enforces PSR-12 through the @PhpCsFixer ruleset, which includes full PSR-12 compliance plus additional rules for consistency. This ensures interoperability with PSR-12 compliant codebases and tooling.
Commands
task coding-standard:lint # Check violations (dry-run)
task coding-standard:fix # Apply fixes automatically
Key Rules
PHP Requirements
- PHP 8.4+ with modern features (readonly classes, enums, typed properties)
- PSR-12 base with project-specific additions
declare(strict_types=1);required in every file
Class Structure
final readonly class CreateBookCommand implements CommandInterface
{
public function __construct(
public string $id,
public string $title,
) {}
}
Naming Conventions
| Element | Convention | Example |
|---|---|---|
| Classes | PascalCase | CreateBookHandler |
| Methods | camelCase | findById() |
| Variables | camelCase | $bookTitle |
| Constants | UPPER_SNAKE_CASE | MAX_LENGTH |
Class Naming Patterns
| Type | Pattern | Example |
|---|---|---|
| Command | {Action}{Entity}Command | CreateBookCommand |
| Query | {Action}{Entity}Query | ListBooksQuery |
| Handler | {Action}{Entity}Handler | CreateBookHandler |
| Event | {Entity}{Action}Event | BookCreatedEvent |
No PHPDoc
Native type hints replace PHPDoc blocks:
See Also
- PSR-12 Extended Coding Style - Interface specification