所以我有一個性狀像如下:PHPDoc的@返回類型等於類字段類型(在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;
}
}
我在找的是定義某種方式,該方法find
(在特徵或界面中)是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
太棒了!多麼簡單...這就是我需要的。非常感謝你。您可以發佈這個答案,我可以將其標記爲解決方案。 –