Enforce PSR-12 coding style with PHP_CodeSniffer
Context
There is no enforced coding standard in this project. Contributors may use different styles for brace placement, spacing, and imports.
Current state
Running phpcs src/ --standard=PSR12 today produces warnings like:
FILE: src/Bootstrap.php
--------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
--------------------------------------------------------------------------------------------
6 | ERROR | [x] Header comment block must be followed by a blank line
34 | ERROR | [x] Expected 1 blank line after function; 2 found
41 | ERROR | [x] Closing brace must be on a line by itself
--------------------------------------------------------------------------------------------
Proposal
- Add
squizlabs/php_codesniffertorequire-dev - Add a
.phpcs.xmlconfiguration file - Add
composer run csandcomposer run cs-fixscripts usingphpcbf
Good first issue
This is a great starting point — fixing PHPCS errors is mechanical and teaches the codebase structure without needing deep PHP knowledge.
Hi @francescobianco Yes, absolutely worth solving and consistent code style makes the project much easier to contribute to and review. I'd like to take this one. My plan:
- Add
squizlabs/php_codesniffertorequire-devvia Composer - Add a
.phpcs.xmlconfig file targetingPSR12for thesrc/directory - Add
csandcs-fixscripts tocomposer.json - Run
phpcbfto auto-fix the existing errors (like the ones insrc/Bootstrap.php) - Open a PR with a clean baseline — zero PHPCS errors Let me know if there are any constraints I should be aware of (PHP version targets, CI setup, etc.).
Hi @muhammadshaharyaraulakh,
Thank you for taking the initiative on this!
Your proposed plan looks great and aligns well with what we had in mind. Establishing a consistent coding style across the project will definitely improve maintainability and make contributions easier for everyone.
A few notes:
- PSR-12 is a good starting point for the coding standard.
- Adding PHPCS and the related Composer scripts sounds perfect.
- Using PHPCBF to generate a clean baseline is exactly the approach we'd prefer.
- Please try to keep the formatting changes focused on the source code and avoid unrelated modifications where possible, as that will make the review process smoother.
At the moment there are no major constraints from our side regarding CI integration. If you discover anything that would benefit from additional discussion while working on the implementation, feel free to share your findings in the PR.
Thanks again for your contribution — we're looking forward to reviewing it!
P.S. After your first merged pull request, we'd be delighted to welcome you to our official contributors registry. Feel free to add your name here:
https://github.com/openapi/contributors