-
Notifications
You must be signed in to change notification settings - Fork 2
Allow multi-line method chaining #7
Conversation
phpcs.xml.dist
Outdated
| <rule ref="Libero"/> | ||
|
|
||
| <file>src/</file> | ||
| <file>Libero/</file> |
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.ObjectStaticOperatorSpacing rather than the expected Libero. 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
| <?php | ||
|
|
||
| $foo->bar($arg1); | ||
| $foo->bar($arg1)->baz(); |
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.
Would rather these became multiline.
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.
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($arg1)->baz(); | ||
|
|
||
| $foo | ||
| ->bar( |
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.
Would rather not keep the newline.
| ->baz( | ||
| $arg1, | ||
| $arg2 | ||
| ); |
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.
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 comment
The 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 comment
The 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 comment
The 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 comment
The 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):
- add a new call
- remove a call
- change the order of calls
- swap two calls
become operations that only involve full lines
|
@giorgiosironi Happy to merge? I'd like to update this to put the semi-colon on the next line, but will need a custom sniff I believe so will do it later. |
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.
As per my latest comments, all reasonable
I can't see sniffs available anywhere that support multi-line method chaining (refs libero/schemas#6 (comment)).
This is an imperfect attempt to support it, without having to write dedicated sniffs.