File tree Expand file tree Collapse file tree 4 files changed +46
-1
lines changed Expand file tree Collapse file tree 4 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -139,10 +139,23 @@ public function process(File $phpcsFile, $stackPtr)
139
139
return ;
140
140
}
141
141
142
+ // If inheritDoc is found without curly braces it is identified as a T_DOC_COMMENT_TAG not a
143
+ // T_DOC_COMMENT_STRING. It would be misleading to give the 'Missing short description' error
144
+ // below, hence we give a more useful message and can fix it automatically.
145
+ if (stripos ($ tokens [$ short ]['content ' ], '@inheritdoc ' ) === 0 ) {
146
+ $ error = "{$ tokens [$ short ]['content ' ]} found. Did you mean { {$ tokens [$ short ]['content ' ]}}? " ;
147
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ short , 'InheritDocWithoutBraces ' );
148
+ if ($ fix === true ) {
149
+ $ phpcsFile ->fixer ->replaceToken ($ short , "{ {$ tokens [$ short ]['content ' ]}} " );
150
+ }
151
+
152
+ return ;
153
+ }
154
+
142
155
$ error = 'Missing short description in doc comment ' ;
143
156
$ phpcsFile ->addError ($ error , $ stackPtr , 'MissingShort ' );
144
157
return ;
145
- }
158
+ }//end if
146
159
147
160
if (isset ($ fileShort ) === true ) {
148
161
$ start = $ fileShort ;
Original file line number Diff line number Diff line change @@ -121,3 +121,18 @@ function test13() {
121
121
function test14 (array $ matches , array $ sub_key , $ to ) {
122
122
123
123
}
124
+
125
+ /**
126
+ * {@inheritdoc}
127
+ */
128
+ function test15_this_inheritdoc_is_correct();
129
+
130
+ /**
131
+ * @inheritdoc
132
+ */
133
+ function test16_lower_case_fail_needs_braces();
134
+
135
+ /**
136
+ * @inheritDoc
137
+ */
138
+ function test17_camel_case_fail_needs_braces();
Original file line number Diff line number Diff line change @@ -130,3 +130,18 @@ function test13() {
130
130
function test14(array $matches, array $sub_key, $to) {
131
131
132
132
}
133
+
134
+ /**
135
+ * {@inheritdoc}
136
+ */
137
+ function test15_this_inheritdoc_is_correct();
138
+
139
+ /**
140
+ * {@inheritdoc}
141
+ */
142
+ function test16_lower_case_fail_needs_braces();
143
+
144
+ /**
145
+ * {@inheritDoc}
146
+ */
147
+ function test17_camel_case_fail_needs_braces();
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ protected function getErrorList(string $testFile): array
33
33
66 => 1 ,
34
34
100 => 4 ,
35
35
101 => 1 ,
36
+ 131 => 1 ,
37
+ 136 => 1 ,
36
38
];
37
39
38
40
case 'DocCommentUnitTest.1.inc ' :
You can’t perform that action at this time.
0 commit comments