How can i generate Laravel macros as dynamic instead of static methods?

1
open
FunctionDJ
FunctionDJ
Posted 1 month ago

How can i generate Laravel macros as dynamic instead of static methods? #1254

Versions:

  • ide-helper Version: 2.10
  • PHP Version: 8.0.8

Question:

I have a Laravel macro like this:

Collection::macro("mapToJSON", fn() => (
  $this->map(fn($entry) => json_encode($entry))
));

But when i generate _ide_helper.php, it contains the following, which is seen by PHPStan as an error when i call it dynamically:

class Collection {
  /**
   * @see \App\Providers\AppServiceProvider::boot()
   * @static 
   */ 
  public static function mapToJSON()
  {
    return \Illuminate\Support\Collection::mapToJSON();
  }
  // ...

How can i make ide-helper generate the method as dynamic and not static?

FunctionDJ
FunctionDJ
Created 1 month ago

Addition: Dynamic methods like \Illuminate\Database\Query\Builder::join are also generated as static when using ide-helper:generate, which also results in an error with phpstan.

To be clear, the issue is not phpstan, it's that the resulting signature is incorrect, which could also result in issues with other linters.