Unverified Commit 70b03b11 authored by Mitch Portier's avatar Mitch Portier Committed by GitHub
Browse files

fix(FullyQualifiedNamespace): Fixer: Insert correct empty lines after file doc...

fix(FullyQualifiedNamespace): Fixer: Insert correct empty lines after file doc comment (#3109636 by Arkener)
parent 15f64e99
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ class FullyQualifiedNamespaceSniff implements Sniff

        if ($fix === true) {
            $fullName = $phpcsFile->getTokensAsString(($before + 1), ($after - 1 - $before));
            $fullName = trim($fullName, '\ ');
            $fullName = trim($fullName, "\ \n");

            $phpcsFile->fixer->beginChangeset();

@@ -131,11 +131,12 @@ class FullyQualifiedNamespaceSniff implements Sniff
                    $fileComment = $phpcsFile->findNext(T_WHITESPACE, ($beginning + 1), null, true);
                    if ($tokens[$fileComment]['code'] === T_DOC_COMMENT_OPEN_TAG) {
                        $beginning = $tokens[$fileComment]['comment_closer'];
                    }

                        $phpcsFile->fixer->addContent($beginning, "\n\nuse $fullName;\n");
                    } else {
                        $phpcsFile->fixer->addContent($beginning, "use $fullName;\n");
                    }
                }
            }

            $phpcsFile->fixer->endChangeset();
        }//end if
+17 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Example file.
 *
 * Disable commenting rules to check if use statements are placed correctly
 * without them.
 * phpcs:disable Drupal.Commenting
 */

/**
 * Foo function.
 */
function foo() {
  \Foo\Bar::load();
}
+19 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Example file.
 *
 * Disable commenting rules to check if use statements are placed correctly
 * without them.
 * phpcs:disable Drupal.Commenting
 */

use Foo\Bar;

/**
 * Foo function.
 */
function foo() {
  Bar::load();
}
+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
        switch ($testFile) {
        case 'FullyQualifiedNamespaceUnitTest.inc':
            return [3 => 1];
        case 'FullyQualifiedNamespaceUnitTest.1.inc':
            return [16 => 1];
        }

        return [];
@@ -58,6 +60,7 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
    {
        return [
            __DIR__.'/FullyQualifiedNamespaceUnitTest.inc',
            __DIR__.'/FullyQualifiedNamespaceUnitTest.1.inc',
            __DIR__.'/FullyQualifiedNamespaceUnitTest.api.php',
        ];