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

[Bug]: PhpStorm shows trait usage by duplicate helper model class after helper code generation #1115

Open
jfeid opened this issue Dec 5, 2024 · 1 comment

Comments

@jfeid
Copy link

jfeid commented Dec 5, 2024

Bug description

When I am using a Trait to a Model class and fire up "Helper Code Generation", PhpStorm indicates that the Trait is used by the Model class referenced and by the helper model class which is kind of annoying.
Also, when the Trait has a relationship method defined, PhpStorm indicates that the method is overridden in the helper model class, which is misleading.

The Model A class:

<?php

namespace App\Models;

use App\Traits\SampleTrait;
use Illuminate\Database\Eloquent\Model;

class SampleModelA extends Model
{
  use SampleTrait;

  public $timestamps = false;

  protected $fillable = [
    'name',
  ];
}

The Model B class (used for the relation):

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SampleModelB extends Model
{
  public $timestamps = false;

  protected $fillable = [
    'name',
  ];
}

The Trait class:

<?php

namespace App\Traits;

use App\Models\SampleModelB;
use Illuminate\Database\Eloquent\Relations\HasMany;

trait SampleTrait
{
  public function sampleMethod(): string
  {
    return 'Sample method from SampleTrait';
  }

  public function sampleRelation(): HasMany
  {
    return $this->hasMany(SampleModelB::class);
  }
}

How Trait looks in PhpStorm that is used by 2 class, the original and the duplicate helper class:
εικόνα

How Trait's relation method looks in PhpStorm that is falsely overridden in original class:
εικόνα

Plugin version

9.0.0.243

Operating system

Linux

Steps to reproduce

  1. Create a model class SampleModelA
  2. Create a model class SampleModelB
  3. Create a Trait class SampleTrait and use it in the SampleModelA class
  4. Add a HasMany relation method in SampleTrait from SampleModelA to SampleModelB
  5. Fire up Helper Code Generation (Ctrl + Shift + .)

Relevant log output

No response

@adelf
Copy link
Member

adelf commented Dec 10, 2024

Hello. Thank you for posting this.

How Trait looks in PhpStorm that is used by 2 class, the original and the duplicate helper class:

This could be fixed from the PhpStorm side. I'll talk with them.

How Trait's relation method looks in PhpStorm that is falsely overridden in original class:

This is tricky... the plugin overrides it to add some completion, since it's not only HasMany, but a query builder for SampleModelB.

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

No branches or pull requests

2 participants