Skip to content

Change code style to PSR-12#738

Merged
mblaney merged 12 commits intosimplepie:masterfrom
Art4:change-code-style-to-psr12
Aug 26, 2022
Merged

Change code style to PSR-12#738
mblaney merged 12 commits intosimplepie:masterfrom
Art4:change-code-style-to-psr12

Conversation

@Art4
Copy link
Contributor

@Art4 Art4 commented May 23, 2022

This PR changes the code style in all classes and tests to PSR-12. As discussed with @jtojnar in #734 (comment) I think that after the huge changes from #722 the timing is ideal.

@Art4 Art4 mentioned this pull request May 23, 2022
48 tasks
@jtojnar
Copy link
Member

jtojnar commented May 23, 2022

@Art4
Copy link
Contributor Author

Art4 commented May 23, 2022

  • We should also add CI check.

Good point 👍

SimplePie does not support PHP 5.4 anymore. And the only rule in @PHP56Migration:risky is pow_to_exponentiation, but we don't use pow() afaik.

I don't have any particular preferences about this. It's enough for me if rules are defined and these can be implemented automatically by running a script.

@jtojnar
Copy link
Member

jtojnar commented May 23, 2022

SimplePie does not support PHP 5.4 anymore

Right, but we did not ever migrate to the newly introduced syntax so we still use long array syntax. PHP54MigrationSet would fix that.

@Art4
Copy link
Contributor Author

Art4 commented May 23, 2022

Right, but we did not ever migrate to the newly introduced syntax so we still use long array syntax. PHP54MigrationSet would fix that.

Oh, wow, you are right. I would have guessed that the short array syntax was already defined in PSR-2. 😅

@jtojnar
Copy link
Member

jtojnar commented May 23, 2022

PSR does not cover many things we take for granted, which is why I suggested the Symfony ruleset (even though it contains some questionable or even choices potentially hindering comprehension of code like the yoda style – we read left to right so having the object that introduces the most information on the left side is clearly preferable. And in most cases that will be the variable. Really, Yoda style only makes sense if you are comparing multiple values against the same variable – but then maybe you should use in_array – or if you have Jedi powers and the order things are written in does not matter to you because you feel them at the same time).

@Art4
Copy link
Contributor Author

Art4 commented May 24, 2022

  • We should also add CI check.

Do you have a tip or example for me on how to make this happen?

I've added all non-risky Migration rules, namely @PHP54Migration. I would not automate risky changes, but require a human to watch over changes.

I would like to move these decisions to a separate PR. In this PR, I would like to have a basic set of rules that everyone can agree on.

@jtojnar
Copy link
Member

jtojnar commented May 24, 2022

Do you have a tip or example for me on how to make this happen?

I would probably add php-cs-fixer:3.8 (pinned version so that CI does not break when new version is released) along with cs2pr as described here as a new job in https://github.com/simplepie/simplepie/blob/master/.github/workflows/ci.yml.

Having it in composer dev dependencies would be nicer but would force us to stay with old version of php-cs-fixer, as the latest version requires PHP 7.4. Edit: Actually, it looks like having a separate composer file is recommended upstream: https://cs.symfony.com/#installation

I would like to move these decisions to a separate PR. In this PR, I would like to have a basic set of rules that everyone can agree on.

On the other hand, we are already changing the coding style significantly (replacing tabs with spaces) so this might be a best time for establishing a coding style once and for all. Each time we change it adds another obstacle to git blame (which has already been pretty battered by #722). Once this PR is merged we should add the commit hash to .git-blame-ignore-revs and hope it works.

@mblaney
Copy link
Member

mblaney commented Jul 7, 2022

nice work I prefer this coding style too

@Art4
Copy link
Contributor Author

Art4 commented Jul 7, 2022

I've resolved the merge conflicts.

Actually, it looks like having a separate composer file is recommended upstream: https://cs.symfony.com/#installation

After reading up a bit, I have to say that I don't feel confident enough in this area. I would like to leave this topic to someone else.

And maybe even @Symfony or @Symfony:risky to automate as many style decisions as possible. Though then we will probably want to deactivate obnoxious rules like yoda_style.

@mblaney Any preferences about this? I could easily define some more rules in this PR.

@mblaney
Copy link
Member

mblaney commented Aug 23, 2022

sorry looks like I missed that this was ready to merge? happy with the composer change but not familiar with the symfony requirements and doesn't feel like something we need to add here?

@Art4
Copy link
Contributor Author

Art4 commented Aug 26, 2022

happy with the composer change but not familiar with the symfony requirements and doesn't feel like something we need to add here?

We could remove the "friendsofphp/php-cs-fixer" library from "require-dev", but it allows every contributor to simply run bin/php-cs-fixer fix to fix all CS issues. Without this dependency the .php-cs-fixer.dist.php also makes no sense, where the CS rules are defined. I would recommend to keep this dependency.

sorry looks like I missed that this was ready to merge?

Yes, it is. As long as there are no change requests, this PR is ready for merge from my side.

@mblaney mblaney merged commit cce6ad2 into simplepie:master Aug 26, 2022
@Art4 Art4 deleted the change-code-style-to-psr12 branch August 27, 2022 06:41
Alkarex added a commit to FreshRSS/simplepie that referenced this pull request Aug 30, 2022
Fix regression from simplepie#738
See simplepie#724

Sad to see all these wasted / inefficient / hard-coded spaces though... Tabs ❤️
mblaney pushed a commit that referenced this pull request Sep 22, 2022
Fix regression from #738
See #724

Sad to see all these wasted / inefficient / hard-coded spaces though... Tabs ❤️
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants