adachsoft / php-code-style
Shared PHP code style (PHP-CS-Fixer) and PHPStan baseline for PHP 8.3+ projects
Installs: 3
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/adachsoft/php-code-style
Requires
- php: ^8.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.68
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^12
This package is not auto-updated.
Last update: 2025-11-05 19:09:09 UTC
README
Shared PHP code style (PHP-CS-Fixer) and PHPStan configuration for PHP 8.3+ projects.
Namespaces used in this package follow AdachSoft\... vendor prefix.
What this package provides
- PHP-CS-Fixer ruleset aligned with PSR-12 plus project conventions:
- php_unit_method_casing: camelCase
- declare_strict_types
- fully_qualified_strict_types: import_symbols=false
- ordered_imports
- trailing_comma_in_multiline for arguments, arrays, parameters
- single_quote
- blank_line_before_statement for return
- PHPStan baseline config (level 9) ready to analyse src/.
Requirements
- PHP 8.3+
- Your project should have dev tools installed: friendsofphp/php-cs-fixer and phpstan/phpstan (this package only provides configuration).
Install
- Require this package as a dev dependency in your project: composer require --dev adachsoft/php-code-style
- If needed, also require the tools in your project: composer require --dev friendsofphp/php-cs-fixer phpstan/phpstan
How to use in your project 1) PHP-CS-Fixer
- Create (or update) a .php-cs-fixer.php file in your project root that imports this package's rules and applies them to your project tree. Example:
- Load the config from this package
- Replace the Finder to point at your project (so it scans your code, not the vendor directory)
- Optionally extend/override rules to fit your needs
2) PHPStan
- Create (or update) phpstan.neon in your project root and include this package's baseline:
includes:
- vendor/adachsoft/php-code-style/phpstan.neon.dist
parameters:
paths:
- src
Optional: configure minimum variable length rule
adachsoftMinVariableLength: 3
- src
- vendor/adachsoft/php-code-style/phpstan.neon.dist
parameters:
paths:
Composer scripts (recommended in your project)
- In your project's composer.json add: scripts: cs:check: php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.php cs:fix: php-cs-fixer fix --config=.php-cs-fixer.php stan: phpstan analyse
Setup script
- This package ships with a helper script to configure your project quickly: vendor/bin/code-style-setup
- It will:
- backup existing .php-cs-fixer(.dist).php and phpstan(.neon|.neon.dist)
- write project .php-cs-fixer.php importing rules from this package and setting the Finder to your paths (default: src, tests)
- write phpstan.neon including this package's phpstan.neon.dist and set paths
- support --restore to revert from the latest backup
Setup script options and examples
Options:
- --dry-run Show planned actions without modifying files
- --no-backup Do not create backups before changing files
- --paths="a,b,c" Comma-separated list of project paths to analyse (defaults: src,tests)
- --restore[=DIR] Restore configs from the latest backup or from DIR if provided
Examples:
- Default setup (with backup): vendor/bin/code-style-setup
- Setup for custom paths: vendor/bin/code-style-setup --paths="src,modules,tests"
- Dry run preview: vendor/bin/code-style-setup --dry-run
- Restore from latest backup: vendor/bin/code-style-setup --restore
- Restore from a specific backup directory: vendor/bin/code-style-setup --restore=.code-style-backups/20250101-120000
Run
- Check coding style: composer cs:check
- Auto-fix coding style: composer cs:fix
- Static analysis: composer stan
Notes
- This package ships with reference configs:
- .php-cs-fixer.dist.php — the default ruleset
- phpstan.neon.dist — the default PHPStan config (level 9) including AdachSoft custom rule
- When importing .php-cs-fixer.dist.php from vendor, always override the Finder to point to your project's root.
Versioning
- No version field in composer.json. Versioning is managed exclusively via Git tags.
License
- MIT (see LICENSE)