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

Adding PSR12 coding standard #56

Merged
merged 12 commits into from
Oct 25, 2019
Merged

Adding PSR12 coding standard #56

merged 12 commits into from
Oct 25, 2019

Conversation

ChrisB9
Copy link
Contributor

@ChrisB9 ChrisB9 commented Oct 23, 2019

Since PSR2 has been replaced with PSR12 and the source code is still fresh and little, i thought it might be good to provide this setup (Not much changes anyway).
Fits also good together with #52, since such a check could be automated in the future.

@tmotyl
Copy link
Collaborator

tmotyl commented Oct 24, 2019

@ChrisB9 thanks for the PR, really appreciate!
How do you reformatted the files? Do you know if php_cs_fixer supports that, and what rules we need to add to the .php_cs.dist ?

@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

which rule from PSR-12 applies here? in TYPO3 Core it's formatted with spaces around "="

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My checks went entirely after PSR12, no additional special configuration

Declare statements MUST contain no spaces and MUST be exactly declare(strict_types=1) (with an optional semi-colon terminator).
https://www.php-fig.org/psr/psr-12/#3-declare-statements-namespace-and-import-statements

Copy link
Collaborator

Choose a reason for hiding this comment

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

you're right!

@@ -167,7 +168,7 @@ protected function recursiveFind(array $haystack, $needle)
* @param array $data
* @return array
*/
protected function decodeFieldsIfRequired(array $data) : array
protected function decodeFieldsIfRequired(array $data): array
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, I've added a rule to check this one in #58

@ChrisB9
Copy link
Contributor Author

ChrisB9 commented Oct 24, 2019

@tmotyl I did my checks with grumphp (pluswerk/grumphp-config does provide php_cs built-in with psr12 enabled). And yes i am aware that the php_cs does this and because you added it i wanted to already provide the base for it

Do you know if php_cs_fixer supports that, and what rules we need to add to the .php_cs.dist ?
'@PSR2' => true, should be replaced with '@PSR12' => true, i think

@tmotyl
Copy link
Collaborator

tmotyl commented Oct 24, 2019

I was convinced that php_cs_fixer doesn't support '@psr12' rules yet.
see PHP-CS-Fixer/PHP-CS-Fixer#4502
Please check what rule does your php_cs have we're missing and update the patch with this rule
Please incorporate changes from #58 in your PR.
I would like to have a PR which adds required rules together with code fixes, so it's green in Travis before merge.

@ChrisB9
Copy link
Contributor Author

ChrisB9 commented Oct 24, 2019

I will update it accordingly 👍
Just as a reference, here you can see, which rules i did my check-up with so far:
https://github.com/pluswerk/grumphp-config/blob/master/grumphp.yml
As you can see, there really is nothing particularly special. no extra configs etc :)

And yes, the PHP-CS-Fixer/PHP-CS-Fixer#4502 was not too long ago, we updated our config earlier this month - so very recent

@ChrisB9
Copy link
Contributor Author

ChrisB9 commented Oct 24, 2019

Would it be okay, if i merge your #58 into my PR to incorporate all changes?
I'd like to add grumphp as well, if that aligns with your way of coding.

@tmotyl
Copy link
Collaborator

tmotyl commented Oct 24, 2019

yes, you can merge or just copy paste the file content (I'll be squashing the commits before merging to master anyway).
The grumpphp will be a separate PR.

@ChrisB9
Copy link
Contributor Author

ChrisB9 commented Oct 24, 2019

I have now updated the branch, but i realized, that i did get php-cs-fixer and phpcs mixed up. So you guys were totally right, the fixer does not yet support the new standard while phpcs does.
So if you want, we can hold of for these changes here for now, or keep them as references in... i am not yet sure how to proceed in that matter

@@ -14,6 +11,10 @@
*
***/

declare(strict_types=1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this change intended (moving declare and namespace after comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it's intended:
https://www.php-fig.org/psr/psr-12/#3-declare-statements-namespace-and-import-statements
The order now is first open tag, then file-comment, then declare, then import, then rest

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, looks good then

Copy link
Contributor

Choose a reason for hiding this comment

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

D'no how that rule got accepted to the standard. Can only assume the reviewers missed it. I've never seen any code before that followed that rule of having the doc above the declares. The 2 authors of the PSR must have wanted it, only...

@tmotyl
Copy link
Collaborator

tmotyl commented Oct 25, 2019

there is one more issue to fix see https://travis-ci.com/TYPO3-Initiatives/headless/builds/133514433
and I can then merge the patch

@ChrisB9
Copy link
Contributor Author

ChrisB9 commented Oct 25, 2019

Yes, i just saw it and fixed that one directly

@tmotyl tmotyl merged commit ef83a99 into TYPO3-Headless:master Oct 25, 2019
@tmotyl
Copy link
Collaborator

tmotyl commented Oct 25, 2019

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants