2016-09-28 4 views
0

그래서 나는 다음과 같이 같은 특성이 동일하는 PHPDoc @return 유형 (PhpStorm 10.0.4에서) 클래스 필드 유형

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; 
    } 
} 

그리고 내가 원하는 것은 그 방법을 어떻게 든 정의하는 것입니다.(특성 또는 인터페이스에서) 유형은 FixedAsset입니다. 그러나 새로 작성하는 모든 새() 클래스 (리포지토리 인터페이스를 구현하는 클래스)에 대해 항상 작동해야합니다.

나는 어떻게 든 가능 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

이 작동하지 않습니다.

그에 대한 제안 사항에 대해 알려 주시면 감사하겠습니다.

+0

가장 좋은 ** 내가 ** 지금 생각할 수있는 것은 그것을'@의 method'를 사용하여 "재 선언"하는 것입니다 올바른 반환 유형 - 이것이 작동하는지 확인하십시오. – LazyOne

+0

좋아요! 얼마나 간단 ... 그게 내가 필요한거야. 고맙습니다. 이 답변을 게시하여 해결책으로 표시 할 수 있습니다. –

답변

1

내가 생각할 수있는 유일한 해결책은 바로 FixedAssetRepository 클래스의 PHPDoc 주석에 올바른 find() 메서드와 올바른 서명 (반환 유형)을 사용하는 것입니다. PHPDoc 솔루션이기 때문에 런타임 중에 PHP 코드에 아무런 영향을 미치지 않습니다.

샘플 코드 :

/** 
* @method FixedAsset find(int $id, array $columns) Find a model by its primary key 
*/ 
class FixedAssetRepository implements Repository 
{ 
... 

@method 태그에 대한 자세한 - https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#711-method