-
Notifications
You must be signed in to change notification settings - Fork 2
Allow multi-line method chaining #7
Changes from 1 commit
1558984
a296741
6013d07
5c2b516
15802a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| namespace Libero\CodingStandard\Sniffs\WhiteSpace; | ||
|
|
||
| use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ObjectOperatorSpacingSniff as BaseObjectOperatorSpacingSniff; | ||
| use const T_DOUBLE_COLON; | ||
|
|
||
| // This is only present to allow double colons to have separate configuration to the regular object operator. | ||
|
|
||
| final class ObjectStaticOperatorSpacingSniff extends BaseObjectOperatorSpacingSniff | ||
| { | ||
| public function register() | ||
| { | ||
| return [T_DOUBLE_COLON]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,25 +3,36 @@ Method calls must not have unnecessary whitespace | |
| ---CONTENTS--- | ||
| <?php | ||
|
|
||
| $foo -> bar ( $arg1 ); | ||
| $foo -> bar ( $arg1 ) -> baz ( ); | ||
|
|
||
| $foo | ||
| -> bar ($arg1 | ||
| ,$arg2) | ||
| -> baz ($arg1 | ||
| ,$arg2); | ||
|
|
||
| $fooBar() | ||
| ->baz() | ||
| ->qux() | ||
| ; | ||
|
|
||
| ---FIXED--- | ||
| <?php | ||
|
|
||
| $foo->bar($arg1); | ||
| $foo->bar($arg1)->baz(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would rather these became multiline. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is reasonable for me to allow an existing single-line statement to remain single-line, while if you want to go multi-line then you would have to follow a standard. |
||
|
|
||
| $foo | ||
| ->bar( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would rather not keep the newline. |
||
| $arg1, | ||
| $arg2 | ||
| ) | ||
| ->baz( | ||
| $arg1, | ||
| $arg2 | ||
| ); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure about whether the semi-colon should go on the next line. Produces nicer diffs, but looks ugly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah so this is enforced, even if you manually put it on the next line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Diff might look something like this: $foo
->bar(
$arg1,
$arg2
+ )
+ ->baz(
+ $arg1,
+ $arg2
);There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought semicolon-on-next-line was a Symfony standard by now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd favor it not because of the diffs but because keeps lines independent (for fluent interfaces, which is the use case for chained calls):
|
||
|
|
||
| $foo->bar( | ||
| $arg1, | ||
| $arg2 | ||
| )->baz( | ||
| $arg1, | ||
| $arg2 | ||
| ); | ||
| $fooBar() | ||
| ->baz() | ||
| ->qux(); | ||
|
|
||
| --- | ||
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.
To avoid the namespace being
Libero\CodingStandard\Libero. (Is there a way to have PHP_CodeSniffer work without having the ruleset's parent directory being the name? It's already defined in the ruleset itself...)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.
Hmm, think we'll have to revert this. The sniff name ends up being
CodingStandard. WhiteSpace.ObjectStaticOperatorSpacingrather than the expectedLibero. WhiteSpace.ObjectStaticOperatorSpacing.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.
What's the decision here in the end? Happy either way