Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect PHPDoc being written to model for BelongsTo relation #1474

Closed
calebdw opened this issue Oct 16, 2023 · 1 comment · Fixed by #1479
Closed

Incorrect PHPDoc being written to model for BelongsTo relation #1474

calebdw opened this issue Oct 16, 2023 · 1 comment · Fixed by #1479
Labels

Comments

@calebdw
Copy link
Contributor

calebdw commented Oct 16, 2023

Versions:

  • ide-helper Version: 2.13.0
  • Laravel Version: 10.x
  • PHP Version: 8.2.x

Description:

Hello!

I'm currently writing the PHPDocs to a few models and I noticed the wrong doc was being generated for the BelongsTo relation (and possibly other relations that return single models):

/** @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\User> $createdByUser */

However, a BelongsTo relation never returns a collection so this instead should be:

/** @property-read null|\App\Models\User $createdByUser */

This is causing PHPStan Level 2 to fail with:

  27     Access to an undefined property Illuminate\Database\Eloquent\Collection<int, App\Models\User>::$name.                                   

when trying to call $model->createdByUser->name

Steps To Reproduce:

  • Create model with BelongsTo relation defined
  • Write PHPDocs to model

Thanks!

@calebdw calebdw added the bug label Oct 16, 2023
@calebdw
Copy link
Contributor Author

calebdw commented Nov 6, 2023

Turns out this was due to the following config:

    'additional_relation_return_types' => [
        'belongsTo' => 'many',
    ],

A developer added this to prevent the model helper file generator from failing when using the Compoships package...however, this broke the types for the BelongsTo relation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant