Skip to content

Commit

Permalink
Added DisallowCommentAfterCode to phpcs.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Mar 26, 2020
1 parent 3e34de9 commit 5901997
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
15 changes: 10 additions & 5 deletions SlevomatCodingStandard/Helpers/ReferencedNameHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,24 @@ private static function createAllReferencedNames(File $phpcsFile, int $openTagPo
} elseif (
!in_array($tokens[$nextTokenAfterEndPointer]['code'], [
T_VARIABLE,
T_ELLIPSIS, // Variadic parameter
T_BITWISE_AND, // Parameter by reference
// Variadic parameter
T_ELLIPSIS,
// Parameter by reference
T_BITWISE_AND,
], true)
) {
if (
!in_array($tokens[$previousTokenBeforeStartPointer]['code'], [
T_EXTENDS,
T_IMPLEMENTS,
T_INSTANCEOF,
T_USE, // Trait
// Trait
T_USE,
T_NEW,
T_COLON, // Return type hint
T_NULLABLE, // Nullable type hint
// Return type hint
T_COLON,
// Nullable type hint
T_NULLABLE,
], true)
&& $tokens[$nextTokenAfterEndPointer]['code'] !== T_DOUBLE_COLON
) {
Expand Down
3 changes: 2 additions & 1 deletion SlevomatCodingStandard/Helpers/YodaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ private static function getTokenDynamism(): array
T_DNUMBER => 0,
T_LNUMBER => 0,
T_OPEN_SHORT_ARRAY => 0,
T_ARRAY => 0, // Do not stack error messages when the old-style array syntax is used
// Do not stack error messages when the old-style array syntax is used
T_ARRAY => 0,
T_CONSTANT_ENCAPSED_STRING => 0,
T_VARIABLE => self::DYNAMISM_VARIABLE,
T_STRING => self::DYNAMISM_FUNCTION_CALL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ static function (int $order) use ($groupsOrder, $expectedGroup): bool {
$firstMemberPointer
);

return $pointer - 1; // run the sniff again to fix the rest of the groups
// run the sniff again to fix the rest of the groups
return $pointer - 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function process(File $phpcsFile, $openTagPointer): void
}
$previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $referencedName->getStartPointer() - 1);
if (in_array($tokens[$previousPointer]['code'], [T_EXTENDS, T_NEW, T_INSTANCEOF], true)) {
continue; // Allow \Exception in extends and instantiating it
// Allow \Exception in extends and instantiating it
continue;
}
if ($tokens[$previousPointer]['code'] === T_BITWISE_OR) {
$previousPointer = TokenHelper::findPreviousExcluding($phpcsFile, array_merge(TokenHelper::$ineffectiveTokenCodes, TokenHelper::$nameTokenCodes, [T_BITWISE_OR]), $previousPointer - 1);
Expand Down
1 change: 1 addition & 0 deletions build/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
<rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing"/>
<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding"/>
<rule ref="SlevomatCodingStandard.Commenting.DisallowCommentAfterCode"/>
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
<properties>
<property name="linesCountBetweenAnnotationsGroups" value="0"/>
Expand Down
9 changes: 6 additions & 3 deletions tests/Sniffs/Namespaces/FullyQualifiedExceptionsSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ public function testIgnoredNames(): void
public function testClassSuffixedErrorOrExceptionIsNotAnExceptionButReportedInNamespace(): void
{
$report = self::checkFile(__DIR__ . '/data/ignoredNamesInNamespace.php');
self::assertNoSniffError($report, 5); // *Error names are reported only with a root namespace
// *Error names are reported only with a root namespace
self::assertNoSniffError($report, 5);
self::assertSniffError($report, 9, FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION);
self::assertNoSniffError($report, 13); // look like Exception but isn't - handled by ReferenceUsedNamesOnlySniff
self::assertNoSniffError($report, 17); // dtto
// look like Exception but isn't - handled by ReferenceUsedNamesOnlySniff
self::assertNoSniffError($report, 13);
// dtto
self::assertNoSniffError($report, 17);
}

public function testIgnoredNamesInNamespace(): void
Expand Down

0 comments on commit 5901997

Please sign in to comment.