Он сообщает о нескольких оставшихся проблемах в следующей модели, которые я хотел бы исправить.
< pre class="lang-php Prettyprint-override">
Код: Выделить всё
class ArticlePrice extends Model
{
protected $fillable = ['cost_type_id', 'type', 'type_id', 'amount'];
/**
* @var array $with
*/
protected $with = ['types'];
/**
* @return MorphTo
*/
public function types(): MorphTo
{
return $this->morphTo('types', 'type', 'type_id');
}
/**
* @return string
*/
public function getName(): string
{
if ($this->types) {
return $this->type === Article::class ? $this->types->vdm_code : $this->types->name;
}
return '';
}
}
Код: Выделить всё
phpstan: Method App\Models\Environment\CostType\ArticlePrice::types()
return type with generic class Illuminate\Database\Eloquent\Relations\MorphTo
does not specify its types: TRelatedModel, TChildModel
Код: Выделить всё
phpstan: Method App\Models\Environment\CostType\ArticlePrice::types() should return
Illuminate\Database\Eloquent\Relations\MorphTo
but returns Illuminate\Database\Eloquent\Relations\MorphTo.
Когда я делаю вместо этого.
Другая проблема заключается в том, что он не понимает содержимое $types:
Код: Выделить всё
phpstan: Access to an undefined property Illuminate\Database\Eloquent\Model::$name.
phpstan: Access to an undefined property Illuminate\Database\Eloquent\Model::$vdm_code.
Короче, как мне заставить PHPStan понять, как работает мое полиморфное отношение, и как мне заставить его распознавать свойства связанных с полиморфизмом моделей?
Подробнее здесь: https://stackoverflow.com/questions/778 ... l-properti