pint icon indicating copy to clipboard operation
pint copied to clipboard

False syntax error on PHP 8.4 hooks

Open allanmcarvalho opened this issue 10 months ago • 2 comments

Pint Version

1.20

PHP Version

8.4.3

Description

Laravel Pint throws a false syntax error when in fact code works.

Steps To Reproduce

PHP Hooks error.

This is a valid php code, but fail on Pint

class Example {

    public ?int $intBoolean {
        get => $this->booleanValue === null ? null : (int) $this->booleanValue;
    }

    public function __construct(
        public ?boolean $booleanValue
    ) {}
}
   FAIL   ............................................................................................................................................. 217 files, 1 error  
  ! Example.php.                                                                                          Parse error: syntax error, unexpected token "public" on line 24.  
      1▕  class Example {
      2▕ 
      3▕     public ?int $intBoolean {
  ➜   4▕         get => $this->booleanValue === null ? null : (int) $this->booleanValue;
      5▕     }
      6▕ 
      7▕     public function __construct(
      8▕         public ?boolean $booleanValue

This is a valid code too, but pass.

class Example {

    public ?int $intBoolean {
        get => ($this->booleanValue === null ? null : (int) $this->booleanValue);
    }

    public function __construct(
        public ?boolean $booleanValue
    ) {}
}

allanmcarvalho avatar Feb 07 '25 14:02 allanmcarvalho

Pending https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/milestone/173

crynobone avatar Feb 08 '25 01:02 crynobone

I don't know if that's enough. However, CS Fixer (v3.75) has published several improvements since then. Dependency upgrades could benefit from this.

julien-boudry avatar Apr 01 '25 09:04 julien-boudry