openapi-php-sdk icon indicating copy to clipboard operation
openapi-php-sdk copied to clipboard

Enforce PSR-12 coding style with PHP_CodeSniffer

Open francescobianco opened this issue 6 months ago • 2 comments

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

  1. Add squizlabs/php_codesniffer to require-dev
  2. Add a .phpcs.xml configuration file
  3. Add composer run cs and composer run cs-fix scripts using phpcbf

Good first issue

This is a great starting point — fixing PHPCS errors is mechanical and teaches the codebase structure without needing deep PHP knowledge.

francescobianco avatar May 08 '26 16:05 francescobianco

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:

  1. Add squizlabs/php_codesniffer to require-dev via Composer
  2. Add a .phpcs.xml config file targeting PSR12 for the src/ directory
  3. Add cs and cs-fix scripts to composer.json
  4. Run phpcbf to auto-fix the existing errors (like the ones in src/Bootstrap.php)
  5. 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.).

muhammadshaharyaraulakh avatar May 23 '26 04:05 muhammadshaharyaraulakh

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

francescobianco avatar Jun 03 '26 15:06 francescobianco