Skip to content

Squiz/ClosingDeclarationComment: add trait support #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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