laravel/pint

Formatting results in Implements being commented out

FelixTHG opened this issue ยท 5 comments

Pint Version

1.13.6

PHP Version

8.2.5

Description

We have a validation rule that implements
use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\Rule;

we had commented out that the rule should implement Illuminate\Contracts\Validation\ValidatorAwareRule at the end of the implements line; like so:

class E164PhoneNumber implements DataAwareRule, Rule //, ValidatorAwareRule

when we format this file using pint fresh as is, it puts the "Rule" into the comment, breaking our validation.

Steps To Reproduce

Install pint on a laravel 10 project
used
composer require laravel/pint

create a rule file like so:

<?php

namespace App\Rules;

use App\Helpers\StringHelper;
use Illuminate\Contracts\Validation\DataAwareRule;
// use Illuminate\Contracts\Validation\ValidatorAwareRule;
use Illuminate\Contracts\Validation\Rule;

class E164PhoneNumber implements DataAwareRule, Rule //, ValidatorAwareRule
{
    public string $strippedPhone;

    public function passes($attribute, $value)
    {
        if (! isset($this->strippedPhone)) {
            return preg_match('/^\d{8,15}$/', $value);
        }

        return preg_match('/^\d{8,15}$/', $this->strippedPhone);
    }

    public function message()
    {
        return trans('validation.e164_phone_number');
    }

    public function setData($data): void
    {
        if (isset($data['phone'])) {
            $this->strippedPhone = StringHelper::Remove47FromPhone($data['phone']);
        }
    }
}

use pint to format the file by running ./vendor/bin/pint

In a fresh Laravel 10 Application with the example code put into "app/Rules/E164PhoneNumber.php" and then running the command vendor/bin/pint nothing happens.

Can you provide an example repository? Or do you have custom rules in your pint.json

Note: I use PHP 8.2.11 instead of PHP 8.2.5 (on MacOS)

Sorry, I guess I was a little quick.
you will have to change your class defining line to be like this:
class E164PhoneNumber implements Rule, DataAwareRule //, ValidatorAwareRule

Having it like so, gives me the bug, after doing a fresh laravel install (was in a more complex project earlier)

using the changed code from you, I can confirm the issue.

using this pint.json

{
    "rules": {
        "ordered_interfaces": false
    }
}

you can for now disable this behaviour, but this is an issue with PHP-CS-Fixer where you should report the problem.

Thanks @Jubeki

@FelixTHG feel free to report this to PHP CS Fixer ๐Ÿ‘

Fix released by Fixer team ๐ŸŽ‰

for cross reference: PHP-CS-Fixer/PHP-CS-Fixer#7463 (comment)

btw folks, in some previous conversations we got lot of involvement of Laravel community pointing not big enough discussion, alignments etc - root cause is limited pool of contributors. Please, take it as good opportunity here - in future cases when you go deep dive to figure out which rule is having the problem, you may not only delegate the issue to core repo, but also contribute to repo with the fix ๐Ÿ™๐Ÿป