Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When an object method is wrapped onto a second line it is supposed to be indented two spaces.
e.g.:
$query = db_select('node');
$query->condition('type', 'article')
->condition('status', 1)
->execute();
The following should throw an error:
$query = db_select('node');
$query->condition('type', 'article')
->condition('status', 1)
->execute();
Currently it doesn't seem to detect this issue.
Comments
Comment #2
klausiI think there is no coding standard specified for this - could you link to a place at https://www.drupal.org/coding-standards or subpages that specifies this?
Comment #3
DamienMcKennaYou are correct, so I opened an issue in the Coding Standards issue queue: #2690599: [policy, no patch] Standardize indenting on chained method calls
Comment #4
alexpott#2690599: [policy, no patch] Standardize indenting on chained method calls has agreed on 2 spaces.
Comment #6
klausiI pushed a start for this, but we will need proper testing for ObjectOperatorIndentSniff.
Comment #7
pfrenssenThis now throws a false positive on this structure:
I get a false positive "Object operator not indented correctly; expected 8 spaces but found 6"
Comment #8
pfrenssenStarted on a PR: https://github.com/klausi/coder/pull/10
Comment #9
pfrenssenI am having some failures that seem to be due to a bug in PHP_CodeSniffer. @Klausi maybe you have already encountered this before? The
nested_parenthesis
seems to be incorrect. I'll explain more in detail on the PR.edit: there is no bug in PHP_CodeSniffer, I'm stupid.
Comment #10
pfrenssenPR is ready, I have done the following:
->
) is at the end of the line.Changing this also to a feature request, this is not a bug but rather an implementation of a newly defined coding standards.
Comment #11
klausiThanks, left a couple of comments on the PR.
It looks like your test case from above with $membership is missing?
Comment #12
klausididn't mean to change the category.
Comment #13
pfrenssenThanks for the lightning fast review!! I fixed the remarks.
Comment #14
pfrenssenThis is actually covered by this part in the test, my example was from Organic Groups, but I replaced it with some core code that exhibits the same problem, this is more recognizable for people unfamiliar with OG:
Comment #16
klausiMerged, thanks!
Comment #17
klausiTested it a bit on core, identified some false positives. Thinking about rewriting the whole sniff, work in progress at https://github.com/klausi/coder/pull/13
Comment #19
klausiRewrote the sniff and all fixes for Drupal core look good now.