Skip to content

fix(laravel): retain custom builders after local scopes - #573

Open
shuvroroy wants to merge 3 commits into
PHPantom-dev:mainfrom
shuvroroy:fix/571-custom-builder-scopes
Open

shuvroroy wants to merge 3 commits into
PHPantom-dev:mainfrom
shuvroroy:fix/571-custom-builder-scopes

Conversation

@shuvroroy

@shuvroroy shuvroroy commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Local scopes on a custom Eloquent builder could lose the custom builder or infer a nested type such as PostBuilder<PostBuilder<Post>>|Post, breaking completion and reporting valid returns as type mismatches. Post::query()->published() now retains PostBuilder<Post> with or without ide-helper docblocks.

Scope resolution preserves real builder methods, registered macros, explicit non-builder results, and callback model inference. Regression tests cover inherited and attribute scopes, generic and non-generic builders, completion, hover, and return diagnostics. The Laravel playground includes a matching demo and runtime assertions.

Closes #571

Validation

  • CI latency comparison passed all 100 paired benchmark cases with zero regressions. The go-to-definition, custom-builder, and WordPress cases measured head/base ratios of 1.016, 1.021, and 0.991.
  • Full cargo test suite passed: 20,263 tests passed and 13 were ignored.
  • cargo clippy --fix --allow-dirty -- -D warnings, cargo clippy --all-targets -- -D warnings, cargo fmt, and cargo fmt --check passed.
  • cargo llvm-cov measured 100% coverage of the changed executable production Rust lines (38/38).
  • PHP lint and runtime assertions passed for the PHP, Laravel, Symfony, Yii, WordPress, Drupal, and Tempest playgrounds.
  • Framework analysis reported only Laravel's four intentional demo errors; all other playgrounds reported no errors.
  • The original reproduction no longer reports type_mismatch_return.

The macOS linker emitted an unwind-table size warning during test builds.

Paired local release benchmarks against the PR base, using the same toolchain and normal Criterion sampling:

Case Base PR PR / base
goto_definition_method 27.220 µs 27.267 µs 1.002
custom_builder_completion/custom_builder_deep_inheritance 38.797 µs 38.814 µs 1.000
wordpress_completion/stub_member_get_post 50.999 µs 52.104 µs 1.022

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, examples/)
  • I have updated the config schema (config-schema.json) — not applicable; no configuration changes
  • I have added/updated tests to cover my changes
  • If I used AI tools, I have reviewed what they produced and can explain
    the changes and why they are needed.
  • I have read through any AI-generated text, especially documentation,
    the changelog, and other user-facing content, and removed or corrected
    anything inaccurate, unclear, or unnecessary.

Keep the custom builder and concrete model when a fluent local scope
returns Eloquent Builder. Prefer the actual scope signature over mixed-in
method annotations while preserving real builder methods and macros.

Recover callback model types from custom builder returns using the exact
class name, and preserve explicit return types for other results.

Closes PHPantom-dev#571
Verify hover types, completion, model generics, and return diagnostics
across ide-helper annotations and builders with or without templates.
Cover inherited scopes, attribute scopes, builder overrides, and explicit
non-builder returns from a caller in a different namespace.

Refs PHPantom-dev#571
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@shuvroroy
shuvroroy marked this pull request as ready for review November 13, 2026 13:48
Add convention and attribute scope examples with ide-helper docblocks,
runtime assertions for builder identity and model retention, and an
unreleased changelog entry.

Refs PHPantom-dev#571
@shuvroroy
shuvroroy force-pushed the fix/571-custom-builder-scopes branch from 85dd27d to fdbdc53 Compare November 13, 2026 13:49

This branch has not been deployed

No deployments
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.

Scopes on a custom Eloquent builder resolve to the base Builder

2 participants