For GitHub pull requests, detect any coding standard violations via PHP_CodeSniffer. Errors should prevent the pull request from being merged and displayed to the user.
- A workflow file with GitHub Actions to set up PHP with Composer and to run PHP_CodeSniffer.
- To prevent the branch from being merged we can make use of protected branches with the
phpcscheck as a required status check.
- Coding standard violations will be displayed via check annotations in Checks via cs2pr.
? Workflow file
The workflow file can be saved in the
.github/workflows directory of your GitHub repository.
- The workflow is using the pat-s/always-upload-cache action, a fork of actions/cache, which also supports caching if a previous step fails.
- Your repository should include a configuration file for PHP_CodeSniffer.
- If the coding standard isn’t one of the defaults it need to be added as (dev) dependency in your project’s
- Only 10 warning and 10 error annotations per step are currently supported (source). It’s recommended to fix all existing errors before publishing the workflow.
- To exit with error codes if there are only warnings you can remove the
--graceful-warningsflag in the last line.
Questions? Feedback? Let me know in the comments!