diff --git a/.travis.yml b/.travis.yml index 493c273..db1ec3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: php php: - - 5.6 # security support until 31/12/2018 - - 7.0 # security support until 03/12/2018 - - 7.1 # security support until 01/12/2019 - 7.2 # security support until 30/11/2020 - 7.3 # security support until 06/12/2021 - 7.4 # security support until 28/11/2022 diff --git a/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php b/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php index df8ecd2..e2be14a 100644 --- a/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php +++ b/Symfony/Sniffs/Arrays/MultiLineArrayCommaSniff.php @@ -96,9 +96,11 @@ public function process(File $phpcsFile, $stackPtr) while ($lastCommaPtr < $closePtr -1) { $lastCommaPtr++; - if ($tokens[$lastCommaPtr]['code'] !== T_WHITESPACE - && $tokens[$lastCommaPtr]['code'] !== T_PHPCS_IGNORE - && $tokens[$lastCommaPtr]['code'] !== T_COMMENT + if (!in_array( + $tokens[$lastCommaPtr]['code'], + [T_WHITESPACE, T_PHPCS_IGNORE, T_COMMENT], + true + ) ) { $fix = $phpcsFile->addFixableError( 'Add a comma after each item in a multi-line array', diff --git a/Symfony/Sniffs/Classes/PropertyDeclarationSniff.php b/Symfony/Sniffs/Classes/PropertyDeclarationSniff.php index 1dd0d8b..8b09667 100644 --- a/Symfony/Sniffs/Classes/PropertyDeclarationSniff.php +++ b/Symfony/Sniffs/Classes/PropertyDeclarationSniff.php @@ -68,10 +68,7 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - $end = null; - if (isset($tokens[$stackPtr]['scope_closer'])) { - $end = $tokens[$stackPtr]['scope_closer']; - } + $end = $tokens[$stackPtr]['scope_closer'] ?? null; $scope = $phpcsFile->findNext( T_FUNCTION, diff --git a/Symfony/Sniffs/Commenting/AnnotationsSniff.php b/Symfony/Sniffs/Commenting/AnnotationsSniff.php index ca0203a..1b1558b 100644 --- a/Symfony/Sniffs/Commenting/AnnotationsSniff.php +++ b/Symfony/Sniffs/Commenting/AnnotationsSniff.php @@ -28,7 +28,7 @@ */ class AnnotationsSniff implements Sniff { - const PATTERN = '/^@([^\\\(]+).*$/i'; + private const PATTERN = '/^@([^\\\(]+).*$/i'; /** * Registers the tokens that this sniff wants to listen for. diff --git a/Symfony/Sniffs/Commenting/TypeHintingSniff.php b/Symfony/Sniffs/Commenting/TypeHintingSniff.php deleted file mode 100644 index 28709d9..0000000 --- a/Symfony/Sniffs/Commenting/TypeHintingSniff.php +++ /dev/null @@ -1,138 +0,0 @@ - - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony-coding-standard - */ - -namespace Symfony\Sniffs\Commenting; - -use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Sniffs\Sniff; - -/** - * Checks for proper type hinting. - * - * @category PHP - * @package Symfony-coding-standard - * @author wicliff wolda - * @license http://spdx.org/licenses/MIT MIT License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class TypeHintingSniff implements Sniff -{ - /** - * Blacklisted types - * - * @var array - */ - private static $_blacklist = [ - 'boolean' => 'bool', - 'integer' => 'int', - 'double' => 'float', - 'real' => 'float', - ]; - - /** - * Cast tokens - * - * @var array - */ - private static $_casts = [ - T_BOOL_CAST, - T_INT_CAST, - T_DOUBLE_CAST, - ]; - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return array - */ - public function register() - { - return [ - T_DOC_COMMENT_TAG, - T_BOOL_CAST, - T_INT_CAST, - T_DOUBLE_CAST, - ]; - } - - /** - * Called when one of the token types that this sniff is listening for - * is found. - * - * @param File $phpcsFile The file where the token was found. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void|int Optionally returns a stack pointer. The sniff will not be - * called again on the current file until the returned stack - * pointer is reached. Return (count($tokens) + 1) to skip - * the rest of the file. - */ - public function process(File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $tag = $tokens[$stackPtr]; - - $fixPtr = $stackPtr; - - if ('@var' === $tag['content']) { - $type = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr + 1); - $fixPtr = $type; - $hint = strtolower( - preg_replace( - '/([^\s]+)[\s]+.*/', - '$1', - $tokens[$type]['content'] - ) - ); - } elseif (in_array($tag['code'], self::$_casts, true)) { - $hint = strtolower( - preg_replace( - '/\(([^\s]+)\)/', - '$1', - $tag['content'] - ) - ); - } - - if (isset($hint, self::$_blacklist[$hint])) { - $error = sprintf( - 'For type-hinting in PHPDocs and casting, use %s instead of %s', - self::$_blacklist[$hint], - $hint - ); - - $fixable = $phpcsFile->addFixableError($error, $stackPtr, 'Invalid'); - - if (true === $fixable) { - - if ($fixPtr === $stackPtr) { - $fixedContent = self::$_blacklist[$hint]; - $fixedContent = "({$fixedContent})"; - } else { - $fixedContent = $tokens[$fixPtr]['content']; - $fixedContent = preg_replace( - "/^$hint/", - self::$_blacklist[$hint], - $fixedContent - ); - } - - $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->replaceToken($fixPtr, $fixedContent); - $phpcsFile->fixer->endChangeset(); - } - } - } -} diff --git a/Symfony/Sniffs/ControlStructure/IdenticalComparisonSniff.php b/Symfony/Sniffs/ControlStructure/IdenticalComparisonSniff.php deleted file mode 100644 index 266b028..0000000 --- a/Symfony/Sniffs/ControlStructure/IdenticalComparisonSniff.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony-coding-standard - */ - -namespace Symfony\Sniffs\ControlStructure; - -use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Sniffs\Sniff; - -/** - * Checks for identical comparison and adds warning if not used. - * - * @category PHP - * @package Symfony-coding-standard - * @author wicliff wolda - * @license http://spdx.org/licenses/MIT MIT License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class IdenticalComparisonSniff implements Sniff -{ - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_IS_EQUAL, - T_IS_NOT_EQUAL, - ); - } - - /** - * Called when one of the token types that this sniff is listening for - * is found. - * - * @param File $phpcsFile The file where the token was found. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void|int Optionally returns a stack pointer. The sniff will not be - * called again on the current file until the returned stack - * pointer is reached. Return (count($tokens) + 1) to skip - * the rest of the file. - */ - public function process(File $phpcsFile, $stackPtr) - { - $phpcsFile->addWarning( - 'Always use identical comparison unless you need type juggling', - $stackPtr, - 'Warning' - ); - } - -} diff --git a/Symfony/Sniffs/ControlStructure/YodaConditionsSniff.php b/Symfony/Sniffs/ControlStructure/YodaConditionsSniff.php deleted file mode 100644 index 0a681b2..0000000 --- a/Symfony/Sniffs/ControlStructure/YodaConditionsSniff.php +++ /dev/null @@ -1,97 +0,0 @@ - - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony-coding-standard - */ - -namespace Symfony\Sniffs\ControlStructure; - -use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Sniffs\Sniff; - -/** - * Checks whether variables are properly compared to expressions. - * - * @category PHP - * @package Symfony-coding-standard - * @author wicliff wolda - * @license http://spdx.org/licenses/MIT MIT License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class YodaConditionsSniff implements Sniff -{ - /** - * Tokens to require Yoda style for - * - * @var array - */ - private $_yodas = array( - T_IS_EQUAL, - T_IS_IDENTICAL, - T_IS_NOT_EQUAL, - T_IS_NOT_IDENTICAL, - ); - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_IF, - T_ELSEIF, - ); - } - - /** - * Called when one of the token types that this sniff is listening for - * is found. - * - * @param File $phpcsFile The file where the token was found. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void|int Optionally returns a stack pointer. The sniff will not be - * called again on the current file until the returned stack - * pointer is reached. Return (count($tokens) + 1) to skip - * the rest of the file. - */ - public function process(File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $opener = $tokens[$stackPtr]['parenthesis_opener']; - $closer = $tokens[$stackPtr]['parenthesis_closer']; - - do { - $comparison = $phpcsFile->findNext($this->_yodas, $opener + 1, $closer); - - if (false === $comparison) { - break; - } - - if (T_VARIABLE === $tokens[$comparison - 2]['code'] - && T_VARIABLE !== $tokens[$comparison + 2]['code'] - ) { - $error = 'Use Yoda conditions when checking a variable against '; - $error .= 'an expression to avoid an accidental assignment '; - $error .= 'inside the condition statement.'; - - $phpcsFile->addError($error, $stackPtr, 'Invalid'); - } - - $opener = $comparison + 1; - - } while ($opener < $closer); - } - -} diff --git a/Symfony/Sniffs/Functions/ArgumentsSniff.php b/Symfony/Sniffs/Functions/ArgumentsSniff.php deleted file mode 100644 index e7009aa..0000000 --- a/Symfony/Sniffs/Functions/ArgumentsSniff.php +++ /dev/null @@ -1,77 +0,0 @@ - - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony-coding-standard - */ - -namespace Symfony\Sniffs\Functions; - -use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Sniffs\Sniff; - -/** - * Checks whether functions are defined on one line. - * - * @category PHP - * @package Symfony-coding-standard - * @author wicliff wolda - * @license http://spdx.org/licenses/MIT MIT License - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class ArgumentsSniff implements Sniff -{ - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return array - */ - public function register() - { - return array( - T_FUNCTION, - ); - } - - /** - * Called when one of the token types that this sniff is listening for - * is found. - * - * @param File $phpcsFile The file where the token was found. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void|int Optionally returns a stack pointer. The sniff will not be - * called again on the current file until the returned stack - * pointer is reached. Return (count($tokens) + 1) to skip - * the rest of the file. - */ - public function process(File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $function = $tokens[$stackPtr]; - - $openerLine = $tokens[$function['parenthesis_opener']]['line']; - $closerLine = $tokens[$function['parenthesis_closer']]['line']; - - if ($openerLine !== $closerLine) { - $error = 'Declare all the arguments on the same line '; - $error .= 'as the method/function name, '; - $error .= 'no matter how many arguments there are.'; - - $phpcsFile->addError( - $error, - $stackPtr, - 'Invalid' - ); - } - } - -} diff --git a/Symfony/Sniffs/Functions/ScopeOrderSniff.php b/Symfony/Sniffs/Functions/ScopeOrderSniff.php index 15346e7..15c92aa 100644 --- a/Symfony/Sniffs/Functions/ScopeOrderSniff.php +++ b/Symfony/Sniffs/Functions/ScopeOrderSniff.php @@ -83,11 +83,7 @@ public function process(File $phpcsFile, $stackPtr) ); while ($function) { - $end = null; - - if (isset($tokens[$stackPtr]['scope_closer'])) { - $end = $tokens[$stackPtr]['scope_closer']; - } + $end = $tokens[$stackPtr]['scope_closer'] ?? null; $function = $phpcsFile->findNext( array( diff --git a/Symfony/Tests/Commenting/TypeHintingUnitTest.inc b/Symfony/Tests/Commenting/TypeHintingUnitTest.inc deleted file mode 100644 index 5bcbca1..0000000 --- a/Symfony/Tests/Commenting/TypeHintingUnitTest.inc +++ /dev/null @@ -1,30 +0,0 @@ - - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony2-coding-standard - */ - -namespace Symfony\Tests\Commenting; - -use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; - -/** - * Unit test class for the TypeHintingUnitTest sniff. - * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * PHP version 5 - * - * @category PHP - * @package Symfony2-coding-standard - * @author wicliff - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony2-coding-standard - */ -class TypeHintingUnitTest extends AbstractSniffUnitTest -{ - /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array - */ - public function getErrorList() - { - return array( - 6 => 1, - 11 => 1, - 22 => 1, - 23 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array - */ - public function getWarningList() - { - return array(); - } -} diff --git a/Symfony/Tests/ControlStructure/IdenticalComparisonUnitTest.inc b/Symfony/Tests/ControlStructure/IdenticalComparisonUnitTest.inc deleted file mode 100644 index 8736537..0000000 --- a/Symfony/Tests/ControlStructure/IdenticalComparisonUnitTest.inc +++ /dev/null @@ -1,9 +0,0 @@ - - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony2-coding-standard - */ - -namespace Symfony\Tests\ControlStructure; - -use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; - -/** - * Unit test class for the IdenticalComparisonUnitTest sniff. - * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * PHP version 5 - * - * @category PHP - * @package Symfony-coding-standard - * @author wicliff - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony2-coding-standard - */ -class IdenticalComparisonUnitTest extends AbstractSniffUnitTest -{ - /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array - */ - public function getErrorList() - { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array - */ - public function getWarningList() - { - return array( - 3 => 1, - 7 => 1, - ); - } -} diff --git a/Symfony/Tests/ControlStructure/YodaConditionsUnitTest.inc b/Symfony/Tests/ControlStructure/YodaConditionsUnitTest.inc deleted file mode 100644 index 067c371..0000000 --- a/Symfony/Tests/ControlStructure/YodaConditionsUnitTest.inc +++ /dev/null @@ -1,9 +0,0 @@ - - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony2-coding-standard - */ - -namespace Symfony\Tests\ControlStructure; - -use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; - -/** - * Unit test class for the YodaConditionsUnitTest sniff. - * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * PHP version 5 - * - * @category PHP - * @package Symfony-coding-standard - * @author wicliff - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony2-coding-standard - */ -class YodaConditionsUnitTest extends AbstractSniffUnitTest -{ - /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array - */ - public function getErrorList() - { - return array( - 3 => 1, - 7 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array - */ - public function getWarningList() - { - return array(); - } -} diff --git a/Symfony/Tests/Functions/ArgumentsUnitTest.inc b/Symfony/Tests/Functions/ArgumentsUnitTest.inc deleted file mode 100644 index 34f8a44..0000000 --- a/Symfony/Tests/Functions/ArgumentsUnitTest.inc +++ /dev/null @@ -1,12 +0,0 @@ - - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony2-coding-standard - */ - -namespace Symfony\Tests\Functions; - -use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; - -/** - * Unit test class for the ArgumentsUnitTest sniff. - * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings are stored in this class. - * - * PHP version 5 - * - * @category PHP - * @package Symfony-coding-standard - * @author wicliff - * @license http://spdx.org/licenses/MIT MIT License - * @link https://github.com/djoos/Symfony2-coding-standard - */ -class ArgumentsUnitTest extends AbstractSniffUnitTest -{ - /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array - */ - public function getErrorList() - { - return array( - 3 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array - */ - public function getWarningList() - { - return array(); - } -} diff --git a/Symfony/ruleset.xml b/Symfony/ruleset.xml index 4ef6dc5..8833208 100755 --- a/Symfony/ruleset.xml +++ b/Symfony/ruleset.xml @@ -10,9 +10,13 @@ - + + + + + + @@ -108,4 +112,14 @@ There should always be a description, followed by a blank line, before the tags of a class comment. + + + + + + + + + + diff --git a/composer.json b/composer.json index b6817e0..b9f65d0 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "issues": "https://github.com/djoos/Symfony-coding-standard/issues" }, "require": { - "squizlabs/php_codesniffer": "^3.3.1" + "squizlabs/php_codesniffer": "^3.3.1", + "slevomat/coding-standard": "^7.0" }, "require-dev": { "phpunit/phpunit": "^5.0 || ^6.0 || ^7.0"