Skip to content

Commit

Permalink
Squiz/ClosingDeclarationComment: add trait support (#442)
Browse files Browse the repository at this point in the history
* Squiz/ClosingDeclarationComment: sort registered tokens alphabetically

This should make it easier to find if a given is registered by this
sniff or not.

* Squiz/ClosingDeclarationComment: add trait support

Now this sniff will also check for the closing declaration comment in
traits.
  • Loading branch information
rodrigoprimo committed Apr 23, 2024
1 parent 49088f4 commit c5f7f69
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Checks the //end ... comments on classes, interfaces and functions.
* Checks the //end ... comments on classes, enums, functions, interfaces and traits.
*
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
Expand All @@ -24,10 +24,11 @@ class ClosingDeclarationCommentSniff implements Sniff
public function register()
{
return [
T_FUNCTION,
T_CLASS,
T_INTERFACE,
T_ENUM,
T_FUNCTION,
T_INTERFACE,
T_TRAIT,
];

}//end register()
Expand Down Expand Up @@ -72,6 +73,8 @@ public function process(File $phpcsFile, $stackPtr)
$comment = '//end class';
} else if ($tokens[$stackPtr]['code'] === T_INTERFACE) {
$comment = '//end interface';
} else if ($tokens[$stackPtr]['code'] === T_TRAIT) {
$comment = '//end trait';
} else {
$comment = '//end enum';
}//end if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ $anon = new class {};

// Arrow functions don't need end comments.
$arrow = fn($a) => $a;

trait TestTrait {
}//end trait

trait TestTrait {
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ $anon = new class {};

// Arrow functions don't need end comments.
$arrow = fn($a) => $a;

trait TestTrait {
}//end trait

trait TestTrait {
}//end trait
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function getErrorList($testFile='')
101 => 1,
106 => 1,
110 => 1,
124 => 1,
];

case 'ClosingDeclarationCommentUnitTest.4.inc':
Expand Down

0 comments on commit c5f7f69

Please sign in to comment.