Unverified Commit c85aae11 authored by Klaus Purer's avatar Klaus Purer Committed by GitHub
Browse files

style(PHPCS): Apply newest version of PHPCS cosing standards (#2734539)

parent d28326dd
Loading
Loading
Loading
Loading
+33 −33
Original line number Diff line number Diff line
@@ -35,10 +35,10 @@ class ArraySniff implements Sniff
     */
    public function register()
    {
        return array(
        return [
            T_ARRAY,
            T_OPEN_SHORT_ARRAY,
               );
        ];

    }//end register()

@@ -57,33 +57,33 @@ class ArraySniff implements Sniff
        $tokens = $phpcsFile->getTokens();

        // Support long and short syntax.
        $parenthesis_opener = 'parenthesis_opener';
        $parenthesis_closer = 'parenthesis_closer';
        $parenthesisOpener = 'parenthesis_opener';
        $parenthesisCloser = 'parenthesis_closer';
        if ($tokens[$stackPtr]['code'] === T_OPEN_SHORT_ARRAY) {
            $parenthesis_opener = 'bracket_opener';
            $parenthesis_closer = 'bracket_closer';
            $parenthesisOpener = 'bracket_opener';
            $parenthesisCloser = 'bracket_closer';
        }

        // Sanity check: this can sometimes be NULL if the array was not correctly
        // parsed.
        if ($tokens[$stackPtr][$parenthesis_closer] === null) {
        if ($tokens[$stackPtr][$parenthesisCloser] === null) {
            return;
        }

        $lastItem = $phpcsFile->findPrevious(
            Tokens::$emptyTokens,
            ($tokens[$stackPtr][$parenthesis_closer] - 1),
            ($tokens[$stackPtr][$parenthesisCloser] - 1),
            $stackPtr,
            true
        );

        // Empty array.
        if ($lastItem === $tokens[$stackPtr][$parenthesis_opener]) {
        if ($lastItem === $tokens[$stackPtr][$parenthesisOpener]) {
            return;
        }

        // Inline array.
        $isInlineArray = $tokens[$tokens[$stackPtr][$parenthesis_opener]]['line'] === $tokens[$tokens[$stackPtr][$parenthesis_closer]]['line'];
        $isInlineArray = $tokens[$tokens[$stackPtr][$parenthesisOpener]]['line'] === $tokens[$tokens[$stackPtr][$parenthesisCloser]]['line'];

        // Check if the last item in a multiline array has a "closing" comma.
        if ($tokens[$lastItem]['code'] !== T_COMMA && $isInlineArray === false
@@ -91,7 +91,7 @@ class ArraySniff implements Sniff
            && $tokens[($lastItem + 1)]['code'] !== T_CLOSE_SHORT_ARRAY
            && isset(Tokens::$heredocTokens[$tokens[$lastItem]['code']]) === false
        ) {
            $data = array($tokens[$lastItem]['content']);
            $data = [$tokens[$lastItem]['content']];
            $fix  = $phpcsFile->addFixableWarning('A comma should follow the last multiline array item. Found: %s', $lastItem, 'CommaLastItem', $data);
            if ($fix === true) {
                $phpcsFile->fixer->addContent($lastItem, ',');
@@ -103,10 +103,10 @@ class ArraySniff implements Sniff
        if ($isInlineArray === true) {
            // Check if this array contains at least 3 elements and exceeds the 80
            // character line length.
            if ($tokens[$tokens[$stackPtr][$parenthesis_closer]]['column'] > 80) {
                $comma1 = $phpcsFile->findNext(T_COMMA, ($stackPtr + 1), $tokens[$stackPtr][$parenthesis_closer]);
            if ($tokens[$tokens[$stackPtr][$parenthesisCloser]]['column'] > 80) {
                $comma1 = $phpcsFile->findNext(T_COMMA, ($stackPtr + 1), $tokens[$stackPtr][$parenthesisCloser]);
                if ($comma1 !== false) {
                    $comma2 = $phpcsFile->findNext(T_COMMA, ($comma1 + 1), $tokens[$stackPtr][$parenthesis_closer]);
                    $comma2 = $phpcsFile->findNext(T_COMMA, ($comma1 + 1), $tokens[$stackPtr][$parenthesisCloser]);
                    if ($comma2 !== false) {
                        $error = 'If the line declaring an array spans longer than 80 characters, each element should be broken into its own line';
                        $phpcsFile->addError($error, $stackPtr, 'LongLineDeclaration');
@@ -146,15 +146,15 @@ class ArraySniff implements Sniff

        $lineStart = $stackPtr;
        // Iterate over all lines of this array.
        while ($lineStart < $tokens[$stackPtr][$parenthesis_closer]) {
        while ($lineStart < $tokens[$stackPtr][$parenthesisCloser]) {
            // Find next line start.
            $newLineStart = $lineStart;
            $current_line = $tokens[$newLineStart]['line'];
            while ($current_line >= $tokens[$newLineStart]['line']) {
            $currentLine  = $tokens[$newLineStart]['line'];
            while ($currentLine >= $tokens[$newLineStart]['line']) {
                $newLineStart = $phpcsFile->findNext(
                    Tokens::$emptyTokens,
                    ($newLineStart + 1),
                    ($tokens[$stackPtr][$parenthesis_closer] + 1),
                    ($tokens[$stackPtr][$parenthesisCloser] + 1),
                    true
                );

@@ -166,32 +166,32 @@ class ArraySniff implements Sniff
                // run.
                if ($tokens[$newLineStart]['code'] === T_ARRAY) {
                    $newLineStart = $tokens[$newLineStart]['parenthesis_closer'];
                    $current_line = $tokens[$newLineStart]['line'];
                    $currentLine  = $tokens[$newLineStart]['line'];
                }

                // Short array syntax: Skip nested arrays, they are checked in a next
                // run.
                if ($tokens[$newLineStart]['code'] === T_OPEN_SHORT_ARRAY) {
                    $newLineStart = $tokens[$newLineStart]['bracket_closer'];
                    $current_line = $tokens[$newLineStart]['line'];
                    $currentLine  = $tokens[$newLineStart]['line'];
                }

                // Nested structures such as closures: skip those, they are checked
                // in other sniffs. If the conditions of a token are different it
                // means that it is in a different nesting level.
                if ($tokens[$newLineStart]['conditions'] !== $tokens[$stackPtr]['conditions']) {
                    $current_line++;
                    $currentLine++;
                }
            }//end while

            if ($newLineStart === $tokens[$stackPtr][$parenthesis_closer]) {
            if ($newLineStart === $tokens[$stackPtr][$parenthesisCloser]) {
                // End of the array reached.
                if ($tokens[$newLineStart]['column'] !== $firstLineColumn) {
                    $error = 'Array closing indentation error, expected %s spaces but found %s';
                    $data  = array(
                              $firstLineColumn - 1,
                              $tokens[$newLineStart]['column'] - 1,
                             );
                    $data  = [
                        ($firstLineColumn - 1),
                        ($tokens[$newLineStart]['column'] - 1),
                    ];
                    $fix   = $phpcsFile->addFixableError($error, $newLineStart, 'ArrayClosingIndentation', $data);
                    if ($fix === true) {
                        if ($tokens[$newLineStart]['column'] === 1) {
@@ -216,7 +216,7 @@ class ArraySniff implements Sniff
                // Skip lines in nested structures such as a function call within an
                // array, no defined coding standard for those.
                $innerNesting = empty($tokens[$newLineStart]['nested_parenthesis']) === false
                    && end($tokens[$newLineStart]['nested_parenthesis']) < $tokens[$stackPtr][$parenthesis_closer];
                    && end($tokens[$newLineStart]['nested_parenthesis']) < $tokens[$stackPtr][$parenthesisCloser];
                // Skip lines that are part of a multi-line string.
                $isMultiLineString = $tokens[($newLineStart - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
                    && substr($tokens[($newLineStart - 1)]['content'], -1) === $phpcsFile->eolChar;
@@ -224,10 +224,10 @@ class ArraySniff implements Sniff
                $nowDoc = isset(Tokens::$heredocTokens[$tokens[$newLineStart]['code']]);
                if ($innerNesting === false && $isMultiLineString === false && $nowDoc === false) {
                    $error = 'Array indentation error, expected %s spaces but found %s';
                    $data  = array(
                              $expectedColumn - 1,
                              $tokens[$newLineStart]['column'] - 1,
                             );
                    $data  = [
                        ($expectedColumn - 1),
                        ($tokens[$newLineStart]['column'] - 1),
                    ];
                    $fix   = $phpcsFile->addFixableError($error, $newLineStart, 'ArrayIndentation', $data);
                    if ($fix === true) {
                        if ($tokens[$newLineStart]['column'] === 1) {
+8 −8
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ class ClassDefinitionNameSpacingSniff implements Sniff
     *
     * @var array
     */
    public $supportedTokenizers = array('CSS');
    public $supportedTokenizers = ['CSS'];


    /**
@@ -40,7 +40,7 @@ class ClassDefinitionNameSpacingSniff implements Sniff
     */
    public function register()
    {
        return array(T_OPEN_CURLY_BRACKET);
        return [T_OPEN_CURLY_BRACKET];

    }//end register()

@@ -66,11 +66,11 @@ class ClassDefinitionNameSpacingSniff implements Sniff

        // Find the first blank line before this opening brace, unless we get
        // to another style definition, comment or the start of the file.
        $endTokens  = array(
        $endTokens  = [
            T_OPEN_CURLY_BRACKET  => T_OPEN_CURLY_BRACKET,
            T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
            T_OPEN_TAG            => T_OPEN_TAG,
                      );
        ];
        $endTokens += Tokens::$commentTokens;

        $foundContent = false;
@@ -95,7 +95,7 @@ class ClassDefinitionNameSpacingSniff implements Sniff
            if ($tokens[$i]['code'] === T_WHITESPACE
                && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false
                && isset($endTokens[$tokens[($i - 1)]['code']]) === false
                && in_array($tokens[($i - 1)]['code'], array(T_WHITESPACE, T_COMMA)) === false
                && in_array($tokens[($i - 1)]['code'], [T_WHITESPACE, T_COMMA]) === false
            ) {
                $error = 'Selectors must be on a single line';
                $fix   = $phpcsFile->addFixableError($error, $i, 'SeletorSingleLine');
+6 −6
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class ColourDefinitionSniff implements Sniff
     *
     * @var array
     */
    public $supportedTokenizers = array('CSS');
    public $supportedTokenizers = ['CSS'];


    /**
@@ -39,7 +39,7 @@ class ColourDefinitionSniff implements Sniff
     */
    public function register()
    {
        return array(T_COLOUR);
        return [T_COLOUR];

    }//end register()

@@ -61,10 +61,10 @@ class ColourDefinitionSniff implements Sniff
        $expected = strtolower($colour);
        if ($colour !== $expected) {
            $error = 'CSS colours must be defined in lowercase; expected %s but found %s';
            $data  = array(
            $data  = [
                $expected,
                $colour,
                     );
            ];
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NotLower', $data);
            if ($fix === true) {
                $phpcsFile->fixer->replaceToken($stackPtr, $expected);
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ class ClassCreateInstanceSniff implements Sniff
     */
    public function register()
    {
        return array(T_NEW);
        return [T_NEW];

    }//end register()

+9 −9
Original line number Diff line number Diff line
@@ -33,11 +33,11 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff
     */
    public function register()
    {
        return array(
        return [
            T_CLASS,
            T_INTERFACE,
            T_TRAIT,
               );
        ];

    }//end register()

@@ -54,7 +54,7 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff
    public function process(File $phpcsFile, $stackPtr)
    {
        $tokens    = $phpcsFile->getTokens();
        $errorData = array(strtolower($tokens[$stackPtr]['content']));
        $errorData = [strtolower($tokens[$stackPtr]['content'])];

        if (isset($tokens[$stackPtr]['scope_opener']) === false) {
            $error = 'Possible parse error: %s missing opening or closing brace';
@@ -106,7 +106,7 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff

        if ($length !== 1) {
            $error = 'Expected 1 space before opening brace; found %s';
            $data  = array($length);
            $data  = [$length];
            $fix   = $phpcsFile->addFixableError($error, $openingBrace, 'SpaceBeforeBrace', $data);
            if ($fix === true) {
                if ($length === 0) {
@@ -152,7 +152,7 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff
            && isset(Tokens::$commentTokens[$tokens[$prevContent]['code']]) === false
        ) {
            $error = 'The closing brace for the %s must have an empty line before it';
            $data  = array($tokens[$stackPtr]['content']);
            $data  = [$tokens[$stackPtr]['content']];
            $fix   = $phpcsFile->addFixableError($error, $closeBrace, 'CloseBraceAfterBody', $data);

            if ($fix === true) {
@@ -175,7 +175,7 @@ class ClassDeclarationSniff extends PSR2ClassDeclarationSniff
        ) {
            $type  = strtolower($tokens[$stackPtr]['content']);
            $error = 'Closing %s brace must be on a line by itself';
            $data  = array($tokens[$stackPtr]['content']);
            $data  = [$tokens[$stackPtr]['content']];
            $phpcsFile->addError($error, $closeBrace, 'CloseBraceSameLine', $data);
        }

Loading