Plugin-php: Chained method arguments split up unnecessarily

Created on 23 Sep 2020  路  3Comments  路  Source: prettier/plugin-php

@prettier/plugin-php v0.14.3
Playground link

Input:

<?php

$query
    ->selectRaw('count(*) as `count`, date_format(`created_at`, "%Y-%m-01") as `date`')
    ->from('quote_searches')
    ->where('account_id', $accountId)
    ->where('created_at', '>=', Carbon::now()->startOfMonth()->subMonths($months))
    ->groupBy('date');

Output:

<?php

$query
    ->selectRaw('count(*) as `count`, date_format(`created_at`, "%Y-%m-01") as `date`')
    ->from('quote_searches')
    ->where('account_id', $accountId)
    ->where(
        'created_at',
        '>=',
        Carbon::now()
            ->startOfMonth()
            ->subMonths($months),
    )
    ->groupBy('date');

I'm specifically referring to the second where call. Prettier leaves this alone, so I assume it must be caused by the php plugin. It's behaving as if the print-width is much less. (I use 120, but this even fits in 80.)

Prettier 2.1.2
Playground link

--arrow-parens avoid
--parser babel
--print-width 120
--single-quote
--tab-width 4
--trailing-comma all

Input:

$query
    .selectRaw('count(*) as `count`, date_format(`created_at`, "%Y-%m-01") as `date`')
    .from('quote_searches')
    .where('account_id', $accountId)
    .where('created_at', '>=', Carbon.now().startOfMonth().subMonths($months))
    .groupBy('date');

Output:

$query
    .selectRaw('count(*) as `count`, date_format(`created_at`, "%Y-%m-01") as `date`')
    .from('quote_searches')
    .where('account_id', $accountId)
    .where('created_at', '>=', Carbon.now().startOfMonth().subMonths($months))
    .groupBy('date');

enhancement

Most helpful comment

Good idea

All 3 comments

Same in latest version. Looks bad, especially in IF statements.

I totally agree. Potentially, we could check how Prettier for JS handles this and port some of the logic to the plugin. cc @evilebottnawi

Good idea

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikulis picture nikulis  路  5Comments

mgrip picture mgrip  路  3Comments

czosel picture czosel  路  5Comments

alexander-akait picture alexander-akait  路  3Comments

aboyton picture aboyton  路  4Comments