Skip to content

Commit c5f7f69

Browse files
authored
Squiz/ClosingDeclarationComment: add trait support (#442)
* 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.
1 parent 49088f4 commit c5f7f69

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Checks the //end ... comments on classes, interfaces and functions.
3+
* Checks the //end ... comments on classes, enums, functions, interfaces and traits.
44
*
55
* @author Greg Sherwood <[email protected]>
66
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
@@ -24,10 +24,11 @@ class ClosingDeclarationCommentSniff implements Sniff
2424
public function register()
2525
{
2626
return [
27-
T_FUNCTION,
2827
T_CLASS,
29-
T_INTERFACE,
3028
T_ENUM,
29+
T_FUNCTION,
30+
T_INTERFACE,
31+
T_TRAIT,
3132
];
3233

3334
}//end register()
@@ -72,6 +73,8 @@ public function process(File $phpcsFile, $stackPtr)
7273
$comment = '//end class';
7374
} else if ($tokens[$stackPtr]['code'] === T_INTERFACE) {
7475
$comment = '//end interface';
76+
} else if ($tokens[$stackPtr]['code'] === T_TRAIT) {
77+
$comment = '//end trait';
7578
} else {
7679
$comment = '//end enum';
7780
}//end if

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.1.inc

+6
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,9 @@ $anon = new class {};
116116

117117
// Arrow functions don't need end comments.
118118
$arrow = fn($a) => $a;
119+
120+
trait TestTrait {
121+
}//end trait
122+
123+
trait TestTrait {
124+
}

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.1.inc.fixed

+6
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ $anon = new class {};
109109

110110
// Arrow functions don't need end comments.
111111
$arrow = fn($a) => $a;
112+
113+
trait TestTrait {
114+
}//end trait
115+
116+
trait TestTrait {
117+
}//end trait

src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function getErrorList($testFile='')
5050
101 => 1,
5151
106 => 1,
5252
110 => 1,
53+
124 => 1,
5354
];
5455

5556
case 'ClosingDeclarationCommentUnitTest.4.inc':

0 commit comments

Comments
 (0)