Plugin-php: First object method call on the same line

Created on 10 May 2018  路  5Comments  路  Source: prettier/plugin-php

Hi everyone, my team is using mehtod chaining with the first method call on the same line:

            $timelineClientBuilder->setUserId($userId)
                ->setPagination(static::PER_PAGE_QUERY, $page)
                ->setEventType($eventType)
                ->setDateRange($startDate, $endDate);

but prettier outputs this like the following:

            $timelineClientBuilder
                ->setUserId($userId)
                ->setPagination(static::PER_PAGE_QUERY, $page)
                ->setEventType($eventType)
                ->setDateRange($startDate, $endDate);

is there already a way to tells prettier to adopt the first formatting? Or is there a workaround for this? Thanks in advance

Most helpful comment

I agree prettier is formatting it correctly. Not a bug and not significant enough for an option. Method chaining should drop every action to new line including first. This is how DOM attributes are handled as well.

/close

All 5 comments

Bug, Thanks!
Example from js: Expected

Feel free PR with fix it.

@evilebottnawi the JS example you listed prints the same as our plugin?

@mgrip oh yes, it is not bug, sorry, tired
@bertuz it is expected behaviour

@bertuz you can use phpcs or other codemodes utils for it for your team. Each -> on new line looks better and easy to read

I agree prettier is formatting it correctly. Not a bug and not significant enough for an option. Method chaining should drop every action to new line including first. This is how DOM attributes are handled as well.

/close

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hawkrives picture hawkrives  路  3Comments

sgruetter picture sgruetter  路  5Comments

czosel picture czosel  路  6Comments

alexander-akait picture alexander-akait  路  3Comments

alexander-akait picture alexander-akait  路  5Comments