This documentation covers Poweradmin 4.0.x and 4.1.x. Some sections are still being expanded.
Poweradmin Coding Standards
Poweradmin follows a set of coding standards based on PSR-12 with some project-specific modifications. This document outlines these standards and how to enforce them.
Standards Overview
- Base Standard: PSR-12
- Modifications:
- Excludes PSR12.Classes.OpeningBraceSpace rule
- Line length set to 250 characters (instead of PSR-12 default)
- Autoloading: PSR-4 (as specified in composer.json)
Code Quality Tools
Poweradmin uses several tools to maintain code quality:
PHP_CodeSniffer (PHPCS/PHPCBF)
- Checks for coding standard violations
- Can automatically fix many issues with PHPCBF
PHP-CS-Fixer
- Additional code style fixing
- Complements PHPCS for more comprehensive style enforcement
PHPStan
- Static analysis tool
- Detects potential errors and type inconsistencies
Psalm
- Type checker
- Configured with level 2 error reporting
PHPMD (PHP Mess Detector)
- Detects code smells and potential problems
- Helps maintain cleaner, more maintainable code
Using the Tools
Running Code Style Checks
# Check code style for lib directory
composer check:lib
# Check code style for all PHP files
composer check:all
Auto-Fixing Code Style Issues
# Fix code style in lib directory
composer format:lib
# Fix code style in all PHP files
composer format:all
Running PHP-CS-Fixer
# Check style with PHP-CS-Fixer
composer style:check
# Fix style with PHP-CS-Fixer
composer style:fix
Static Analysis
# Run PHPStan static analysis
composer analyse:all
# Run Psalm type checking
composer check:psalm
PHP Mess Detection
# Run PHPMD
composer check:phpmd:lib
Setting Up Your Development Environment
For a consistent development experience, configure your IDE to use these coding standards:
PhpStorm
- Install the PHP_CodeSniffer plugin
- Configure it to use the project's phpcs.xml file
- Enable "Reformat Code" to use PSR-12 with project modifications
VSCode
- Install the PHP Intelephense or PHP CodeSniffer extensions
- Configure them to use the project's phpcs.xml file
Pre-Commit Hooks
Consider setting up Git pre-commit hooks to automatically check/fix code style before commits:
- Install husky and lint-staged
- Configure lint-staged to run PHP_CodeSniffer or PHP-CS-Fixer on staged PHP files