に等しいだから私は以下のようにのような特性を持っている:たPHPDoc @returnタイプは(PhpStorm 10.0.4で)クラスフィールドタイプ
trait RepositoryTrait
{
/**
* Find a model by its primary key.
*
* @param int $id
* @param array $columns
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function find($id, array $columns = ['*'])
{
return $this->query()->find($id, $columns);
}
}
およびインタフェース:
interface Repository
{
/**
* Find a model by its primary key.
*
* @param int $id
* @param array $columns
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function find($id, array $columns = ['*']);
}
と私が持っていますリポジトリクラスのような:
class FixedAssetRepository implements Repository
{
use RepositoryTrait;
/**
* FixedAsset model.
*
* @var FixedAsset
*/
protected $model;
/**
* Repository constructor.
*
* @param FixedAsset $fixedAsset
*/
public function __construct(FixedAsset $fixedAsset)
{
$this->model = $fixedAsset;
}
}
と私は何とかそのメソッド0を定義することです(特性またはインターフェイス)のタイプはFixedAsset
ですが、これは(Repositoryインターフェイスを実装する)新しいRepository
クラスごとに常に機能するはずです。私はPhpStorm 10.0.4
タイプヒンティングのためにそれを必要とする
は、それが何らかの形で可能ですか?
だから、結果は、私がどこかで呼び出すときすなわち:
$fixedAsset = $this->fixedAssetRepositry->find($id);
PhpStormが$fixedAsset
がクラスFixedAsset
ちょうど\Illuminate\Database\Eloquent\Model
(今そのように働いている)ではないの対象であることを知っているだろうということでなければなりません。
だから私は、インターフェイスに好きなもの必要がある(または形質を?):
/**
* Find a model by its primary key.
*
* @param int $id
* @param array $columns
* @return $this->model
*/
public function find($id, array $columns = ['*']);
もちろん@return $this->model
のは動作しません。
私はそのことに関するご意見をいただければ幸いです。
最高**私は**今考えることができ、 'の@ method'を使用することですし、それを "再宣言"正しい戻り値の型 - これが機能するかどうかを確認してください。 – LazyOne
素晴らしい!どのように単純な...それは私が必要なものです。どうもありがとうございました。この回答を投稿して解決策としてマークすることができます。 –