N°8796 - Add pre-commit hooks for auto PHP code style fixing #780
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Base information
Objective (enhancement)
In a previous PR, we introduced the PHP code style tool (PHP CS Fixer), a re-formatting of the code base and a comformity check in the CI.
This PR aims at easing developer's experience by automatically running the PHP code style fixer on files about to be committed. Avoiding to manually launch the tool or to make a "Fix CI" commit after pushing non-comform code.
Proposed solution
What has been done:
pre-commithook to fix code style of staged PHP files<ITOP>/captainhook.json?pre-commithook it would either:check, block the commit, which was good but forced the developer to manually run PHP-CS-Fixer, then re-commit => Not OKfix, commit files anyway, then fix them for a second commit => Not OKfixcommand on files, then re-stage them for the current commit, which makes it a transparent operation for the developerHow to use it:
<ITOP>/tests/php-code-stylefoldercomposer install<ITOP>folder<ITOP>/captainhook.config.json.distinto<ITOP>/captainhook.config.jsonphp-pathline and adjust it to your environement (It's important to change this BEFORE running the next command, otherwise the Git hook will be installed with an incorrect path to PHP)composer installChecklist before requesting a review
Things to keep in mind
require-devjust like for some other dependencies (e.g. "web profiler"), it should be up to the Factory to clean these "dev dependencies" when building the final package.