[英]PhpStorm code completion for base classes
I have a base class named BaseSniff
and have derived several classes from this. 我有一个名为
BaseSniff
的基类,并从中派生了几个类。
BaseSniff
contains a member of type PHP_CodeSniffer_File
called $phpcsFile
. BaseSniff
包含类型为$phpcsFile
PHP_CodeSniffer_File
类型的成员。
When editing BaseSniff
PhpStorm will autocomplete when using $this->phpcsFile
but in the derived classes this does not work. 在编辑
BaseSniff
时,使用$this->phpcsFile
时PhpStorm将自动完成,但在派生类中则不起作用。
Is there a way of achieving this? 有没有办法做到这一点?
Here is how the base class is declared 这是如何声明基类的
/**
* 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;
}
}
And here is a derived class 这是派生类
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.