Skip to content

Conversation

@KentarouTakeda
Copy link
Contributor

Summary

Overview

Currently, Laravel IDE Helper does not generate extends declarations for Macroable classes in their DocBlock. For example, Illuminate\Http\Request extends Symfony\Component\HttpFoundation\Request, but this inheritance is missing in the generated helper file.

As a result, tools like PHPStan or PHP Intelephense sonetimes fail to detect the inherited methods and constants, triggering errors or warnings such as:

use Illuminate\Http\Request;

function foo(Request $request)
{
    $request->isMethod(Request::METHOD_GET);
}
Access to undefined constant Illuminate\Http\Request::METHOD_GET
Call to an undefined method Illuminate\Http\Request::isMethod()

What this PR Does

  • Adds an extends declaration to the DocBlock for Macroable classes so that PHPStan, Intelephense, and other tools can properly recognize inherited methods and constants.
  • Facades are always omitted, since they do not truly extend the underlying class but rather proxy calls to an actual instance.

Additional Notes

  • In a default Laravel configuration, Illuminate\Http\Request is effectively the only Macroable class that relies on a parent class. Without an extends declaration, any inherited methods or constants remain hidden from static analysis.
  • After applying this PR, the generated DocBlock for Illuminate\Http\Request gains the extends line:
22382c22382
<     class Request {
---
>     class Request extends \Symfony\Component\HttpFoundation\Request {

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • Existing tests have been adapted and/or new tests have been added
  • Code style has been fixed via composer fix-style

@KentarouTakeda KentarouTakeda force-pushed the add-extends-declaration-to-macroable-docblock branch from 2430405 to 83b9311 Compare February 11, 2025 07:02
@barryvdh barryvdh merged commit 09623f2 into barryvdh:master Feb 22, 2025
17 checks passed
@KentarouTakeda
Copy link
Contributor Author

@barryvdh
Hello! Are you planning to release a new version with this fix?

Both versions seem to work fine, this fix and the one on top of the current dev-master. I've tried both on a ~100k line project I work on. I was able to remove over 100 instances of @phpstan-ignore and everything worked fine!!

Thanks for the great tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants