Skip to content

Commit 01073ff

Browse files
committed
Merge pull request phpbb#3560 from Nicofuma/ticket/13790
[ticket/13790] Update phpcs
2 parents b5fed65 + a462f14 commit 01073ff

23 files changed

Lines changed: 109 additions & 126 deletions

File tree

build/build.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@
7575

7676
<target name="sniff">
7777
<exec command="phpBB/vendor/bin/phpcs
78-
-s
78+
-s -p
7979
--extensions=php
8080
--standard=build/code_sniffer/ruleset-php-strict-core.xml
8181
--ignore=${project.basedir}/phpBB/phpbb/db/migration/data/v30x/*
8282
phpBB/phpbb"
8383
dir="." returnProperty="retval-php-strict" passthru="true" />
8484
<exec command="phpBB/vendor/bin/phpcs
85-
-s
85+
-s -p
8686
--extensions=php
8787
--standard=build/code_sniffer/ruleset-php-legacy-core.xml
8888
--ignore=${project.basedir}/phpBB/cache/*
@@ -98,7 +98,7 @@
9898
phpBB"
9999
dir="." returnProperty="retval-php-legacy" passthru="true" />
100100
<exec command="phpBB/vendor/bin/phpcs
101-
-s
101+
-s -p
102102
--extensions=php
103103
--standard=build/code_sniffer/ruleset-php-extensions.xml
104104
--ignore=${project.basedir}/phpBB/ext/*/tests/*

build/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
138138
// Check docblocks
139139
$find = array(
140140
T_COMMENT,
141+
T_DOC_COMMENT_CLOSE_TAG,
141142
T_DOC_COMMENT,
142143
T_CLASS,
143144
T_FUNCTION,
@@ -147,43 +148,31 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
147148
$comment_end = $phpcsFile->findPrevious($find, ($function_declaration - 1));
148149
if ($comment_end !== false)
149150
{
150-
if (!$tokens[$comment_end]['code'] !== T_DOC_COMMENT)
151+
if ($tokens[$comment_end]['code'] === T_DOC_COMMENT_CLOSE_TAG)
151152
{
152-
$comment_start = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($comment_end - 1), null, true) + 1);
153-
$comment = $phpcsFile->getTokensAsString($comment_start, ($comment_end - $comment_start + 1));
154-
155-
try
156-
{
157-
$comment_parser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsFile);
158-
$comment_parser->parse();
159-
160-
// Check @param
161-
foreach ($comment_parser->getParams() as $param) {
162-
$type = $param->getType();
163-
$types = explode('|', str_replace('[]', '', $type));
164-
foreach ($types as $type)
165-
{
166-
$ok = $this->check($phpcsFile, $type, $class_name_full, $class_name_short, $param->getLine() + $comment_start) ? true : $ok;
167-
}
153+
$comment_start = $tokens[$comment_end]['comment_opener'];
154+
foreach ($tokens[$comment_start]['comment_tags'] as $tag) {
155+
if ($tokens[$tag]['content'] !== '@param' && $tokens[$tag]['content'] !== '@return' && $tokens[$tag]['content'] !== '@throws') {
156+
continue;
168157
}
169158

170-
// Check @return
171-
$return = $comment_parser->getReturn();
172-
if ($return !== null)
159+
$classes = $tokens[($tag + 2)]['content'];
160+
$space = strpos($classes, ' ');
161+
if ($space !== false) {
162+
$classes = substr($classes, 0, $space);
163+
}
164+
165+
$tab = strpos($classes, "\t");
166+
if ($tab !== false) {
167+
$classes = substr($classes, 0, $tab);
168+
}
169+
170+
$classes = explode('|', str_replace('[]', '', $classes));
171+
foreach ($classes as $class)
173172
{
174-
$type = $return->getValue();
175-
$types = explode('|', str_replace('[]', '', $type));
176-
foreach ($types as $type)
177-
{
178-
$ok = $this->check($phpcsFile, $type, $class_name_full, $class_name_short, $return->getLine() + $comment_start) ? true : $ok;
179-
}
173+
$ok = $this->check($phpcsFile, $class, $class_name_full, $class_name_short, $tokens[$tag + 2]['line']) ? true : $ok;
180174
}
181175
}
182-
catch (PHP_CodeSniffer_CommentParser_ParserException $e)
183-
{
184-
$line = ($e->getLineWithinComment() + $comment_start);
185-
$phpcsFile->addError($e->getMessage(), $line, 'FailedParse');
186-
}
187176
}
188177
}
189178

phpBB/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
},
3939
"require-dev": {
4040
"fabpot/goutte": "1.0.*",
41+
"phing/phing": "2.4.*",
4142
"phpunit/dbunit": "1.3.*",
4243
"phpunit/phpunit": "4.1.*",
43-
"phing/phing": "2.4.*",
4444
"sami/sami": "1.*",
45-
"squizlabs/php_codesniffer": "1.*",
45+
"squizlabs/php_codesniffer": "2.*",
4646
"symfony/browser-kit": "2.3.*",
4747
"symfony/css-selector": "2.3.*",
4848
"symfony/debug": "2.3.*",

0 commit comments

Comments
 (0)