Skip to content

Commit 158ea91

Browse files
committed
Added attibute support
1 parent d2812fd commit 158ea91

File tree

5 files changed

+73
-32
lines changed

5 files changed

+73
-32
lines changed

package.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
10591059
<dir name="Commenting">
10601060
<file baseinstalldir="PHP/CodeSniffer" name="ClassCommentUnitTest.inc" role="test" />
10611061
<file baseinstalldir="PHP/CodeSniffer" name="ClassCommentUnitTest.php" role="test" />
1062-
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.inc" role="test" />
1062+
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.inc" role="test" />
1063+
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.2.inc" role="test" />
10631064
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.php" role="test" />
10641065
<file baseinstalldir="PHP/CodeSniffer" name="FunctionCommentUnitTest.inc" role="test" />
10651066
<file baseinstalldir="PHP/CodeSniffer" name="FunctionCommentUnitTest.inc.fixed" role="test" />

src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,24 @@ public function process(File $phpcsFile, $stackPtr)
138138

139139
$commentEnd = $tokens[$commentStart]['comment_closer'];
140140

141-
$nextToken = $phpcsFile->findNext(
142-
T_WHITESPACE,
143-
($commentEnd + 1),
144-
null,
145-
true
146-
);
141+
for ($nextToken = ($commentEnd + 1); $nextToken < $phpcsFile->numTokens; $nextToken++) {
142+
if ($tokens[$nextToken]['code'] === T_WHITESPACE) {
143+
continue;
144+
}
145+
146+
if ($tokens[$nextToken]['code'] === T_ATTRIBUTE
147+
&& isset($tokens[$nextToken]['attribute_closer']) === true
148+
) {
149+
$nextToken = $tokens[$nextToken]['attribute_closer'];
150+
continue;
151+
}
152+
153+
break;
154+
}
155+
156+
if ($nextToken === $phpcsFile->numTokens) {
157+
$nextToken--;
158+
}
147159

148160
$ignore = [
149161
T_CLASS,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
/**
4+
* Shows open tasks for admins
5+
*/
6+
#[Authenticate('admin_logged_in')]
7+
class TodoController extends AbstractController implements MustBeLoggedInInterface
8+
{
9+
}

src/Standards/PEAR/Tests/Commenting/FileCommentUnitTest.php

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,38 @@ class FileCommentUnitTest extends AbstractSniffUnitTest
2121
* The key of the array should represent the line number and the value
2222
* should represent the number of errors that should occur on that line.
2323
*
24+
* @param string $testFile The name of the file being tested.
25+
*
2426
* @return array<int, int>
2527
*/
26-
public function getErrorList()
28+
public function getErrorList($testFile='FileCommentUnitTest.inc')
2729
{
28-
return [
29-
21 => 1,
30-
23 => 2,
31-
24 => 1,
32-
26 => 1,
33-
28 => 1,
34-
29 => 1,
35-
30 => 1,
36-
31 => 1,
37-
32 => 2,
38-
33 => 1,
39-
34 => 1,
40-
35 => 1,
41-
40 => 2,
42-
41 => 2,
43-
43 => 1,
44-
];
30+
switch ($testFile) {
31+
case 'FileCommentUnitTest.1.inc':
32+
return [
33+
21 => 1,
34+
23 => 2,
35+
24 => 1,
36+
26 => 1,
37+
28 => 1,
38+
29 => 1,
39+
30 => 1,
40+
31 => 1,
41+
32 => 2,
42+
33 => 1,
43+
34 => 1,
44+
35 => 1,
45+
40 => 2,
46+
41 => 2,
47+
43 => 1,
48+
];
49+
50+
case 'FileCommentUnitTest.2.inc':
51+
return [1 => 1];
52+
53+
default:
54+
return [];
55+
}//end switch
4556

4657
}//end getErrorList()
4758

@@ -52,16 +63,24 @@ public function getErrorList()
5263
* The key of the array should represent the line number and the value
5364
* should represent the number of warnings that should occur on that line.
5465
*
66+
* @param string $testFile The name of the file being tested.
67+
*
5568
* @return array<int, int>
5669
*/
57-
public function getWarningList()
70+
public function getWarningList($testFile='FileCommentUnitTest.inc')
5871
{
59-
return [
60-
29 => 1,
61-
30 => 1,
62-
34 => 1,
63-
43 => 1,
64-
];
72+
switch ($testFile) {
73+
case 'FileCommentUnitTest.1.inc':
74+
return [
75+
29 => 1,
76+
30 => 1,
77+
34 => 1,
78+
43 => 1,
79+
];
80+
81+
default:
82+
return [];
83+
}//end switch
6584

6685
}//end getWarningList()
6786

0 commit comments

Comments
 (0)