簡體   English   中英

PhpStorm代碼完成的基礎類

[英]PhpStorm code completion for base classes

我有一個名為BaseSniff的基類,並從中派生了幾個類。

BaseSniff包含類型為$phpcsFile PHP_CodeSniffer_File類型的成員。

在編輯BaseSniff時,使用$this->phpcsFile時PhpStorm將自動完成,但在派生類中則不起作用。

有沒有辦法做到這一點?

這是如何聲明基類的

 /**
 * Base class for all Cardstream code sniffs.
 *
 * The class is constructed from a 
 *     list of tokens to register 
 *     list of code violations to check
 * This class implements the 'process' method of the PHP_CodeSniffer_Sniff 
 * class.
 * Derived classes are able to execute code before the actual processing of 
 * the token via the 'preProcess' method.
 * The code violations are then processed and errors and warnings are reported.
 * 
 * A code violation can stop the processing of the remaining 
 * violations for the file.
 * 
 * @author      Graham Labdon <graham.labdon@cardstream.com>
 */
abstract class BaseSniff implements \PHP_CodeSniffer_Sniff {
    public function process(\PHP_CodeSniffer_File $phpcs_file, $stack_ptr) {
        $this->phpcsFile = $phpcs_file;
    }
    /**
     * Creates the sniff.
     * 
     * Initialises the sniff
     *
     * @param   array       $register           Array of tokens to register
     * @param   array       $code_violations    List of code violations to check
     * @param   string      $sniff_name         Name of sniff
     * @return  void
     */
    public function __construct(
        array $register, 
        array $code_violations, 
        $sniff_name
    ) {
        $this->firstCall = true;
        $this->registeredTokens = $register;
        $this->codeViolations = $code_violations;
        $this->sniffName = $sniff_name; 
    }
}

這是派生類

class MultilineFunctionCallSniff extends BaseSniff {
    public function __construct() {
        $violations = array();

        $register = \PHP_CodeSniffer_Tokens::$functionNameTokens;

        parent::__construct(
            $register,
            $violations,
            "MultilineFunctionCall"
        );
    }   
}

答案是在基類的doc塊中添加一個@property標記

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM