Type indicator => suggested partial error phrase. */ protected $initialValueTypes = [ 'const' => 'constants', 'property' => 'class properties', 'staticvar' => 'static variables', 'default' => 'default parameter values', ]; /** * Do a version check to determine if this sniff needs to run at all. * * @since 8.2.0 * * @return bool */ protected function bowOutEarly() { return (ScannedCode::shouldRunOnOrBelow('5.2') === false); } /** * Process a token which has an initial value. * * @since 10.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the variable/constant name token * in the stack passed in $tokens. * @param int $start The stackPtr to the start of the initial value. * @param int $end The stackPtr to the end of the initial value. * This will normally be a comma or semi-colon. * @param string $type The "type" of initial value declaration being examined. * The type will match one of the keys in the * `AbstractInitialValueSniff::$initialValueTypes` property. * * @return void */ protected function processInitialValue(File $phpcsFile, $stackPtr, $start, $end, $type) { $hasHeredoc = $phpcsFile->findNext(\T_START_HEREDOC, $start, $end); if ($hasHeredoc === false) { // Initial value doesn't contain a heredoc, nothing to do. return; } $error = static::ERROR_PHRASE; $errorCode = 'Found'; $phrase = ''; $codeSnippet = \trim(GetTokensAsString::noComments($phpcsFile, $stackPtr, $hasHeredoc)); if (isset($this->initialValueTypes[$type]) === true) { $errorCode = MessageHelper::stringToErrorCode($type) . 'Found'; $phrase = $this->initialValueTypes[$type]; } $data = [$phrase, $codeSnippet]; $phpcsFile->addError($error, $stackPtr, $errorCode, $data); } }