[Bug]: PhpStorm shows trait usage by duplicate helper model class after helper code generation
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
- Create a model class SampleModelA
- Create a model class SampleModelB
- Create a Trait class SampleTrait and use it in the SampleModelA class
- Add a HasMany relation method in SampleTrait from SampleModelA to SampleModelB
- Fire up Helper Code Generation (Ctrl + Shift + .)
Relevant log output
No response
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.