adachsoft / php-code-style
Shared PHP code style (PHP-CS-Fixer) and PHPStan baseline for PHP 8.3+ projects
Installs: 14
Dependents: 10
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/adachsoft/php-code-style
Requires
- php: ^8.3
Requires (Dev)
- adachsoft/changelog-linter: ^0.3.0
- adachsoft/collection: ^2.5.0
- friendsofphp/php-cs-fixer: ^3.68
- justinrainbow/json-schema: ^5.2
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12
- twig/twig: ^3.0
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/ (compatible with PHPStan 2.x).
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
- EITHER let phpstan/extension-installer include our config automatically via composer extra:
- This package declares extra.phpstan.includes in its composer.json
- If your project uses phpstan/extension-installer, our phpstan.neon.dist will be auto-included
- OR include manually in your project's phpstan.neon:
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
- Coverage (when running PHPUnit):
- Text summary in console
- Clover XML: build/logs/clover.xml
- HTML report: build/coverage/
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)