Plugin-php: Breaking change: splits long lines in the middle of a reference chain

Created on 13 Mar 2018  路  7Comments  路  Source: prettier/plugin-php

However, this may fix itself after #210 is fixed.

Input:

<?php
class test {
    public function test_method() {
        $customer = (object) [ 'name' => 'Bob' ];
        $job = (object) [ 'customer' => $customer ];

        return "The customer for that job, {$job->customer->name} has an error that shows up after the line gets waaaaay toooo long.";
    }
}

Output

<?php
class test
{
    public function test_method()
    {
        $customer = (object) ['name' => 'Bob'];
        $job = (object) ['customer' => $customer];

        return "The customer for that job, $job->customer->
            name has an error that shows up after the line gets waaaaay toooo long.";
    }
}

Expected Output:

<?php
class test
{
    public function test_method()
    {
        $customer = (object) ['name' => 'Bob'];
        $job = (object) ['customer' => $customer];

        return "The customer for that job, {$job->customer->name}
            has an error that shows up after the line gets waaaaay toooo long.";
    }
}
bug

All 7 comments

Just checked this against the latest code base - I was on an old version. Still happens with the current updates.

We also lose curly quotes :disappointed:

@evilebottnawi yep, see #6

@cmancone can you check this again with the most recent version of master? I believe it should have been fixed with #251

@mgrip The results here are mixed. The curly braces now stay, so this is no longer a breaking change, but the newline is still split in the middle of the chain:

class test
{
    public function test_method()
    {
        $customer = (object) ['name' => 'Bob'];
        $job = (object) ['customer' => $customer];

        return "The customer for that job, {$job->customer->
            name} has an error that shows up after the line gets waaaaay toooo long.";
    }
}

When I first saw this I assumed that it was a breaking change, but it turns out no: this is perfectly valid PHP that is semantically identical to the input. Therefore, this does now work. I personally think it is a bit unusual to split in the middle of a variable chain like that, but that is a matter of personal preference, and this certainly isn't a high-priority issue anymore (if it is an issue at all).

Got it - yes I agree. I'm going to leave open for now but remove the high-priority label. Thanks for looking into it!

added tests in #401 to confirm this is fixed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

em4nl picture em4nl  路  5Comments

nikulis picture nikulis  路  5Comments

czosel picture czosel  路  5Comments

czosel picture czosel  路  6Comments

alexander-akait picture alexander-akait  路  3Comments