Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce PSR-12 and organise imports on Winter CMS core files #1188

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from

Conversation

bennothommo
Copy link
Member

@bennothommo bennothommo commented Aug 23, 2024

This commit changes the PHP code sniffer to use PSR-12 rules, as that ruleset will pick up a lot of the code style issues being flagged in PRs recently.

In order to set the baseline, all current core files have been reformatted to fit the ruleset.

I have also implemented rules around imports in files - mainly, taking out the aliases and using qualified facades and class names, and stripping out unused imports. This will improve IDE support for PHP intelligence and code completion.

Arrays are also now enforced to have a trailing comma to improve diffs.

Sorry in advance for the code review... 😬

This commit changes the PHP code sniffer to use PSR-12 rules, as that ruleset will pick up a lot of the code style issues being flagged in PRs recently.

In order to set the baseline, all current core files have been reformatted to fit the ruleset.
- Convert all aliases to qualified class names (mainly facades)
- Reorder imports alphabetically
- Ensure last item in array has a trailing comma
- Strip out unused imports
@bennothommo bennothommo changed the title Enforce PSR-12 on Winter CMS core files Enforce PSR-12 and organise imports on Winter CMS core files Aug 23, 2024
@LukeTowers
Copy link
Member

@bennothommo can you submit a PR to our developer guidelines docs to reflect these changes? Also, is it worth adding a winter:phpcs command to run the coding styles against plugins and then providing that as a command that plugin devs can run against their codebase to make sure that it conforms with the community standards?

Another thing to check is our stub files, I'm not sure if they've all been updated to our latest preferences for generating PHP files.

This will allow us to use the ruleset in plugins as well
With new ruleset, it now passes
This command will allow developers to check code style against the Winter CMS code style rules in both the core and installed plugins.
parent::__construct();

// Register aliases for backwards compatibility with October
$this->setAliases(['winter:phpcs']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bennothommo bennothommo marked this pull request as draft October 11, 2024 00:25
@bennothommo bennothommo added enhancement PRs that implement a new feature or substantial change and removed Status: In Progress labels Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement PRs that implement a new feature or substantial change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants