-
Notifications
You must be signed in to change notification settings - Fork 15
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
Apply coding style #652
Apply coding style #652
Conversation
.php_cs is outdated and cannot be used anymore due to PHP CS Fixer 3 upgrade. Instead use .php-cs-fixer.php and updated methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Please also update the fix
script in composer.json
to use the new config file.
Beside the comments below, a problem I always had is the indentation that CS fixer wants to enforce. For example, it suggests something like this:
$this->putJson("/api/v1/maia/annotation-candidates/{$a->id}", [
- // Must be points of a circle.
- 'points' => [10, 20],
- ])
+ // Must be points of a circle.
+ 'points' => [10, 20],
+ ])
->assertStatus(422);
But I want the parenthesis of putJson()
to end at the same level of indentation than the chained assertStatus()
. Either the parenthesis (and arguments) are indented one level or the chained method is unindented. Can you find a ruleset that does this? You can check the proposed output with composer fix -- --dry-run --diff
.
Also please remember to put the
|
Ah yes. Sorry, I completely forgot about this. Shall I change this and force push the changes? |
Force push because of the commit message? No, it's fine. Just do it next time 😉 |
I've opened a discussion for the method chain indentation issue: PHP-CS-Fixer/PHP-CS-Fixer#7319 |
In the discussion, the |
So, one possible solution (from the discussion linked above) would be to make sure the line with the opening $this
->putJson("/api/v1/maia/annotation-candidates/{$a->id}", [
// Must be points of a circle.
'points' => [10, 20],
])
->assertStatus(422); or this: $parentConflicts =
$mergeLabels->filter(function ($label) {
return array_key_exists('conflicting_parent_id', $label);
})
->each(function ($label) use ($parentConflictResolution) { This should work both for the multiline array case and for the multiline closure case. I could live with this coding style but unfortunately all these cases would have to be updated by hand. We could do this all with great effort now and then enforce the style in the future. On the other hand, this is a cosmetic change and might cost a lot of time for "nothing". @lehecht Could you estimate how much manual work would be involved? |
Should something like be changed to this or to this ? |
I wrote a small python parser to help recognize some lines with wrong indentation and fix them. This helps a lot but will still require proof reading. Furthermore testing is needed. I wouldn't rely on the |
I would change your example from $query = $this->volume->files()
->when($this->only, function ($query) {
return $query->whereIn('id', $this->only);
}); to $query = $this->volume
->files()
->when($this->only, fn ($query) => $query->whereIn('id', $this->only)); To be more consistent, I'll update my example from above to $parentConflicts = $mergeLabels
->filter(function ($label) {
return array_key_exists('conflicting_parent_id', $label);
})
->each(function ($label) use ($parentConflictResolution) { It's also only a problem with the CS Fixer if the closure or array is opened at a different level of indentation than it should be closed (see my examples above). In your example 1) the closure starts at the same level than it should be closed and 2) in the updated code there is no multi-line closure at all any more.
If that's the case then we sould update the tests 😉 Do you have an example for that?
That's a lot but I think it's worth it. Afterwards we can enforce the coding style in pull requests. |
I applied your changes and a new rule (no_unused_imports) to the app directory. Could you look through some files to check if you like it? I will apply those changes to all other files after you gave me your feedback. Some candidates to check could be: |
No, I don't have one. I just meant that more complex bugs sometimes occur when several functions were used consecutively. But maybe I'm worrying too much about it. I also don't know how every test looks like. So if you think, it's enough to just run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many changes that I wouldn't do. I've tried to give a few examples.
If this is getting too complicated, let me know. We could always disable any indentation style checks, too.
This reverts commit 24abc0f.
Use PHP-cs-fixer and add indentations manually
I saw that you marked this ready for review and I'll have a look. Next time please also click to re-request my review otherwise I won't get a notification for this 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a nice cleanup! I really like all the arrow functions that we now got for free and that make the code more readable.
I've added several suggestions that should make the code even more readable in context of what we agreed on here. It's probably easiest for you if you commit them as a batch here in the GitHub UI (if you agree with them).
Do you also want to add the GitHub action that will complain about incorrect coding style in this PR?
When this is all sorted out and working, the modules come next 😉 But maybe you should work on something else in the meantime so you don't do CS fixed for the rest of the year 😄 You could pick up one module after the other inbetween other tasks (bugfixes, features).
app/Http/Controllers/Api/Annotations/Filters/AnnotationUserController.php
Outdated
Show resolved
Hide resolved
app/Http/Controllers/Api/Volumes/Filters/AnnotationLabelController.php
Outdated
Show resolved
Hide resolved
Thank you for your big support! I'm sorry that you still had to put so much time into it. I really just went through all marked files of git diff. |
Co-authored-by: Martin Zurowietz <[email protected]>
Yes! But I will need some more informations on how to do it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 3 unresolved comments from my previous review.
I think we are almost done now. But I suggest that the GitHub action should be added in another PR so we can merge this huge one first.
When you want to implement a new GitHub action, you add a new file to .github/workflows
. However, we already have lint.yml
there to which the new job could be added, too. As a start, all you have to do is to copy the lint-php
block and append it as new cs-php
block to the file. Then you only have to update the last command from composer lint
to composer fix -- --dry-run
. After that we can try to figure out how to add GitHub annotations.
$this | ||
->postJson("/api/v1/projects/{$id}/invitations", [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be updated, too.
Unfortunately, the given website states that PHP-CS Fixer doesn't support GitHub annotations. |
The linked article suggests a solution with |
.php_cs is outdated and cannot be used anymore due to PHP CS Fixer 3 upgrade. Instead use .php-cs-fixer.php and updated methods.