Merge pull request #3560 from Nicofuma/ticket/13790

[ticket/13790] Update phpcs
This commit is contained in:
Nils Adermann 2015-05-30 10:53:47 +02:00
commit 01073ffcbf
23 changed files with 110 additions and 127 deletions

View file

@ -75,14 +75,14 @@
<target name="sniff"> <target name="sniff">
<exec command="phpBB/vendor/bin/phpcs <exec command="phpBB/vendor/bin/phpcs
-s -s -p
--extensions=php --extensions=php
--standard=build/code_sniffer/ruleset-php-strict-core.xml --standard=build/code_sniffer/ruleset-php-strict-core.xml
--ignore=${project.basedir}/phpBB/phpbb/db/migration/data/v30x/* --ignore=${project.basedir}/phpBB/phpbb/db/migration/data/v30x/*
phpBB/phpbb" phpBB/phpbb"
dir="." returnProperty="retval-php-strict" passthru="true" /> dir="." returnProperty="retval-php-strict" passthru="true" />
<exec command="phpBB/vendor/bin/phpcs <exec command="phpBB/vendor/bin/phpcs
-s -s -p
--extensions=php --extensions=php
--standard=build/code_sniffer/ruleset-php-legacy-core.xml --standard=build/code_sniffer/ruleset-php-legacy-core.xml
--ignore=${project.basedir}/phpBB/cache/* --ignore=${project.basedir}/phpBB/cache/*
@ -98,7 +98,7 @@
phpBB" phpBB"
dir="." returnProperty="retval-php-legacy" passthru="true" /> dir="." returnProperty="retval-php-legacy" passthru="true" />
<exec command="phpBB/vendor/bin/phpcs <exec command="phpBB/vendor/bin/phpcs
-s -s -p
--extensions=php --extensions=php
--standard=build/code_sniffer/ruleset-php-extensions.xml --standard=build/code_sniffer/ruleset-php-extensions.xml
--ignore=${project.basedir}/phpBB/ext/*/tests/* --ignore=${project.basedir}/phpBB/ext/*/tests/*

View file

@ -60,14 +60,14 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
return; return;
} }
// Mark as error if this is not a doc comment // Mark as error if this is not a doc comment
else if ($start === false || $tokens[$start]['code'] !== T_DOC_COMMENT) else if ($start === false || $tokens[$start]['code'] !== T_DOC_COMMENT_OPEN_TAG)
{ {
$phpcsFile->addError('Missing required file doc comment.', $stackPtr); $phpcsFile->addError('Missing required file doc comment.', $stackPtr);
return; return;
} }
// Find comment end token // Find comment end token
$end = $phpcsFile->findNext(T_DOC_COMMENT, $start + 1, null, true) - 1; $end = $tokens[$start]['comment_closer'];
// If there is no end, skip processing here // If there is no end, skip processing here
if ($end === false) if ($end === false)
@ -75,38 +75,30 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
return; return;
} }
// List of found comment tags
$tags = array();
// check comment lines without the first(/**) an last(*/) line // check comment lines without the first(/**) an last(*/) line
for ($i = $start + 1, $c = $end - 1; $i <= $c; ++$i) for ($token = $start + 1, $c = $end - 2; $token <= $c; ++$token)
{ {
$line = $tokens[$i]['content'];
// Check that each line starts with a '*' // Check that each line starts with a '*'
if (substr($line, 0, 1) !== '*' && substr($line, 0, 2) !== ' *') if ($tokens[$token]['column'] === 1 && (($tokens[$token]['content'] !== '*' && $tokens[$token]['content'] !== ' ') || ($tokens[$token]['content'] === ' ' && $tokens[$token + 1]['content'] !== '*')))
{ {
$message = 'The file doc comment should not be indented.'; $message = 'The file doc comment should not be indented.';
$phpcsFile->addWarning($message, $i); $phpcsFile->addWarning($message, $token);
}
else if (preg_match('/^[ ]?\*\s+@([\w]+)\s+(.*)$/', $line, $match) !== 0)
{
if (!isset($tags[$match[1]]))
{
$tags[$match[1]] = array();
}
$tags[$match[1]][] = array($match[2], $i);
} }
} }
// Check that the first and last line is empty // Check that the first and last line is empty
if (trim($tokens[$start + 1]['content']) !== '*') // /**T_WHITESPACE
// (T_WHITESPACE)*T_WHITESPACE
// (T_WHITESPACE)* ...
// (T_WHITESPACE)*T_WHITESPACE
// T_WHITESPACE*/
if (!(($tokens[$start + 2]['content'] !== '*' && $tokens[$start + 4]['content'] !== '*') || ($tokens[$start + 3]['content'] !== '*' && $tokens[$start + 6]['content'] !== '*')))
{ {
$message = 'The first file comment line should be empty.'; $message = 'The first file comment line should be empty.';
$phpcsFile->addWarning($message, ($start + 1)); $phpcsFile->addWarning($message, ($start + 1));
} }
if (trim($tokens[$end - 1]['content']) !== '*')
if ($tokens[$end - 3]['content'] !== '*' && $tokens[$end - 6]['content'] !== '*')
{ {
$message = 'The last file comment line should be empty.'; $message = 'The last file comment line should be empty.';
$phpcsFile->addWarning($message, $end - 1); $phpcsFile->addWarning($message, $end - 1);
@ -114,8 +106,8 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
//$this->processPackage($phpcsFile, $start, $tags); //$this->processPackage($phpcsFile, $start, $tags);
//$this->processVersion($phpcsFile, $start, $tags); //$this->processVersion($phpcsFile, $start, $tags);
$this->processCopyright($phpcsFile, $start, $tags); $this->processCopyright($phpcsFile, $start, $tokens[$start]['comment_tags']);
$this->processLicense($phpcsFile, $start, $tags); $this->processLicense($phpcsFile, $start, $tokens[$start]['comment_tags']);
} }
/** /**
@ -176,17 +168,24 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
{ {
$copyright = '(c) phpBB Limited <https://www.phpbb.com>'; $copyright = '(c) phpBB Limited <https://www.phpbb.com>';
$tokens = $phpcsFile->getTokens();
if (!isset($tags['copyright'])) foreach ($tags as $tag)
{ {
$message = 'Missing require @copyright tag in file doc comment.'; if ($tokens[$tag]['content'] === '@copyright')
$phpcsFile->addError($message, $ptr); {
} if ($tokens[$tag + 2]['content'] !== $copyright)
else if ($tags['copyright'][0][0] !== $copyright)
{ {
$message = 'Invalid content found for the first @copyright tag, use "' . $copyright . '".'; $message = 'Invalid content found for the first @copyright tag, use "' . $copyright . '".';
$phpcsFile->addError($message, $tags['copyright'][0][1]); $phpcsFile->addError($message, $tags['copyright'][0][1]);
} }
return;
}
}
$message = 'Missing require @copyright tag in file doc comment.';
$phpcsFile->addError($message, $ptr);
} }
/** /**
@ -201,22 +200,33 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags)
{ {
$license = 'GNU General Public License, version 2 (GPL-2.0)'; $license = 'GNU General Public License, version 2 (GPL-2.0)';
$tokens = $phpcsFile->getTokens();
if (!isset($tags['license'])) $found = false;
foreach ($tags as $tag)
{ {
$message = 'Missing require @license tag in file doc comment.'; if ($tokens[$tag]['content'] === '@license')
$phpcsFile->addError($message, $ptr); {
} if ($found)
else if (sizeof($tags['license']) !== 1)
{ {
$message = 'It must be only one @license tag in file doc comment.'; $message = 'It must be only one @license tag in file doc comment.';
$phpcsFile->addError($message, $ptr); $phpcsFile->addError($message, $ptr);
} }
else if (trim($tags['license'][0][0]) !== $license)
$found = true;
if ($tokens[$tag + 2]['content'] !== $license)
{ {
$message = 'Invalid content found for @license tag, use ' $message = 'Invalid content found for @license tag, use "' . $license . '".';
. '"' . $license . '".';
$phpcsFile->addError($message, $tags['license'][0][1]); $phpcsFile->addError($message, $tags['license'][0][1]);
} }
} }
} }
if (!$found)
{
$message = 'Missing require @license tag in file doc comment.';
$phpcsFile->addError($message, $ptr);
}
}
}

View file

@ -138,6 +138,7 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
// Check docblocks // Check docblocks
$find = array( $find = array(
T_COMMENT, T_COMMENT,
T_DOC_COMMENT_CLOSE_TAG,
T_DOC_COMMENT, T_DOC_COMMENT,
T_CLASS, T_CLASS,
T_FUNCTION, T_FUNCTION,
@ -147,42 +148,30 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements PHP_CodeSniffer_Sniff
$comment_end = $phpcsFile->findPrevious($find, ($function_declaration - 1)); $comment_end = $phpcsFile->findPrevious($find, ($function_declaration - 1));
if ($comment_end !== false) if ($comment_end !== false)
{ {
if (!$tokens[$comment_end]['code'] !== T_DOC_COMMENT) if ($tokens[$comment_end]['code'] === T_DOC_COMMENT_CLOSE_TAG)
{ {
$comment_start = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($comment_end - 1), null, true) + 1); $comment_start = $tokens[$comment_end]['comment_opener'];
$comment = $phpcsFile->getTokensAsString($comment_start, ($comment_end - $comment_start + 1)); foreach ($tokens[$comment_start]['comment_tags'] as $tag) {
if ($tokens[$tag]['content'] !== '@param' && $tokens[$tag]['content'] !== '@return' && $tokens[$tag]['content'] !== '@throws') {
try continue;
{
$comment_parser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsFile);
$comment_parser->parse();
// Check @param
foreach ($comment_parser->getParams() as $param) {
$type = $param->getType();
$types = explode('|', str_replace('[]', '', $type));
foreach ($types as $type)
{
$ok = $this->check($phpcsFile, $type, $class_name_full, $class_name_short, $param->getLine() + $comment_start) ? true : $ok;
}
} }
// Check @return $classes = $tokens[($tag + 2)]['content'];
$return = $comment_parser->getReturn(); $space = strpos($classes, ' ');
if ($return !== null) if ($space !== false) {
{ $classes = substr($classes, 0, $space);
$type = $return->getValue();
$types = explode('|', str_replace('[]', '', $type));
foreach ($types as $type)
{
$ok = $this->check($phpcsFile, $type, $class_name_full, $class_name_short, $return->getLine() + $comment_start) ? true : $ok;
} }
$tab = strpos($classes, "\t");
if ($tab !== false) {
$classes = substr($classes, 0, $tab);
} }
}
catch (PHP_CodeSniffer_CommentParser_ParserException $e) $classes = explode('|', str_replace('[]', '', $classes));
foreach ($classes as $class)
{ {
$line = ($e->getLineWithinComment() + $comment_start); $ok = $this->check($phpcsFile, $class, $class_name_full, $class_name_short, $tokens[$tag + 2]['line']) ? true : $ok;
$phpcsFile->addError($e->getMessage(), $line, 'FailedParse'); }
} }
} }
} }

View file

@ -38,11 +38,11 @@
}, },
"require-dev": { "require-dev": {
"fabpot/goutte": "1.0.*", "fabpot/goutte": "1.0.*",
"phing/phing": "2.4.*",
"phpunit/dbunit": "1.3.*", "phpunit/dbunit": "1.3.*",
"phpunit/phpunit": "4.1.*", "phpunit/phpunit": "4.1.*",
"phing/phing": "2.4.*",
"sami/sami": "1.*", "sami/sami": "1.*",
"squizlabs/php_codesniffer": "1.*", "squizlabs/php_codesniffer": "2.*",
"symfony/browser-kit": "2.3.*", "symfony/browser-kit": "2.3.*",
"symfony/css-selector": "2.3.*", "symfony/css-selector": "2.3.*",
"symfony/debug": "2.3.*", "symfony/debug": "2.3.*",

56
phpBB/composer.lock generated
View file

@ -1,9 +1,10 @@
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
], ],
"hash": "d93446768ea0665b7c55c01890153a67", "hash": "17b51553237b78392baf2ec78bfdfbc0",
"packages": [ "packages": [
{ {
"name": "lusitanian/oauth", "name": "lusitanian/oauth",
@ -652,12 +653,12 @@
"version": "v1.13.2", "version": "v1.13.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/fabpot/Twig.git", "url": "https://github.com/twigphp/Twig.git",
"reference": "6d6a1009427d1f398c9d40904147bf9f723d5755" "reference": "6d6a1009427d1f398c9d40904147bf9f723d5755"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/fabpot/Twig/zipball/6d6a1009427d1f398c9d40904147bf9f723d5755", "url": "https://api.github.com/repos/twigphp/Twig/zipball/6d6a1009427d1f398c9d40904147bf9f723d5755",
"reference": "6d6a1009427d1f398c9d40904147bf9f723d5755", "reference": "6d6a1009427d1f398c9d40904147bf9f723d5755",
"shasum": "" "shasum": ""
}, },
@ -682,14 +683,11 @@
"authors": [ "authors": [
{ {
"name": "Fabien Potencier", "name": "Fabien Potencier",
"email": "fabien@symfony.com", "email": "fabien@symfony.com"
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
}, },
{ {
"name": "Armin Ronacher", "name": "Armin Ronacher",
"email": "armin.ronacher@active-4.com", "email": "armin.ronacher@active-4.com"
"role": "Project Founder"
} }
], ],
"description": "Twig, the flexible, fast, and secure template language for PHP", "description": "Twig, the flexible, fast, and secure template language for PHP",
@ -1914,41 +1912,45 @@
}, },
{ {
"name": "squizlabs/php_codesniffer", "name": "squizlabs/php_codesniffer",
"version": "1.5.2", "version": "2.3.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "a76a39b317ce8106abe6264daa505e24e1731860" "reference": "e96d8579fbed0c95ecf2a0501ec4f307a4aa6404"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/a76a39b317ce8106abe6264daa505e24e1731860", "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/e96d8579fbed0c95ecf2a0501ec4f307a4aa6404",
"reference": "a76a39b317ce8106abe6264daa505e24e1731860", "reference": "e96d8579fbed0c95ecf2a0501ec4f307a4aa6404",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-tokenizer": "*", "ext-tokenizer": "*",
"ext-xmlwriter": "*",
"php": ">=5.1.2" "php": ">=5.1.2"
}, },
"suggest": {
"phpunit/php-timer": "dev-master"
},
"bin": [ "bin": [
"scripts/phpcs" "scripts/phpcs",
"scripts/phpcbf"
], ],
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": { "autoload": {
"classmap": [ "classmap": [
"CodeSniffer.php", "CodeSniffer.php",
"CodeSniffer/CLI.php", "CodeSniffer/CLI.php",
"CodeSniffer/Exception.php", "CodeSniffer/Exception.php",
"CodeSniffer/File.php", "CodeSniffer/File.php",
"CodeSniffer/Fixer.php",
"CodeSniffer/Report.php", "CodeSniffer/Report.php",
"CodeSniffer/Reporting.php", "CodeSniffer/Reporting.php",
"CodeSniffer/Sniff.php", "CodeSniffer/Sniff.php",
"CodeSniffer/Tokens.php", "CodeSniffer/Tokens.php",
"CodeSniffer/Reports/", "CodeSniffer/Reports/",
"CodeSniffer/CommentParser/",
"CodeSniffer/Tokenizers/", "CodeSniffer/Tokenizers/",
"CodeSniffer/DocGenerators/", "CodeSniffer/DocGenerators/",
"CodeSniffer/Standards/AbstractPatternSniff.php", "CodeSniffer/Standards/AbstractPatternSniff.php",
@ -1974,13 +1976,13 @@
"role": "lead" "role": "lead"
} }
], ],
"description": "PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
"homepage": "http://www.squizlabs.com/php-codesniffer", "homepage": "http://www.squizlabs.com/php-codesniffer",
"keywords": [ "keywords": [
"phpcs", "phpcs",
"standards" "standards"
], ],
"time": "2014-02-04 23:49:58" "time": "2015-04-28 23:28:20"
}, },
{ {
"name": "symfony/browser-kit", "name": "symfony/browser-kit",
@ -2236,17 +2238,13 @@
"time": "2014-10-01 05:38:33" "time": "2014-10-01 05:38:33"
} }
], ],
"aliases": [ "aliases": [],
],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [ "stability-flags": [],
"prefer-stable": false,
], "prefer-lowest": false,
"platform": { "platform": {
"php": ">=5.3.3" "php": ">=5.3.3"
}, },
"platform-dev": [ "platform-dev": []
]
} }

View file

@ -13,7 +13,6 @@
namespace phpbb\auth\provider\oauth; namespace phpbb\auth\provider\oauth;
use OAuth\OAuth1\Token\StdOAuth1Token; use OAuth\OAuth1\Token\StdOAuth1Token;
use OAuth\Common\Token\TokenInterface; use OAuth\Common\Token\TokenInterface;
use OAuth\Common\Storage\TokenStorageInterface; use OAuth\Common\Storage\TokenStorageInterface;

View file

@ -14,7 +14,6 @@
namespace phpbb\template\twig\node; namespace phpbb\template\twig\node;
class definenode extends \Twig_Node class definenode extends \Twig_Node
{ {
public function __construct($capture, \Twig_NodeInterface $name, \Twig_NodeInterface $value, $lineno, $tag = null) public function __construct($capture, \Twig_NodeInterface $name, \Twig_NodeInterface $value, $lineno, $tag = null)

View file

@ -13,7 +13,6 @@
namespace phpbb\template\twig\node; namespace phpbb\template\twig\node;
class event extends \Twig_Node class event extends \Twig_Node
{ {
/** /**

View file

@ -13,7 +13,6 @@
namespace phpbb\template\twig\node\expression\binary; namespace phpbb\template\twig\node\expression\binary;
class equalequal extends \Twig_Node_Expression_Binary class equalequal extends \Twig_Node_Expression_Binary
{ {
public function operator(\Twig_Compiler $compiler) public function operator(\Twig_Compiler $compiler)

View file

@ -13,7 +13,6 @@
namespace phpbb\template\twig\node\expression\binary; namespace phpbb\template\twig\node\expression\binary;
class notequalequal extends \Twig_Node_Expression_Binary class notequalequal extends \Twig_Node_Expression_Binary
{ {
public function operator(\Twig_Compiler $compiler) public function operator(\Twig_Compiler $compiler)

View file

@ -13,7 +13,6 @@
namespace phpbb\template\twig\node; namespace phpbb\template\twig\node;
class includenode extends \Twig_Node_Include class includenode extends \Twig_Node_Include
{ {
/** /**

View file

@ -14,7 +14,6 @@
namespace phpbb\template\twig\node; namespace phpbb\template\twig\node;
class includephp extends \Twig_Node class includephp extends \Twig_Node
{ {
/** @var \Twig_Environment */ /** @var \Twig_Environment */

View file

@ -13,7 +13,6 @@
namespace phpbb\template\twig\node; namespace phpbb\template\twig\node;
class php extends \Twig_Node class php extends \Twig_Node
{ {
/** @var \Twig_Environment */ /** @var \Twig_Environment */

View file

@ -14,7 +14,6 @@
namespace phpbb\template\twig\tokenparser; namespace phpbb\template\twig\tokenparser;
class defineparser extends \Twig_TokenParser class defineparser extends \Twig_TokenParser
{ {
/** /**

View file

@ -13,7 +13,6 @@
namespace phpbb\template\twig\tokenparser; namespace phpbb\template\twig\tokenparser;
class event extends \Twig_TokenParser class event extends \Twig_TokenParser
{ {
/** /**

View file

@ -13,7 +13,6 @@
namespace phpbb\template\twig\tokenparser; namespace phpbb\template\twig\tokenparser;
class includejs extends \Twig_TokenParser class includejs extends \Twig_TokenParser
{ {
/** /**

View file

@ -14,7 +14,6 @@
namespace phpbb\template\twig\tokenparser; namespace phpbb\template\twig\tokenparser;
class includeparser extends \Twig_TokenParser_Include class includeparser extends \Twig_TokenParser_Include
{ {
/** /**

View file

@ -14,7 +14,6 @@
namespace phpbb\template\twig\tokenparser; namespace phpbb\template\twig\tokenparser;
class includephp extends \Twig_TokenParser class includephp extends \Twig_TokenParser
{ {
/** /**

View file

@ -13,7 +13,6 @@
namespace phpbb\template\twig\tokenparser; namespace phpbb\template\twig\tokenparser;
class php extends \Twig_TokenParser class php extends \Twig_TokenParser
{ {
/** /**