File tree 4 files changed +77
-3
lines changed 4 files changed +77
-3
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,16 @@ class ClassAndInterfacePHPDocFormattingSniff implements Sniff
19
19
*/
20
20
private $ PHPDocFormattingValidator ;
21
21
22
+ /**
23
+ * @var string[] List of tags that can not be used in comments
24
+ */
25
+ private $ forbiddenTags = [
26
+ '@author ' ,
27
+ '@category ' ,
28
+ '@package ' ,
29
+ '@subpackage '
30
+ ];
31
+
22
32
/**
23
33
* Helper initialisation
24
34
*/
@@ -75,5 +85,35 @@ public function process(File $phpcsFile, $stackPtr)
75
85
);
76
86
}
77
87
88
+ $ this ->validateTags ($ phpcsFile , $ commentStartPtr , $ tokens );
89
+ }
90
+
91
+ /**
92
+ * Validates that forbidden tags are not used in comment
93
+ *
94
+ * @param File $phpcsFile
95
+ * @param int $commentStartPtr
96
+ * @param array $tokens
97
+ * @return bool
98
+ */
99
+ private function validateTags (File $ phpcsFile , $ commentStartPtr , $ tokens )
100
+ {
101
+ $ commentCloserPtr = $ tokens [$ commentStartPtr ]['comment_closer ' ];
102
+
103
+ for ($ i = $ commentStartPtr ; $ i <= $ commentCloserPtr ; $ i ++) {
104
+ if ($ tokens [$ i ]['code ' ] !== T_DOC_COMMENT_TAG ) {
105
+ continue ;
106
+ }
107
+
108
+ if (in_array ($ tokens [$ i ]['content ' ], $ this ->forbiddenTags ) === true ) {
109
+ $ phpcsFile ->addWarning (
110
+ sprintf ('Tag %s MUST NOT be used. ' , $ tokens [$ i ]['content ' ]),
111
+ $ i ,
112
+ 'ForbiddenTags '
113
+ );
114
+ }
115
+ }
116
+
117
+ return false ;
78
118
}
79
119
}
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ class YetAnotherHandler
39
39
40
40
/**
41
41
* GreenHandler
42
- * @package NotFromArroundHere
42
+ * @api Do not confuse tag for faulty short description
43
43
*/
44
44
class GreenHandler
45
45
{
@@ -52,4 +52,19 @@ class GreenHandler
52
52
class EmptyHandler
53
53
{
54
54
55
+ }
56
+
57
+ /**
58
+ * Handler for PHP errors/warnings/notices that converts them to exceptions.
59
+ *
60
+ * @api is ok here
61
+ * @deprecated can be used in this context
62
+ * @author must not be mentioned
63
+ * @category is irrelevant
64
+ * @package is not ment to be used
65
+ * @subpackage does not belong here
66
+ */
67
+ class ExampleHandler
68
+ {
69
+
55
70
}
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ interface YetAnotherHandler
39
39
40
40
/**
41
41
* GreenHandler
42
- * @package NotFromArroundHere
42
+ * @api Do not confuse tag for faulty short description
43
43
*/
44
44
interface GreenHandler
45
45
{
@@ -52,4 +52,19 @@ interface GreenHandler
52
52
interface EmptyHandler
53
53
{
54
54
55
+ }
56
+
57
+ /**
58
+ * Handler for PHP errors/warnings/notices that converts them to exceptions.
59
+ *
60
+ * @api is ok here
61
+ * @deprecated can be used in this context
62
+ * @author must not be mentioned
63
+ * @category is irrelevant
64
+ * @package is not ment to be used
65
+ * @subpackage does not belong here
66
+ */
67
+ interface ExampleHandler
68
+ {
69
+
55
70
}
Original file line number Diff line number Diff line change @@ -31,7 +31,11 @@ public function getWarningList($testFile = '')
31
31
27 => 1 ,
32
32
35 => 1 ,
33
33
44 => 1 ,
34
- 52 => 1
34
+ 52 => 1 ,
35
+ 62 => 1 ,
36
+ 63 => 1 ,
37
+ 64 => 1 ,
38
+ 65 => 1 ,
35
39
];
36
40
}
37
41
}
You can’t perform that action at this time.
0 commit comments