footeam / php-style
FooTeam's shared PHP style rules for PHP-CS-Fixer
dev-main
2021-06-01 22:24 UTC
Requires
- php: >=8.0
- friendsofphp/php-cs-fixer: ^3.0
- matt-allan/laravel-code-style: dev-main#b224862421b6b2777026202509e395cb945313dd
This package is not auto-updated.
Last update: 2025-03-28 01:58:46 UTC
README
Rules preset :
@Laravel
by Matt Allan@Laravel:risky
by Matt Allan@PHP80Migration
@PHP80Migration:risky
And custom rules (see /src/rules
).
Installation
Add this repository in your composer.json:
"repositories": [
{
"type": "vcs",
"url": "https://gitlab.com/FooTeam/php-style"
}
]
Then execute the following commands:
composer require footeam/php-style:dev-main --dev
echo "<?php
require __DIR__.'/vendor/autoload.php';
return FooTeam\styles(PhpCsFixer\Finder::create()
->in([__DIR__.'/app', __DIR__.'/config', __DIR__.'/database', __DIR__.'/routes', __DIR__.'/tests']));
" >> .php-cs-fixer.dist.php
Don't forget to add the following line to the .gitignore
:
.php-cs-fixer.cache
Usage
In a terminal:
./vendor/bin/php-cs-fixer fix
In a git pre-commit hook (.git/hooks/pre-commit
):
#!/usr/bin/env bash
source_root=$(git rev-parse --show-toplevel)
staged_files=$(git diff --cached --name-only)
exit_code=0
for staged in ${staged_files}; do
if [[ -f ${staged} && ${staged} == *.php ]]; then
${source_root}/vendor/bin/php-cs-fixer fix ${staged} --dry-run -vv --using-cache=no
if [[ $? -ne 0 ]]; then
exit_code=1
fi
fi
done
if [[ ${exit_code} -eq 1 ]]; then
echo "lint failed"
fi
exit ${exit_code}
Risky rules
This will apply the following risky rules:
- no_php4_constructor
- no_alias_functions
- implode_call
- combine_nested_dirname
- pow_to_exponentiation
- void_return
- is_null
- no_unreachable_default_argument_value
- self_accessor
- no_unneeded_final_method
- use_arrow_functions
- non_printable_character
- random_api_migration
- psr4
- psr_autoloading
Check them here.