diff --git a/Yii2/Sniffs/PHP/DisallowLongArraySyntaxSniff.php b/Yii2/Sniffs/PHP/DisallowLongArraySyntaxSniff.php new file mode 100644 index 0000000..d26d44b --- /dev/null +++ b/Yii2/Sniffs/PHP/DisallowLongArraySyntaxSniff.php @@ -0,0 +1,62 @@ + + * $array = array( + * "foo" => "bar", + * "bar" => "foo", + * ); + * + * + * The short syntax should be used instead: + * + * + * $array = [ + * "foo" => "bar", + * "bar" => "foo", + * ]; + * + * + */ + +class Yii2_Sniffs_PHP_DisallowLongArraySyntaxSniff implements PHP_CodeSniffer_Sniff +{ + /** + * Returns the token types that this sniff is interested in. + * + * @return array(int) + */ + public function register() + { + return array(T_ARRAY); + }//end register() + + /** + * Processes the tokens that this sniff is interested in. + * + * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. + * + * @return void + */ + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + if ($tokens[$stackPtr]['content'] === 'array') { + $error = 'Expected [], found %s'; + $data = array(trim($tokens[$stackPtr]['content'])); + $phpcsFile->addError($error, $stackPtr, '', $data); + } + + }//end process() + +} \ No newline at end of file diff --git a/Yii2/ruleset.xml b/Yii2/ruleset.xml index fc0ad9d..fe19948 100644 --- a/Yii2/ruleset.xml +++ b/Yii2/ruleset.xml @@ -28,11 +28,11 @@ + */i18n/data/* */views/errorHandler/* - */requirements/views/* + */requirements/* - YiiRequirementChecker.php ProfileTarget.php