@@ -60,62 +60,54 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6060 return ;
6161 }
6262 // Mark as error if this is not a doc comment
63- else if ($ start === false || $ tokens [$ start ]['code ' ] !== T_DOC_COMMENT )
63+ else if ($ start === false || $ tokens [$ start ]['code ' ] !== T_DOC_COMMENT_OPEN_TAG )
6464 {
6565 $ phpcsFile ->addError ('Missing required file doc comment. ' , $ stackPtr );
6666 return ;
6767 }
6868
6969 // Find comment end token
70- $ end = $ phpcsFile -> findNext ( T_DOC_COMMENT , $ start + 1 , null , true ) - 1 ;
70+ $ end = $ tokens [ $ start][ ' comment_closer ' ] ;
7171
7272 // If there is no end, skip processing here
7373 if ($ end === false )
7474 {
7575 return ;
7676 }
7777
78- // List of found comment tags
79- $ tags = array ();
80-
8178 // check comment lines without the first(/**) an last(*/) line
82- for ($ i = $ start + 1 , $ c = $ end - 1 ; $ i <= $ c ; ++$ i )
79+ for ($ token = $ start + 1 , $ c = $ end - 2 ; $ token <= $ c ; ++$ token )
8380 {
84- $ line = $ tokens [$ i ]['content ' ];
85-
8681 // Check that each line starts with a '*'
87- if (substr ( $ line , 0 , 1 ) !== '* ' && substr ( $ line , 0 , 2 ) !== ' * ' )
82+ if ($ tokens [ $ token ][ ' column ' ] === 1 && (( $ tokens [ $ token ][ ' content ' ] !== '* ' && $ tokens [ $ token ][ ' content ' ] !== ' ' ) || ( $ tokens [ $ token ][ ' content ' ] === ' ' && $ tokens [ $ token + 1 ][ ' content ' ] !== ' * ' )) )
8883 {
8984 $ message = 'The file doc comment should not be indented. ' ;
90- $ phpcsFile ->addWarning ($ message , $ i );
91- }
92- else if (preg_match ('/^[ ]?\*\s+@([\w]+)\s+(.*)$/ ' , $ line , $ match ) !== 0 )
93- {
94- if (!isset ($ tags [$ match [1 ]]))
95- {
96- $ tags [$ match [1 ]] = array ();
97- }
98-
99- $ tags [$ match [1 ]][] = array ($ match [2 ], $ i );
85+ $ phpcsFile ->addWarning ($ message , $ token );
10086 }
10187 }
10288
10389 // Check that the first and last line is empty
104- if (trim ($ tokens [$ start + 1 ]['content ' ]) !== '* ' )
90+ // /**T_WHITESPACE
91+ // (T_WHITESPACE)*T_WHITESPACE
92+ // (T_WHITESPACE)* ...
93+ // (T_WHITESPACE)*T_WHITESPACE
94+ // T_WHITESPACE*/
95+ if (!(($ tokens [$ start + 2 ]['content ' ] !== '* ' && $ tokens [$ start + 4 ]['content ' ] !== '* ' ) || ($ tokens [$ start + 3 ]['content ' ] !== '* ' && $ tokens [$ start + 6 ]['content ' ] !== '* ' )))
10596 {
10697 $ message = 'The first file comment line should be empty. ' ;
10798 $ phpcsFile ->addWarning ($ message , ($ start + 1 ));
10899 }
109- if (trim ($ tokens [$ end - 1 ]['content ' ]) !== '* ' )
100+
101+ if ($ tokens [$ end - 3 ]['content ' ] !== '* ' && $ tokens [$ end - 6 ]['content ' ] !== '* ' )
110102 {
111103 $ message = 'The last file comment line should be empty. ' ;
112104 $ phpcsFile ->addWarning ($ message , $ end - 1 );
113105 }
114106
115107 //$this->processPackage($phpcsFile, $start, $tags);
116108 //$this->processVersion($phpcsFile, $start, $tags);
117- $ this ->processCopyright ($ phpcsFile , $ start , $ tags );
118- $ this ->processLicense ($ phpcsFile , $ start , $ tags );
109+ $ this ->processCopyright ($ phpcsFile , $ start , $ tokens [ $ start ][ ' comment_tags ' ] );
110+ $ this ->processLicense ($ phpcsFile , $ start , $ tokens [ $ start ][ ' comment_tags ' ] );
119111 }
120112
121113 /**
@@ -176,17 +168,24 @@ protected function processVersion(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
176168 protected function processCopyright (PHP_CodeSniffer_File $ phpcsFile , $ ptr , $ tags )
177169 {
178170 $ copyright = '(c) phpBB Limited <https://www.phpbb.com> ' ;
171+ $ tokens = $ phpcsFile ->getTokens ();
179172
180- if (! isset ( $ tags[ ' copyright ' ]) )
173+ foreach ( $ tags as $ tag )
181174 {
182- $ message = 'Missing require @copyright tag in file doc comment. ' ;
183- $ phpcsFile ->addError ($ message , $ ptr );
184- }
185- else if ($ tags ['copyright ' ][0 ][0 ] !== $ copyright )
186- {
187- $ message = 'Invalid content found for the first @copyright tag, use " ' . $ copyright . '". ' ;
188- $ phpcsFile ->addError ($ message , $ tags ['copyright ' ][0 ][1 ]);
175+ if ($ tokens [$ tag ]['content ' ] === '@copyright ' )
176+ {
177+ if ($ tokens [$ tag + 2 ]['content ' ] !== $ copyright )
178+ {
179+ $ message = 'Invalid content found for the first @copyright tag, use " ' . $ copyright . '". ' ;
180+ $ phpcsFile ->addError ($ message , $ tags ['copyright ' ][0 ][1 ]);
181+ }
182+
183+ return ;
184+ }
189185 }
186+
187+ $ message = 'Missing require @copyright tag in file doc comment. ' ;
188+ $ phpcsFile ->addError ($ message , $ ptr );
190189 }
191190
192191 /**
@@ -201,22 +200,33 @@ protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags
201200 protected function processLicense (PHP_CodeSniffer_File $ phpcsFile , $ ptr , $ tags )
202201 {
203202 $ license = 'GNU General Public License, version 2 (GPL-2.0) ' ;
203+ $ tokens = $ phpcsFile ->getTokens ();
204204
205- if (!isset ($ tags ['license ' ]))
205+ $ found = false ;
206+ foreach ($ tags as $ tag )
206207 {
207- $ message = 'Missing require @license tag in file doc comment. ' ;
208- $ phpcsFile ->addError ($ message , $ ptr );
208+ if ($ tokens [$ tag ]['content ' ] === '@license ' )
209+ {
210+ if ($ found )
211+ {
212+ $ message = 'It must be only one @license tag in file doc comment. ' ;
213+ $ phpcsFile ->addError ($ message , $ ptr );
214+ }
215+
216+ $ found = true ;
217+
218+ if ($ tokens [$ tag + 2 ]['content ' ] !== $ license )
219+ {
220+ $ message = 'Invalid content found for @license tag, use " ' . $ license . '". ' ;
221+ $ phpcsFile ->addError ($ message , $ tags ['license ' ][0 ][1 ]);
222+ }
223+ }
209224 }
210- else if (sizeof ($ tags ['license ' ]) !== 1 )
225+
226+ if (!$ found )
211227 {
212- $ message = 'It must be only one @license tag in file doc comment. ' ;
228+ $ message = 'Missing require @license tag in file doc comment. ' ;
213229 $ phpcsFile ->addError ($ message , $ ptr );
214230 }
215- else if (trim ($ tags ['license ' ][0 ][0 ]) !== $ license )
216- {
217- $ message = 'Invalid content found for @license tag, use '
218- . '" ' . $ license . '". ' ;
219- $ phpcsFile ->addError ($ message , $ tags ['license ' ][0 ][1 ]);
220- }
221231 }
222232}
0 commit comments