plugin icon indicating copy to clipboard operation
plugin copied to clipboard

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

Open jfeid opened this issue 1 year ago • 1 comments

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

jfeid avatar Dec 05 '24 10:12 jfeid

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.

adelf avatar Dec 10 '24 14:12 adelf