From 78cb9c5b3d931bede57844aa9e7b327da11996a5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 25 Aug 2023 05:00:57 +0200 Subject: [PATCH 01/32] Update for PHPUnit Polyfills 1.1.0 The Polyfills 1.1.0 backport a trait which was made available in the 2.0.0 version. This updates the `PolyfilledTestCase` to take that into account and updates the minimum supported version in Composer. Ref: https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/1.1.0 --- Tests/PolyfilledTestCase.php | 1 + composer.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/PolyfilledTestCase.php b/Tests/PolyfilledTestCase.php index 2cd04b3c..4cce3293 100644 --- a/Tests/PolyfilledTestCase.php +++ b/Tests/PolyfilledTestCase.php @@ -103,6 +103,7 @@ abstract class PolyfilledTestCase extends UtilityMethodTestCase use AssertIsType; use AssertNumericType; use AssertObjectEquals; + use AssertObjectProperty; use AssertStringContains; use EqualToSpecializations; use ExpectException; diff --git a/composer.json b/composer.json index 8c0e8d45..2ff4cf91 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "phpcsstandards/phpcsdevcs": "^1.1.6", "php-parallel-lint/php-parallel-lint": "^1.3.2", "php-parallel-lint/php-console-highlighter": "^1.0", - "yoast/phpunit-polyfills": "^1.0.5 || ^2.0.0" + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0" }, "minimum-stability": "dev", "prefer-stable": true, From d55e09158c98b74cb502a0a4b430703f4cd494bc Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 24 Aug 2023 22:21:28 +0200 Subject: [PATCH 02/32] Tests: minor clean up Remove some stray parameters from implementations which were eventually rejected or removed. --- Tests/Internal/IsShortArrayOrList/SolveTest.php | 2 +- Tests/Internal/IsShortArrayOrList/WalkInsideTest.php | 8 ++++---- Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php | 2 +- Tests/Utils/Namespaces/DetermineNamespaceTest.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/Internal/IsShortArrayOrList/SolveTest.php b/Tests/Internal/IsShortArrayOrList/SolveTest.php index 1e136ed0..45788bde 100644 --- a/Tests/Internal/IsShortArrayOrList/SolveTest.php +++ b/Tests/Internal/IsShortArrayOrList/SolveTest.php @@ -37,7 +37,7 @@ final class SolveTest extends UtilityMethodTestCase public function testSolve($testMarker, $expected) { $stackPtr = $this->getTargetToken($testMarker, StableCollections::$shortArrayListOpenTokensBC); - $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr, []); + $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr); $type = $solver->solve(); $this->assertSame($expected, $type); diff --git a/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php b/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php index 8a23c0cd..4e7a64d5 100644 --- a/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php +++ b/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php @@ -36,7 +36,7 @@ final class WalkInsideTest extends UtilityMethodTestCase public function testWalkInsideUndetermined($testMarker, $expected) { $stackPtr = $this->getTargetToken($testMarker, [\T_OPEN_SHORT_ARRAY]); - $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr, []); + $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr); $type = $solver->solve(); $this->assertSame($expected, $type); @@ -121,7 +121,7 @@ public static function dataWalkInsideUndetermined() public function testWalkInsideResolved($testMarker, $expected) { $stackPtr = $this->getTargetToken($testMarker, [\T_OPEN_SHORT_ARRAY]); - $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr, []); + $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr); $type = $solver->solve(); $this->assertSame($expected, $type); @@ -244,7 +244,7 @@ public static function dataWalkInsideResolved() public function testSampleTooSmall() { $stackPtr = $this->getTargetToken('/* testNestedShortArraySampleTooSmall */', \T_OPEN_SHORT_ARRAY); - $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr, []); + $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr); $type = $solver->solve(); $this->assertSame(IsShortArrayOrList::SHORT_ARRAY, $type); @@ -263,7 +263,7 @@ public function testSampleTooSmall() public function testRecursionLimit($testMarker, $expected) { $stackPtr = $this->getTargetToken($testMarker, [\T_OPEN_SHORT_ARRAY]); - $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr, []); + $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr); $type = $solver->solve(); $this->assertSame($expected, $type); diff --git a/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php b/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php index 820eb0a2..012be957 100644 --- a/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php +++ b/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php @@ -39,7 +39,7 @@ final class WalkOutsideTest extends UtilityMethodTestCase public function testWalkOutside($testMarker, $expected) { $stackPtr = $this->getTargetToken($testMarker, [\T_OPEN_SHORT_ARRAY]); - $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr, []); + $solver = new IsShortArrayOrList(self::$phpcsFile, $stackPtr); $type = $solver->solve(); $this->assertSame($expected, $type); diff --git a/Tests/Utils/Namespaces/DetermineNamespaceTest.php b/Tests/Utils/Namespaces/DetermineNamespaceTest.php index 8799e8fd..c00ee201 100644 --- a/Tests/Utils/Namespaces/DetermineNamespaceTest.php +++ b/Tests/Utils/Namespaces/DetermineNamespaceTest.php @@ -260,7 +260,7 @@ public function testFallbackToEmptyString() $result = Namespaces::findNamespacePtr(self::$phpcsFile, $stackPtr); $this->assertSame($expected, $result, 'Failed test with findNamespacePtr'); - $result = Namespaces::determineNamespace(self::$phpcsFile, $stackPtr, false); + $result = Namespaces::determineNamespace(self::$phpcsFile, $stackPtr); $this->assertSame('', $result, 'Failed test with determineNamespace'); } } From 6a55ba59bf253b8df05b40fbafe1dbccbcdb8836 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 25 Aug 2023 03:03:09 +0200 Subject: [PATCH 03/32] [NoFile]Cache/SetTest: pass correct type to base_convert() The PHP native `base_convert()` function expects a string as the first parameter. While this is not really a problem, as without `strict_types`, PHP will just juggle the type from `int` to `string`, it is still good to be explicit. Ref: https://www.php.net/manual/en/function.base-convert.php --- Tests/Internal/Cache/SetTest.php | 2 +- Tests/Internal/NoFileCache/SetTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Internal/Cache/SetTest.php b/Tests/Internal/Cache/SetTest.php index 343cf0cb..28df3ed7 100644 --- a/Tests/Internal/Cache/SetTest.php +++ b/Tests/Internal/Cache/SetTest.php @@ -95,7 +95,7 @@ public static function resetCachingStatus() */ public function testSetAcceptsEveryTypeOfInput($input) { - $id = \base_convert(\rand((int) 10e16, (int) 10e20), 10, 36); + $id = \base_convert((string) \rand((int) 10e16, (int) 10e20), 10, 36); Cache::set(self::$phpcsFile, __METHOD__, $id, $input); $this->assertTrue( diff --git a/Tests/Internal/NoFileCache/SetTest.php b/Tests/Internal/NoFileCache/SetTest.php index aaeb4faf..fc327001 100644 --- a/Tests/Internal/NoFileCache/SetTest.php +++ b/Tests/Internal/NoFileCache/SetTest.php @@ -89,7 +89,7 @@ public static function resetCachingStatus() */ public function testSetAcceptsEveryTypeOfInput($input) { - $id = \base_convert(\rand((int) 10e16, (int) 10e20), 10, 36); + $id = \base_convert((string) \rand((int) 10e16, (int) 10e20), 10, 36); NoFileCache::set(__METHOD__, $id, $input); $this->assertTrue( From 0a5408c8219f80a0125a9c2c47d84392bb8520af Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 25 Aug 2023 03:03:57 +0200 Subject: [PATCH 04/32] Exceptions/TestTargetNotFound: improve defensive coding --- PHPCSUtils/Exceptions/TestTargetNotFound.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCSUtils/Exceptions/TestTargetNotFound.php b/PHPCSUtils/Exceptions/TestTargetNotFound.php index 0e9eed68..d9838080 100644 --- a/PHPCSUtils/Exceptions/TestTargetNotFound.php +++ b/PHPCSUtils/Exceptions/TestTargetNotFound.php @@ -34,7 +34,7 @@ final class TestTargetNotFound extends OutOfBoundsException public static function create($marker, $content, $file) { $contentPhrase = ''; - if ($content !== null) { + if (\is_string($content)) { $contentPhrase = ' with token content: ' . $content; } From d08c2d0b132946de0bc0a0196e0866fcf4dd4738 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 25 Aug 2023 02:12:21 +0200 Subject: [PATCH 05/32] CS/QA: remove some redundant code --- Tests/BackCompat/Helper/GetVersionTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/BackCompat/Helper/GetVersionTest.php b/Tests/BackCompat/Helper/GetVersionTest.php index 162b6070..1667387e 100644 --- a/Tests/BackCompat/Helper/GetVersionTest.php +++ b/Tests/BackCompat/Helper/GetVersionTest.php @@ -46,8 +46,6 @@ public function testGetVersion() $this->markTestSkipped('The test for the Helper::getVersion() method will only run' . ' if the PHPCS_VERSION environment variable is set, such as during a CI build' . ' or when this variable has been set in the PHPUnit configuration file.'); - - return; } if ($expected === 'lowest') { From 58757e0c396b27a5a0b178168758293f218862e7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 24 Aug 2023 22:32:43 +0200 Subject: [PATCH 06/32] Docs: various `@var`/`@param`/`@return` tag improvements Not claiming completeness. This is just another iteration step in improving the documented types. Includes minor tweak to the PHPCS ruleset to allow for the longer types and still have a var/param/return description. --- .../AbstractArrayDeclarationSniff.php | 8 +- PHPCSUtils/BackCompat/BCFile.php | 32 +++--- PHPCSUtils/BackCompat/BCTokens.php | 10 +- PHPCSUtils/BackCompat/Helper.php | 2 +- PHPCSUtils/Exceptions/TestTargetNotFound.php | 2 +- PHPCSUtils/Internal/Cache.php | 5 +- PHPCSUtils/Internal/IsShortArrayOrList.php | 4 +- .../Internal/IsShortArrayOrListWithCache.php | 2 +- PHPCSUtils/Internal/NoFileCache.php | 2 +- PHPCSUtils/Internal/StableCollections.php | 4 +- .../TestUtils/UtilityMethodTestCase.php | 12 +-- PHPCSUtils/Tokens/Collections.php | 92 ++++++++-------- PHPCSUtils/Utils/Arrays.php | 20 ++-- PHPCSUtils/Utils/Conditions.php | 30 +++--- PHPCSUtils/Utils/ControlStructures.php | 3 +- PHPCSUtils/Utils/FunctionDeclarations.php | 10 +- PHPCSUtils/Utils/Lists.php | 23 ++-- PHPCSUtils/Utils/MessageHelper.php | 4 +- PHPCSUtils/Utils/Numbers.php | 2 +- PHPCSUtils/Utils/ObjectDeclarations.php | 28 ++--- PHPCSUtils/Utils/Operators.php | 2 +- PHPCSUtils/Utils/Parentheses.php | 100 +++++++++--------- PHPCSUtils/Utils/PassedParameters.php | 44 ++++---- PHPCSUtils/Utils/Scopes.php | 10 +- PHPCSUtils/Utils/UseStatements.php | 52 ++++----- PHPCSUtils/Utils/Variables.php | 4 +- .../AbstractArrayDeclarationSniffTest.php | 2 +- .../ArrayDeclarationSniffTestDouble.php | 2 +- Tests/BackCompat/BCFile/GetConditionTest.php | 10 +- .../BCFile/GetMemberPropertiesTest.php | 2 +- .../BCTokens/UnchangedTokenArraysTest.php | 22 ++-- .../SpacesFixer/SpacesFixerAtEOFTest.php | 2 +- .../SpacesFixer/SpacesFixerNewlineTest.php | 2 +- .../SpacesFixer/SpacesFixerNoSpaceTest.php | 2 +- .../SpacesFixer/SpacesFixerOneSpaceTest.php | 2 +- .../SpacesFixer/SpacesFixerTestCase.php | 8 +- .../SpacesFixer/SpacesFixerTwoSpaceTest.php | 2 +- .../TrailingCommentHandlingNewlineTest.php | 2 +- .../TrailingCommentHandlingTest.php | 2 +- Tests/Utils/Arrays/GetDoubleArrowPtrTest.php | 6 +- .../GetParametersDiffTest.php | 7 +- Tests/Utils/MessageHelper/AddMessageTest.php | 2 +- Tests/Utils/Numbers/NumberTypesTest.php | 10 +- Tests/Utils/Parentheses/ParenthesesTest.php | 6 +- .../GetParameterFromStackTest.php | 2 +- .../GetParametersWithLimitTest.php | 2 +- .../TextStrings/GetCompleteTextStringTest.php | 2 +- .../TextStrings/InterpolatedVariablesTest.php | 2 +- .../Variables/GetMemberPropertiesDiffTest.php | 2 +- Tests/Xtra/Messages/HasNewLineSupportTest.php | 2 +- phpcs.xml.dist | 13 +++ 51 files changed, 324 insertions(+), 299 deletions(-) diff --git a/PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php b/PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php index 21420a8e..b79a3fdc 100644 --- a/PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php +++ b/PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php @@ -42,7 +42,7 @@ abstract class AbstractArrayDeclarationSniff implements Sniff * * @since 1.0.0 * - * @var array + * @var array> */ protected $tokens; @@ -79,7 +79,7 @@ abstract class AbstractArrayDeclarationSniff implements Sniff * * @since 1.0.0 * - * @var array + * @var array> */ protected $arrayItems; @@ -108,7 +108,7 @@ abstract class AbstractArrayDeclarationSniff implements Sniff * * @since 1.0.0 * - * @var array + * @var array */ private $acceptedTokens = [ \T_NULL => \T_NULL, @@ -152,7 +152,7 @@ final public function __construct() * * @codeCoverageIgnore * - * @return array + * @return array */ public function register() { diff --git a/PHPCSUtils/BackCompat/BCFile.php b/PHPCSUtils/BackCompat/BCFile.php index 030bde4b..6b8cab44 100644 --- a/PHPCSUtils/BackCompat/BCFile.php +++ b/PHPCSUtils/BackCompat/BCFile.php @@ -201,7 +201,7 @@ public static function getDeclarationName(File $phpcsFile, $stackPtr) * @param int $stackPtr The position in the stack of the function token * to acquire the parameters for. * - * @return array + * @return array> * * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified `$stackPtr` is not of * type `T_FUNCTION`, `T_CLOSURE`, `T_USE`, @@ -509,7 +509,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr) * @param int $stackPtr The position in the stack of the function token to * acquire the properties for. * - * @return array + * @return array * * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position is not a * `T_FUNCTION`, `T_CLOSURE`, or `T_FN` token. @@ -554,7 +554,7 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr) * @param int $stackPtr The position in the stack of the `T_VARIABLE` token to * acquire the properties for. * - * @return array + * @return array * * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position is not a * `T_VARIABLE` token, or if the position is not @@ -573,7 +573,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr) * array( * 'is_abstract' => boolean, // TRUE if the abstract keyword was found. * 'is_final' => boolean, // TRUE if the final keyword was found. - * 'is_readonly' => false, // TRUE if the readonly keyword was found. + * 'is_readonly' => boolean, // TRUE if the readonly keyword was found. * ); * ``` * @@ -593,7 +593,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr) * @param int $stackPtr The position in the stack of the `T_CLASS` * token to acquire the properties for. * - * @return array + * @return array * * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position is not a * `T_CLASS` token. @@ -714,9 +714,9 @@ public static function getTokensAsString(File $phpcsFile, $start, $length, $orig * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. - * @param int $start The position to start searching from in the token stack. - * @param int|string|array $ignore Token types that should not be considered stop points. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $start The position to start searching from in the token stack. + * @param int|string|array $ignore Token types that should not be considered stop points. * * @return int */ @@ -738,9 +738,9 @@ public static function findStartOfStatement(File $phpcsFile, $start, $ignore = n * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. - * @param int $start The position to start searching from in the token stack. - * @param int|string|array $ignore Token types that should not be considered stop points. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $start The position to start searching from in the token stack. + * @param int|string|array $ignore Token types that should not be considered stop points. * * @return int */ @@ -763,9 +763,9 @@ public static function findEndOfStatement(File $phpcsFile, $start, $ignore = nul * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $types The type(s) of tokens to search for. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $types The type(s) of tokens to search for. * * @return bool */ @@ -847,8 +847,8 @@ public static function findExtendedClassName(File $phpcsFile, $stackPtr) * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The stack position of the class or enum token. * - * @return array|false Array with names of the implemented interfaces or `FALSE` on - * error or if there are no implemented interface names. + * @return string[]|false Array with names of the implemented interfaces or `FALSE` on + * error or if there are no implemented interface names. */ public static function findImplementedInterfaceNames(File $phpcsFile, $stackPtr) { diff --git a/PHPCSUtils/BackCompat/BCTokens.php b/PHPCSUtils/BackCompat/BCTokens.php index 78591164..c7ac15fb 100644 --- a/PHPCSUtils/BackCompat/BCTokens.php +++ b/PHPCSUtils/BackCompat/BCTokens.php @@ -78,11 +78,11 @@ final class BCTokens * * @since 1.0.0 * - * @param string $name The name of the method which has been called. - * @param array $args Any arguments passed to the method. - * Unused as none of the methods take arguments. + * @param string $name The name of the method which has been called. + * @param array $args Any arguments passed to the method. + * Unused as none of the methods take arguments. * - * @return array => Token array + * @return array Token array * * @throws \PHPCSUtils\Exceptions\InvalidTokenArray When an invalid token array is requested. */ @@ -110,7 +110,7 @@ public static function __callStatic($name, $args) * * @since 1.0.0 * - * @return array => Token array. + * @return array Token array. */ public static function functionNameTokens() { diff --git a/PHPCSUtils/BackCompat/Helper.php b/PHPCSUtils/BackCompat/Helper.php index c3a30257..7352a8cb 100644 --- a/PHPCSUtils/BackCompat/Helper.php +++ b/PHPCSUtils/BackCompat/Helper.php @@ -52,7 +52,7 @@ public static function getVersion() * @since 1.0.0 * * @param string $key The name of the config value. - * @param string|null $value The value to set. If `null`, the config entry + * @param mixed $value The value to set. If `null`, the config entry * is deleted, reverting it to the default value. * @param bool $temp Set this config data temporarily for this script run. * This will not write the config data to the config file. diff --git a/PHPCSUtils/Exceptions/TestTargetNotFound.php b/PHPCSUtils/Exceptions/TestTargetNotFound.php index d9838080..4f9e5b4e 100644 --- a/PHPCSUtils/Exceptions/TestTargetNotFound.php +++ b/PHPCSUtils/Exceptions/TestTargetNotFound.php @@ -29,7 +29,7 @@ final class TestTargetNotFound extends OutOfBoundsException * @param string $content The (optional) target token content. * @param string $file The file in which the target token was not found. * - * @return \PHPCSUtils\Exceptions\TestMarkerNotFound + * @return \PHPCSUtils\Exceptions\TestTargetNotFound */ public static function create($marker, $content, $file) { diff --git a/PHPCSUtils/Internal/Cache.php b/PHPCSUtils/Internal/Cache.php index 3843f03d..2f7873fe 100644 --- a/PHPCSUtils/Internal/Cache.php +++ b/PHPCSUtils/Internal/Cache.php @@ -68,7 +68,8 @@ final class Cache * * @since 1.0.0 * - * @var array> Format: $cache[$loop][$fileName][$key][$id] = mixed $value; + * @var array>>> + * Format: $cache[$loop][$fileName][$key][$id] = mixed $value; */ private static $cache = []; @@ -144,7 +145,7 @@ public static function get(File $phpcsFile, $key, $id) * @param string $key The key to identify a particular set of results. * It is recommended to pass __METHOD__ to this parameter. * - * @return array + * @return array */ public static function getForFile(File $phpcsFile, $key) { diff --git a/PHPCSUtils/Internal/IsShortArrayOrList.php b/PHPCSUtils/Internal/IsShortArrayOrList.php index f056d623..28a38989 100644 --- a/PHPCSUtils/Internal/IsShortArrayOrList.php +++ b/PHPCSUtils/Internal/IsShortArrayOrList.php @@ -114,7 +114,7 @@ final class IsShortArrayOrList * * @since 1.0.0 * - * @var array + * @var array> */ private $tokens; @@ -168,7 +168,7 @@ final class IsShortArrayOrList * * @since 1.0.0 * - * @return array => + * @var array */ private $openBrackets; diff --git a/PHPCSUtils/Internal/IsShortArrayOrListWithCache.php b/PHPCSUtils/Internal/IsShortArrayOrListWithCache.php index 72f854f0..b1b8c47e 100644 --- a/PHPCSUtils/Internal/IsShortArrayOrListWithCache.php +++ b/PHPCSUtils/Internal/IsShortArrayOrListWithCache.php @@ -58,7 +58,7 @@ final class IsShortArrayOrListWithCache * * @since 1.0.0 * - * @var array + * @var array> */ private $tokens; diff --git a/PHPCSUtils/Internal/NoFileCache.php b/PHPCSUtils/Internal/NoFileCache.php index 6e7d08dd..2f7a2478 100644 --- a/PHPCSUtils/Internal/NoFileCache.php +++ b/PHPCSUtils/Internal/NoFileCache.php @@ -116,7 +116,7 @@ public static function get($key, $id) * @param string $key The key to identify a particular set of results. * It is recommended to pass `__METHOD__` to this parameter. * - * @return array + * @return array */ public static function getForKey($key) { diff --git a/PHPCSUtils/Internal/StableCollections.php b/PHPCSUtils/Internal/StableCollections.php index 7d8d92f0..593392df 100644 --- a/PHPCSUtils/Internal/StableCollections.php +++ b/PHPCSUtils/Internal/StableCollections.php @@ -46,7 +46,7 @@ final class StableCollections * * @since 1.0.2 * - * @var array => + * @var array */ public static $shortArrayListOpenTokensBC = [ \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, @@ -64,7 +64,7 @@ final class StableCollections * * @since 1.0.2 * - * @var array => + * @var array */ public static $shortArrayListTokensBC = [ \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, diff --git a/PHPCSUtils/TestUtils/UtilityMethodTestCase.php b/PHPCSUtils/TestUtils/UtilityMethodTestCase.php index fcc1e75a..20780dc4 100644 --- a/PHPCSUtils/TestUtils/UtilityMethodTestCase.php +++ b/PHPCSUtils/TestUtils/UtilityMethodTestCase.php @@ -154,7 +154,7 @@ abstract class UtilityMethodTestCase extends TestCase * * @since 1.0.0 * - * @var \PHP_CodeSniffer\Files\File + * @var \PHP_CodeSniffer\Files\File|null */ protected static $phpcsFile; @@ -168,7 +168,7 @@ abstract class UtilityMethodTestCase extends TestCase * * @since 1.0.0 * - * @var array + * @var string[] */ protected static $selectedSniff = ['Dummy.Dummy.Dummy']; @@ -329,10 +329,10 @@ public static function usesPhp8NameTokens() * * @since 1.0.0 * - * @param string $commentString The complete delimiter comment to look for as a string. - * This string should include the comment opener and closer. - * @param int|string|array $tokenType The type of token(s) to look for. - * @param string $tokenContent Optional. The token content for the target token. + * @param string $commentString The complete delimiter comment to look for as a string. + * This string should include the comment opener and closer. + * @param int|string|array $tokenType The type of token(s) to look for. + * @param string $tokenContent Optional. The token content for the target token. * * @return int * diff --git a/PHPCSUtils/Tokens/Collections.php b/PHPCSUtils/Tokens/Collections.php index 09ed84b4..a84846f0 100644 --- a/PHPCSUtils/Tokens/Collections.php +++ b/PHPCSUtils/Tokens/Collections.php @@ -67,7 +67,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::alternativeControlStructureSyntaxes()} method for access. * - * @var array => + * @var array */ private static $alternativeControlStructureSyntaxes = [ \T_IF => \T_IF, @@ -85,7 +85,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::alternativeControlStructureSyntaxClosers()} method for access. * - * @var array => + * @var array */ private static $alternativeControlStructureSyntaxClosers = [ \T_ENDIF => \T_ENDIF, @@ -109,7 +109,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::arrayOpenTokensBC()} method for access. * - * @var array => + * @var array */ private static $arrayOpenTokensBC = [ \T_ARRAY => \T_ARRAY, @@ -128,7 +128,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::arrayTokens()} method for access. * - * @var array => + * @var array */ private static $arrayTokens = [ \T_ARRAY => \T_ARRAY, @@ -141,7 +141,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::classModifierKeywords()} method for access. * - * @var array => + * @var array */ private static $classModifierKeywords = [ \T_FINAL => \T_FINAL, @@ -160,7 +160,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::closedScopes()} method for access. * - * @var array => + * @var array */ private static $closedScopes = [ \T_CLASS => \T_CLASS, @@ -180,7 +180,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::constantModifierKeywords()} method for access. * - * @var array => + * @var array */ private static $constantModifierKeywords = [ \T_PUBLIC => \T_PUBLIC, @@ -194,7 +194,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::controlStructureTokens()} method for access. * - * @var array => + * @var array */ private static $controlStructureTokens = [ \T_IF => \T_IF, @@ -214,7 +214,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::functionDeclarationTokens()} method for access. * - * @var array => + * @var array */ private static $functionDeclarationTokens = [ \T_FUNCTION => \T_FUNCTION, @@ -227,7 +227,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::incrementDecrementOperators()} method for access. * - * @var array => + * @var array */ private static $incrementDecrementOperators = [ \T_DEC => \T_DEC, @@ -247,7 +247,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::listOpenTokensBC()} method for access. * - * @var array => + * @var array */ private static $listOpenTokensBC = [ \T_LIST => \T_LIST, @@ -264,7 +264,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::listTokens()} method for access. * - * @var array => + * @var array */ private static $listTokens = [ \T_LIST => \T_LIST, @@ -277,7 +277,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::namespaceDeclarationClosers()} method for access. * - * @var array => + * @var array */ private static $namespaceDeclarationClosers = [ \T_SEMICOLON => \T_SEMICOLON, @@ -298,7 +298,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::nameTokens()} method for access. * - * @var array => + * @var array */ private static $nameTokens = [ \T_STRING => \T_STRING, @@ -312,7 +312,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::objectOperators()} method for access. * - * @var array => + * @var array */ private static $objectOperators = [ \T_DOUBLE_COLON => \T_DOUBLE_COLON, @@ -325,7 +325,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::ooCanExtend()} method for access. * - * @var array => + * @var array */ private static $ooCanExtend = [ \T_CLASS => \T_CLASS, @@ -338,7 +338,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::ooCanImplement()} method for access. * - * @var array => + * @var array */ private static $ooCanImplement = [ \T_CLASS => \T_CLASS, @@ -353,7 +353,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::ooConstantScopes()} method for access. * - * @var array => + * @var array */ private static $ooConstantScopes = [ \T_CLASS => \T_CLASS, @@ -370,7 +370,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::ooHierarchyKeywords()} method for access. * - * @var array => + * @var array */ private static $ooHierarchyKeywords = [ \T_PARENT => \T_PARENT, @@ -385,7 +385,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::ooPropertyScopes()} method for access. * - * @var array => + * @var array */ private static $ooPropertyScopes = [ \T_CLASS => \T_CLASS, @@ -398,7 +398,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::parameterTypeTokens()} method for access. * - * @var array => + * @var array */ private static $parameterTypeTokens = [ \T_CALLABLE => \T_CALLABLE, @@ -416,7 +416,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::phpOpenTags()} method for access. * - * @var array => + * @var array */ private static $phpOpenTags = [ \T_OPEN_TAG => \T_OPEN_TAG, @@ -428,7 +428,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::propertyModifierKeywords()} method for access. * - * @var array => + * @var array */ private static $propertyModifierKeywords = [ \T_PUBLIC => \T_PUBLIC, @@ -444,7 +444,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::propertyTypeTokens()} method for access. * - * @var array => + * @var array */ private static $propertyTypeTokens = [ \T_CALLABLE => \T_CALLABLE, @@ -462,7 +462,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::returnTypeTokens()} method for access. * - * @var array => + * @var array */ private static $returnTypeTokens = [ \T_CALLABLE => \T_CALLABLE, @@ -481,7 +481,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::shortArrayListOpenTokensBC()} method for access. * - * @var array => + * @var array */ private static $shortArrayListOpenTokensBC = [ \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, @@ -494,7 +494,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::shortArrayTokens()} method for access. * - * @var array => + * @var array */ private static $shortArrayTokens = [ \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, @@ -508,7 +508,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::shortListTokens()} method for access. * - * @var array => + * @var array */ private static $shortListTokens = [ \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, @@ -520,7 +520,7 @@ final class Collections * * @since 1.0.0 Use the {@see Collections::textStringStartTokens()} method for access. * - * @var array => + * @var array */ private static $textStringStartTokens = [ \T_START_HEREDOC => \T_START_HEREDOC, @@ -534,11 +534,11 @@ final class Collections * * @since 1.0.0 * - * @param string $name The name of the method which has been called. - * @param array $args Any arguments passed to the method. - * Unused as none of the methods take arguments. + * @param string $name The name of the method which has been called. + * @param array $args Any arguments passed to the method. + * Unused as none of the methods take arguments. * - * @return array => Token array + * @return array Token array * * @throws \PHPCSUtils\Exceptions\InvalidTokenArray When an invalid token array is requested. */ @@ -592,7 +592,7 @@ private static function triggerDeprecation($method, $version, $replacement) * * @since 1.0.0 * - * @return array => + * @return array */ public static function arrayOpenTokensBC() { @@ -619,7 +619,7 @@ public static function arrayOpenTokensBC() * * @since 1.0.0 * - * @return array => + * @return array */ public static function arrayTokensBC() { @@ -640,7 +640,7 @@ public static function arrayTokensBC() * * @since 1.0.0 * - * @return array => + * @return array */ public static function functionCallTokens() { @@ -669,7 +669,7 @@ public static function functionCallTokens() * * @since 1.0.0 * - * @return array => + * @return array */ public static function listOpenTokensBC() { @@ -694,7 +694,7 @@ public static function listOpenTokensBC() * * @since 1.0.0 * - * @return array => + * @return array */ public static function listTokensBC() { @@ -718,7 +718,7 @@ public static function listTokensBC() * * @since 1.0.0 * - * @return array => + * @return array */ public static function namespacedNameTokens() { @@ -739,7 +739,7 @@ public static function namespacedNameTokens() * * @since 1.0.0 * - * @return array => + * @return array */ public static function parameterPassingTokens() { @@ -761,7 +761,7 @@ public static function parameterPassingTokens() * * @since 1.0.0 * - * @return array => + * @return array */ public static function parameterTypeTokens() { @@ -776,7 +776,7 @@ public static function parameterTypeTokens() * * @since 1.0.0 * - * @return array => + * @return array */ public static function propertyTypeTokens() { @@ -791,7 +791,7 @@ public static function propertyTypeTokens() * * @since 1.0.0 * - * @return array => + * @return array */ public static function returnTypeTokens() { @@ -811,7 +811,7 @@ public static function returnTypeTokens() * * @since 1.0.0 * - * @return array => + * @return array */ public static function shortArrayListOpenTokensBC() { @@ -836,7 +836,7 @@ public static function shortArrayListOpenTokensBC() * * @since 1.0.0 * - * @return array => + * @return array */ public static function shortArrayTokensBC() { @@ -862,7 +862,7 @@ public static function shortArrayTokensBC() * * @since 1.0.0 * - * @return array => + * @return array */ public static function shortListTokensBC() { diff --git a/PHPCSUtils/Utils/Arrays.php b/PHPCSUtils/Utils/Arrays.php index 3fe7a100..1e228413 100644 --- a/PHPCSUtils/Utils/Arrays.php +++ b/PHPCSUtils/Utils/Arrays.php @@ -29,7 +29,7 @@ final class Arrays * * @since 1.0.0 * - * @var array => + * @var array */ private static $doubleArrowTargets = [ \T_DOUBLE_ARROW => \T_DOUBLE_ARROW, @@ -86,15 +86,15 @@ public static function isShortArray(File $phpcsFile, $stackPtr) * tokens in an array. * Use with care. * - * @return array|false An array with the token pointers; or `FALSE` if this is not a - * (short) array token or if the opener/closer could not be determined. - * The format of the array return value is: - * ```php - * array( - * 'opener' => integer, // Stack pointer to the array open bracket. - * 'closer' => integer, // Stack pointer to the array close bracket. - * ) - * ``` + * @return array|false An array with the token pointers; or `FALSE` if this is not a + * (short) array token or if the opener/closer could not be determined. + * The format of the array return value is: + * ```php + * array( + * 'opener' => integer, // Stack pointer to the array open bracket. + * 'closer' => integer, // Stack pointer to the array close bracket. + * ) + * ``` */ public static function getOpenClose(File $phpcsFile, $stackPtr, $isShortArray = null) { diff --git a/PHPCSUtils/Utils/Conditions.php b/PHPCSUtils/Utils/Conditions.php index aba769e3..76f0e885 100644 --- a/PHPCSUtils/Utils/Conditions.php +++ b/PHPCSUtils/Utils/Conditions.php @@ -39,12 +39,12 @@ final class Conditions * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $types Optional. The type(s) of tokens to search for. - * @param bool $first Optional. Whether to search for the first (outermost) - * (`true`) or the last (innermost) condition (`false`) of - * the specified type(s). + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $types Optional. The type(s) of tokens to search for. + * @param bool $first Optional. Whether to search for the first (outermost) + * (`true`) or the last (innermost) condition (`false`) of + * the specified type(s). * * @return int|false Integer stack pointer to the condition; or `FALSE` if the token * does not have the condition or has no conditions at all. @@ -103,9 +103,9 @@ public static function getCondition(File $phpcsFile, $stackPtr, $types = [], $fi * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $types The type(s) of tokens to search for. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $types The type(s) of tokens to search for. * * @return bool */ @@ -122,9 +122,9 @@ public static function hasCondition(File $phpcsFile, $stackPtr, $types) * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $types Optional. The type(s) of tokens to search for. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $types Optional. The type(s) of tokens to search for. * * @return int|false Integer stack pointer to the condition; or `FALSE` if the token * does not have the condition or has no conditions at all. @@ -142,9 +142,9 @@ public static function getFirstCondition(File $phpcsFile, $stackPtr, $types = [] * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $types Optional. The type(s) of tokens to search for. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $types Optional. The type(s) of tokens to search for. * * @return int|false Integer stack pointer to the condition; or `FALSE` if the token * does not have the condition or has no conditions at all. diff --git a/PHPCSUtils/Utils/ControlStructures.php b/PHPCSUtils/Utils/ControlStructures.php index 44bc053d..b343c736 100644 --- a/PHPCSUtils/Utils/ControlStructures.php +++ b/PHPCSUtils/Utils/ControlStructures.php @@ -199,7 +199,8 @@ public static function isElseIf(File $phpcsFile, $stackPtr) * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the token we are checking. * - * @return array Array with information about the caught Exception(s). + * @return array> + * Array with information about the caught Exception(s). * The returned array will contain the following information for * each caught exception: * ```php diff --git a/PHPCSUtils/Utils/FunctionDeclarations.php b/PHPCSUtils/Utils/FunctionDeclarations.php index 153bce45..26872ea2 100644 --- a/PHPCSUtils/Utils/FunctionDeclarations.php +++ b/PHPCSUtils/Utils/FunctionDeclarations.php @@ -43,7 +43,7 @@ final class FunctionDeclarations * * @since 1.0.0 * - * @var array => + * @var array */ public static $magicFunctions = [ '__autoload' => 'autoload', @@ -59,7 +59,7 @@ final class FunctionDeclarations * * @since 1.0.0 * - * @var array => + * @var array */ public static $magicMethods = [ '__construct' => 'construct', @@ -94,7 +94,7 @@ final class FunctionDeclarations * * @since 1.0.0 * - * @var array => + * @var array */ public static $methodsDoubleUnderscore = [ '__dorequest' => 'SOAPClient', @@ -160,7 +160,7 @@ public static function getName(File $phpcsFile, $stackPtr) * @param int $stackPtr The position in the stack of the function token to * acquire the properties for. * - * @return array Array with information about a function declaration. + * @return array Array with information about a function declaration. * The format of the return value is: * ```php * array( @@ -379,7 +379,7 @@ public static function getProperties(File $phpcsFile, $stackPtr) * @param int $stackPtr The position in the stack of the function token * to acquire the parameters for. * - * @return array + * @return array> * * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified $stackPtr is not of * type `T_FUNCTION`, `T_CLOSURE` or `T_USE`, diff --git a/PHPCSUtils/Utils/Lists.php b/PHPCSUtils/Utils/Lists.php index baf2c02a..167d6508 100644 --- a/PHPCSUtils/Utils/Lists.php +++ b/PHPCSUtils/Utils/Lists.php @@ -33,7 +33,7 @@ final class Lists * * @since 1.0.0 * - * @var array + * @var array */ private static $listItemDefaults = [ 'raw' => '', @@ -87,15 +87,15 @@ public static function isShortList(File $phpcsFile, $stackPtr) * tokens in a list. * Use with care. * - * @return array|false An array with the token pointers; or `FALSE` if this is not a (short) list - * token or if the opener/closer could not be determined. - * The format of the array return value is: - * ```php - * array( - * 'opener' => integer, // Stack pointer to the list open bracket. - * 'closer' => integer, // Stack pointer to the list close bracket. - * ) - * ``` + * @return array|false An array with the token pointers; or `FALSE` if this is not a (short) list + * token or if the opener/closer could not be determined. + * The format of the array return value is: + * ```php + * array( + * 'opener' => integer, // Stack pointer to the list open bracket. + * 'closer' => integer, // Stack pointer to the list close bracket. + * ) + * ``` */ public static function getOpenClose(File $phpcsFile, $stackPtr, $isShortList = null) { @@ -190,7 +190,8 @@ public static function getOpenClose(File $phpcsFile, $stackPtr, $isShortList = n * @param int $stackPtr The position in the stack of the function token * to acquire the parameters for. * - * @return array An array with information on each assignment made, including skipped assignments (empty), + * @return array> + * An array with information on each assignment made, including skipped assignments (empty), * or an empty array if no assignments are made at all (fatal error in PHP >= 7.0). * * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified $stackPtr is not of diff --git a/PHPCSUtils/Utils/MessageHelper.php b/PHPCSUtils/Utils/MessageHelper.php index 388f2a09..eb7c1505 100644 --- a/PHPCSUtils/Utils/MessageHelper.php +++ b/PHPCSUtils/Utils/MessageHelper.php @@ -34,7 +34,7 @@ final class MessageHelper * Defaults to true (error). * @param string $code The error code for the message. * Defaults to 'Found'. - * @param array $data Optional input for the data replacements. + * @param scalar[] $data Optional input for the data replacements. * @param int $severity Optional. Severity level. Defaults to 0 which will * translate to the PHPCS default severity level. * @@ -70,7 +70,7 @@ public static function addMessage( * Defaults to true (error). * @param string $code The error code for the message. * Defaults to 'Found'. - * @param array $data Optional input for the data replacements. + * @param scalar[] $data Optional input for the data replacements. * @param int $severity Optional. Severity level. Defaults to 0 which will * translate to the PHPCS default severity level. * diff --git a/PHPCSUtils/Utils/Numbers.php b/PHPCSUtils/Utils/Numbers.php index 053643d7..69ec4ef0 100644 --- a/PHPCSUtils/Utils/Numbers.php +++ b/PHPCSUtils/Utils/Numbers.php @@ -106,7 +106,7 @@ final class Numbers * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of a T_LNUMBER or T_DNUMBER token. * - * @return array An array with information about the number. + * @return array An array with information about the number. * The format of the array return value is: * ```php * array( diff --git a/PHPCSUtils/Utils/ObjectDeclarations.php b/PHPCSUtils/Utils/ObjectDeclarations.php index e284224c..cb45bd4f 100644 --- a/PHPCSUtils/Utils/ObjectDeclarations.php +++ b/PHPCSUtils/Utils/ObjectDeclarations.php @@ -147,7 +147,7 @@ public static function getName(File $phpcsFile, $stackPtr) * @param int $stackPtr The position in the stack of the `T_CLASS` * token to acquire the properties for. * - * @return array Array with implementation properties of a class. + * @return array Array with implementation properties of a class. * The format of the return value is: * ```php * array( @@ -272,8 +272,8 @@ public static function findExtendedClassName(File $phpcsFile, $stackPtr) * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The stack position of the class or enum token. * - * @return array|false Array with names of the implemented interfaces or `FALSE` on - * error or if there are no implemented interface names. + * @return string[]|false Array with names of the implemented interfaces or `FALSE` on + * error or if there are no implemented interface names. */ public static function findImplementedInterfaceNames(File $phpcsFile, $stackPtr) { @@ -290,8 +290,8 @@ public static function findImplementedInterfaceNames(File $phpcsFile, $stackPtr) * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. * @param int $stackPtr The stack position of the interface keyword. * - * @return array|false Array with names of the extended interfaces or `FALSE` on - * error or if there are no extended interface names. + * @return string[]|false Array with names of the extended interfaces or `FALSE` on + * error or if there are no extended interface names. */ public static function findExtendedInterfaceNames(File $phpcsFile, $stackPtr) { @@ -309,16 +309,16 @@ public static function findExtendedInterfaceNames(File $phpcsFile, $stackPtr) * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The stack position of the - * class/interface declaration keyword. - * @param int $keyword The token constant for the keyword to examine. - * Either `T_EXTENDS` or `T_IMPLEMENTS`. - * @param array $allowedFor Array of OO types for which use of the keyword - * is allowed. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The stack position of the + * class/interface declaration keyword. + * @param int $keyword The token constant for the keyword to examine. + * Either `T_EXTENDS` or `T_IMPLEMENTS`. + * @param array $allowedFor Array of OO types for which use of the keyword + * is allowed. * - * @return array|false Returns an array of names or `FALSE` on error or when the object - * being declared does not extend/implement another object. + * @return string[]|false Returns an array of names or `FALSE` on error or when the object + * being declared does not extend/implement another object. */ private static function findNames(File $phpcsFile, $stackPtr, $keyword, array $allowedFor) { diff --git a/PHPCSUtils/Utils/Operators.php b/PHPCSUtils/Utils/Operators.php index ae155c13..562440fe 100644 --- a/PHPCSUtils/Utils/Operators.php +++ b/PHPCSUtils/Utils/Operators.php @@ -35,7 +35,7 @@ final class Operators * * @since 1.0.0 * - * @var array => + * @var array Note: value is irrelevant, only key is used. */ private static $extraUnaryIndicators = [ \T_STRING_CONCAT => true, diff --git a/PHPCSUtils/Utils/Parentheses.php b/PHPCSUtils/Utils/Parentheses.php index 2e7384e0..998b64f9 100644 --- a/PHPCSUtils/Utils/Parentheses.php +++ b/PHPCSUtils/Utils/Parentheses.php @@ -34,7 +34,7 @@ final class Parentheses * * @since 1.0.0 * - * @var array => + * @var array */ private static $extraParenthesesOwners = [ \T_ISSET => \T_ISSET, @@ -95,10 +95,10 @@ public static function getOwner(File $phpcsFile, $stackPtr) * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of `T_OPEN/CLOSE_PARENTHESIS` token. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of `T_OPEN/CLOSE_PARENTHESIS` token. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return bool `TRUE` if the owner is within the list of `$validOwners`; `FALSE` if not and * if the parenthesis does not have a (direct) owner. @@ -121,10 +121,10 @@ public static function isOwnerIn(File $phpcsFile, $stackPtr, $validOwners) * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return bool */ @@ -143,10 +143,10 @@ public static function hasOwner(File $phpcsFile, $stackPtr, $validOwners) * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return int|false Integer stack pointer to the parentheses opener; or `FALSE` if the token * does not have parentheses owned by any of the valid owners or if @@ -167,10 +167,10 @@ public static function getFirstOpener(File $phpcsFile, $stackPtr, $validOwners = * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return int|false Integer stack pointer to the parentheses closer; or `FALSE` if the token * does not have parentheses owned by any of the valid owners or if @@ -197,10 +197,10 @@ public static function getFirstCloser(File $phpcsFile, $stackPtr, $validOwners = * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return int|false Integer stack pointer to the parentheses owner; or `FALSE` if the token * does not have parentheses owned by any of the valid owners or if @@ -226,10 +226,10 @@ public static function getFirstOwner(File $phpcsFile, $stackPtr, $validOwners = * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return int|false Integer stack pointer to the parentheses opener; or `FALSE` if the token * does not have parentheses owned by any of the valid owners or if @@ -250,10 +250,10 @@ public static function getLastOpener(File $phpcsFile, $stackPtr, $validOwners = * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return int|false Integer stack pointer to the parentheses closer; or `FALSE` if the token * does not have parentheses owned by any of the valid owners or if @@ -280,10 +280,10 @@ public static function getLastCloser(File $phpcsFile, $stackPtr, $validOwners = * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return int|false Integer stack pointer to the parentheses owner; or `FALSE` if the token * does not have parentheses owned by any of the valid owners or if @@ -305,11 +305,11 @@ public static function getLastOwner(File $phpcsFile, $stackPtr, $validOwners = [ * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position in the stack of the - * token to verify. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position in the stack of the + * token to verify. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return int|false Integer stack pointer to the valid parentheses owner; or `FALSE` if * the token was not wrapped in parentheses or if the outermost set @@ -333,11 +333,11 @@ public static function firstOwnerIn(File $phpcsFile, $stackPtr, $validOwners) * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position in the stack of the - * token to verify. - * @param int|string|array $validOwners Array of token constants for the owners - * which should be considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position in the stack of the + * token to verify. + * @param int|string|array $validOwners Array of token constants for the owners + * which should be considered valid. * * @return int|false Integer stack pointer to the valid parentheses owner; or `FALSE` if * the token was not wrapped in parentheses or if the innermost set @@ -363,13 +363,13 @@ public static function lastOwnerIn(File $phpcsFile, $stackPtr, $validOwners) * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position of the token we are checking. - * @param int|string|array $validOwners Optional. Array of token constants for the owners - * which should be considered valid. - * @param bool $reverse Optional. Whether to search for the first/outermost - * (`false`) or the last/innermost (`true`) set of - * parentheses with the specified owner(s). + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position of the token we are checking. + * @param int|string|array $validOwners Optional. Array of token constants for the owners + * which should be considered valid. + * @param bool $reverse Optional. Whether to search for the first/outermost + * (`false`) or the last/innermost (`true`) set of + * parentheses with the specified owner(s). * * @return int|false Integer stack pointer to the parentheses opener; or `FALSE` if the token * does not have parentheses owned by any of the valid owners or if diff --git a/PHPCSUtils/Utils/PassedParameters.php b/PHPCSUtils/Utils/PassedParameters.php index f73ee8c4..35f1f391 100644 --- a/PHPCSUtils/Utils/PassedParameters.php +++ b/PHPCSUtils/Utils/PassedParameters.php @@ -33,7 +33,7 @@ final class PassedParameters * * @since 1.0.0 * - * @var array => + * @var array */ private static $callParsingStopPoints = [ \T_COMMA => \T_COMMA, @@ -170,7 +170,8 @@ public static function hasParameters(File $phpcsFile, $stackPtr, $isShortArray = * Efficiency tweak for when this has already been established, * Use with EXTREME care. * - * @return array A multi-dimentional array with information on each parameter/array item. + * @return array> + * A multi-dimentional array with information on each parameter/array item. * The information gathered about each parameter/array item is in the following format: * ```php * 1 => array( @@ -379,11 +380,11 @@ public static function getParameters(File $phpcsFile, $stackPtr, $limit = 0, $is * always pass both the offset as well as the parameter * name when examining function calls. * - * @return array|false Array with information on the parameter/array item at the specified offset, - * or with the specified name. - * Or `FALSE` if the specified parameter/array item is not found. - * See {@see PassedParameters::getParameters()} for the format of the returned - * (single-dimensional) array. + * @return array|false Array with information on the parameter/array item at the specified + * offset, or with the specified name. + * Or `FALSE` if the specified parameter/array item is not found. + * See {@see PassedParameters::getParameters()} for the format of the + * returned (single-dimensional) array. * * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the token passed is not one of the * accepted types or doesn't exist. @@ -452,20 +453,23 @@ public static function getParameterCount(File $phpcsFile, $stackPtr) * * @since 1.0.0 * - * @param array $parameters The output of a previous call to {@see PassedParameters::getParameters()}. - * @param int $paramOffset The 1-based index position of the parameter to retrieve. - * @param string|string[] $paramNames Either the name of the target parameter to retrieve - * as a string or an array of names for the same target parameter. - * An array of names is supported to allow for functions - * for which the parameter names have undergone name - * changes over time. - * The name will take precedence over the offset. + * @param array> $parameters The output of a previous call to + * {@see PassedParameters::getParameters()}. + * @param int $paramOffset The 1-based index position of the parameter + * to retrieve. + * @param string|string[] $paramNames Either the name of the target parameter to retrieve + * as a string or an array of names for the same target + * parameter. + * An array of names is supported to allow for functions + * for which the parameter names have undergone name + * changes over time. + * The name will take precedence over the offset. * - * @return array|false Array with information on the parameter at the specified offset, - * or with the specified name. - * Or `FALSE` if the specified parameter is not found. - * See {@see PassedParameters::getParameters()} for the format of the returned - * (single-dimensional) array. + * @return array|false Array with information on the parameter at the specified offset, + * or with the specified name. + * Or `FALSE` if the specified parameter is not found. + * See {@see PassedParameters::getParameters()} for the format of the + * returned (single-dimensional) array. * * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the `$paramNames` parameter is not passed * and the requested parameter was not passed diff --git a/PHPCSUtils/Utils/Scopes.php b/PHPCSUtils/Utils/Scopes.php index 32947c9e..99011fba 100644 --- a/PHPCSUtils/Utils/Scopes.php +++ b/PHPCSUtils/Utils/Scopes.php @@ -30,11 +30,11 @@ final class Scopes * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position in the stack of the - * token to verify. - * @param int|string|array $validScopes Array of token constants representing - * the scopes considered valid. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position in the stack of the + * token to verify. + * @param int|string|array $validScopes Array of token constants representing + * the scopes considered valid. * * @return int|false Integer stack pointer to the valid direct scope; or `FALSE` if * no valid direct scope was found. diff --git a/PHPCSUtils/Utils/UseStatements.php b/PHPCSUtils/Utils/UseStatements.php index 4e917322..3fdf9d66 100644 --- a/PHPCSUtils/Utils/UseStatements.php +++ b/PHPCSUtils/Utils/UseStatements.php @@ -156,7 +156,8 @@ public static function isTraitUse(File $phpcsFile, $stackPtr) * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. * @param int $stackPtr The position in the stack of the `T_USE` token. * - * @return array A multi-level array containing information about the use statement. + * @return array> + * A multi-level array containing information about the use statement. * The first level is `'name'`, `'function'` and `'const'`. These keys will always exist. * If any statements are found for any of these categories, the second level * will contain the alias/name as the key and the full original use name as the @@ -358,16 +359,18 @@ public static function splitImportUseStatement(File $phpcsFile, $stackPtr) * * @since 1.0.0 * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. - * @param int $stackPtr The position in the stack of the `T_USE` token. - * @param array $previousUseStatements The import `use` statements collected so far. - * This should be either the output of a - * previous call to this method or the output of - * an earlier call to the - * {@see UseStatements::splitImportUseStatement()} - * method. - * - * @return array A multi-level array containing information about the current `use` statement combined with + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. + * @param int $stackPtr The position in the stack of the + * `T_USE` token. + * @param array> $previousUseStatements The import `use` statements collected so far. + * This should be either the output of a + * previous call to this method or the output of + * an earlier call to the + * {@see UseStatements::splitImportUseStatement()} + * method. + * + * @return array> + * A multi-level array containing information about the current `use` statement combined with * the previously collected `use` statement information. * See {@see UseStatements::splitImportUseStatement()} for more details about the array format. */ @@ -393,19 +396,20 @@ public static function splitAndMergeImportUseStatement(File $phpcsFile, $stackPt * * @since 1.0.0 * - * @param array $previousUseStatements The import `use` statements collected so far. - * This should be either the output of a - * previous call to this method or the output of - * an earlier call to the - * {@see UseStatements::splitImportUseStatement()} - * method. - * @param array $currentUseStatement The parsed import `use` statements to merge with - * the previously collected use statements. - * This should be the output of a call to the - * {@see UseStatements::splitImportUseStatement()} - * method. - * - * @return array A multi-level array containing information about the current `use` statement combined with + * @param array> $previousUseStatements The import `use` statements collected so far. + * This should be either the output of a + * previous call to this method or the output of + * an earlier call to the + * {@see UseStatements::splitImportUseStatement()} + * method. + * @param array> $currentUseStatement The parsed import `use` statements to merge with + * the previously collected use statements. + * This should be the output of a call to the + * {@see UseStatements::splitImportUseStatement()} + * method. + * + * @return array> + * A multi-level array containing information about the current `use` statement combined with * the previously collected `use` statement information. * See {@see UseStatements::splitImportUseStatement()} for more details about the array format. */ diff --git a/PHPCSUtils/Utils/Variables.php b/PHPCSUtils/Utils/Variables.php index 4c92e1ed..4b5e70e9 100644 --- a/PHPCSUtils/Utils/Variables.php +++ b/PHPCSUtils/Utils/Variables.php @@ -41,7 +41,7 @@ final class Variables * * @since 1.0.0 * - * @var array => + * @var array */ public static $phpReservedVars = [ '_SERVER' => true, @@ -94,7 +94,7 @@ final class Variables * @param int $stackPtr The position in the stack of the `T_VARIABLE` token * to acquire the properties for. * - * @return array Array with information about the class member variable. + * @return array Array with information about the class member variable. * The format of the return value is: * ```php * array( diff --git a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php index a6b32bc4..2f34f7b5 100644 --- a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php +++ b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php @@ -31,7 +31,7 @@ final class AbstractArrayDeclarationSniffTest extends PolyfilledTestCase * Needed for PHPUnit cross-version support as PHPUnit 4.x does not have a * `setMethodsExcept()` method yet. * - * @var array + * @var string[] */ public $methodsToMock = [ 'processOpenClose', diff --git a/Tests/AbstractSniffs/AbstractArrayDeclaration/ArrayDeclarationSniffTestDouble.php b/Tests/AbstractSniffs/AbstractArrayDeclaration/ArrayDeclarationSniffTestDouble.php index b006753c..efa0b653 100644 --- a/Tests/AbstractSniffs/AbstractArrayDeclaration/ArrayDeclarationSniffTestDouble.php +++ b/Tests/AbstractSniffs/AbstractArrayDeclaration/ArrayDeclarationSniffTestDouble.php @@ -24,7 +24,7 @@ final class ArrayDeclarationSniffTestDouble extends AbstractArrayDeclarationSnif /** * The token stack for the current file being examined. * - * @var array + * @var array> */ public $tokens; diff --git a/Tests/BackCompat/BCFile/GetConditionTest.php b/Tests/BackCompat/BCFile/GetConditionTest.php index 077cddb6..1c6e0f46 100644 --- a/Tests/BackCompat/BCFile/GetConditionTest.php +++ b/Tests/BackCompat/BCFile/GetConditionTest.php @@ -44,7 +44,7 @@ class GetConditionTest extends UtilityMethodTestCase * - The startPoint token is left out as it is tested separately. * - The key is the type of token to look for after the test marker. * - * @var array => + * @var array */ protected static $testTargets = [ \T_VARIABLE => '/* testSeriouslyNestedMethod */', @@ -92,7 +92,7 @@ class GetConditionTest extends UtilityMethodTestCase * This array isn't auto-generated based on the array in Tokens as for these * tests we want to have access to the token constant names, not just their values. * - * @var array => + * @var array */ protected $conditionDefaults = [ 'T_CLASS' => false, @@ -124,21 +124,21 @@ class GetConditionTest extends UtilityMethodTestCase /** * Cache for the test token stack pointers. * - * @var array => + * @var array */ protected static $testTokens = []; /** * Cache for the marker token stack pointers. * - * @var array => + * @var array */ protected static $markerTokens = []; /** * OO scope tokens array. * - * @var => + * @var array */ protected $ooScopeTokens = []; diff --git a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php index e47ca18b..bcdc6dbd 100644 --- a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php +++ b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php @@ -52,7 +52,7 @@ class GetMemberPropertiesTest extends UtilityMethodTestCase * @dataProvider dataGetMemberProperties * * @param string $identifier Comment which precedes the test case. - * @param bool $expected Expected function output. + * @param array $expected Expected function output. * * @return void */ diff --git a/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php b/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php index 94255fad..ba949545 100644 --- a/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php +++ b/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php @@ -53,7 +53,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that represent equality comparisons. * - * @var array => + * @var array */ private $equalityTokens = [ \T_IS_EQUAL => \T_IS_EQUAL, @@ -120,7 +120,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that perform boolean operations. * - * @var array => + * @var array */ private $booleanOperators = [ \T_BOOLEAN_AND => \T_BOOLEAN_AND, @@ -133,7 +133,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that represent casting. * - * @var array => + * @var array */ private $castTokens = [ \T_INT_CAST => \T_INT_CAST, @@ -183,7 +183,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that represent scope modifiers. * - * @var array => + * @var array */ private $scopeModifiers = [ \T_PRIVATE => \T_PRIVATE, @@ -194,7 +194,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that can prefix a method name * - * @var array => + * @var array */ private $methodPrefixes = [ \T_PRIVATE => \T_PRIVATE, @@ -208,7 +208,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that open code blocks. * - * @var array => + * @var array */ private $blockOpeners = [ \T_OPEN_CURLY_BRACKET => \T_OPEN_CURLY_BRACKET, @@ -276,7 +276,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that represent strings. * - * @var array => + * @var array */ private $stringTokens = [ \T_CONSTANT_ENCAPSED_STRING => \T_CONSTANT_ENCAPSED_STRING, @@ -299,7 +299,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that represent brackets and parenthesis. * - * @var array => + * @var array */ private $bracketTokens = [ \T_OPEN_CURLY_BRACKET => \T_OPEN_CURLY_BRACKET, @@ -313,7 +313,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that include files. * - * @var array => + * @var array */ private $includeTokens = [ \T_REQUIRE_ONCE => \T_REQUIRE_ONCE, @@ -325,7 +325,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens that make up a heredoc string. * - * @var array => + * @var array */ private $heredocTokens = [ \T_START_HEREDOC => \T_START_HEREDOC, @@ -352,7 +352,7 @@ final class UnchangedTokenArraysTest extends TestCase /** * Tokens representing PHP magic constants. * - * @var array => + * @var array * * @link https://www.php.net/language.constants.predefined PHP Manual on magic constants */ diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.php index 4d735cc7..303a9d9f 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.php @@ -58,7 +58,7 @@ final class SpacesFixerAtEOFTest extends UtilityMethodTestCase /** * Set the name of a sniff to pass to PHPCS to limit the run (and force it to record errors). * - * @var array + * @var string[] */ protected static $selectedSniff = ['PHPCSUtils.SpacesFixer.Test']; diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php index c89ed2c1..a8e42c3a 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php @@ -48,7 +48,7 @@ final class SpacesFixerNewlineTest extends SpacesFixerTestCase /** * The names of the test case(s) in compliance. * - * @var array + * @var string[] */ protected static $compliantCases = [ 'newline-and-trailing-spaces', diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php index 573184b5..caca0072 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php @@ -48,7 +48,7 @@ final class SpacesFixerNoSpaceTest extends SpacesFixerTestCase /** * The names of the test case(s) in compliance. * - * @var array + * @var string[] */ protected static $compliantCases = ['no-space']; diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php index 22d9c287..a8cdeef8 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php @@ -48,7 +48,7 @@ final class SpacesFixerOneSpaceTest extends SpacesFixerTestCase /** * The names of the test case(s) in compliance. * - * @var array + * @var string[] */ protected static $compliantCases = [ 'one-space', diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php b/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php index 36863bc6..ae861daa 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php @@ -26,7 +26,7 @@ abstract class SpacesFixerTestCase extends UtilityMethodTestCase * * Important: this MUST be set in the concrete test class! * - * @var int|string + * @var int|string|null Note: `null` is not an acceptable value for the overloaded constant! */ const SPACES = null; @@ -69,7 +69,7 @@ abstract class SpacesFixerTestCase extends UtilityMethodTestCase * * Important: this MUST be set in the concrete test class! * - * @var array + * @var string[] */ protected static $compliantCases = []; @@ -85,7 +85,7 @@ abstract class SpacesFixerTestCase extends UtilityMethodTestCase /** * Set the name of a sniff to pass to PHPCS to limit the run (and force it to record errors). * - * @var array + * @var string[] */ protected static $selectedSniff = ['PHPCSUtils.SpacesFixer.Test']; @@ -301,7 +301,7 @@ public function testFixesMade() /** * Helper function holding the base data for the data providers. * - * @return array + * @return array> */ protected static function getAllData() { diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php index 8c2eabe8..55d443e8 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php @@ -50,7 +50,7 @@ final class SpacesFixerTwoSpaceTest extends SpacesFixerTestCase /** * The names of the test case(s) in compliance. * - * @var array + * @var string[] */ protected static $compliantCases = ['two-spaces']; diff --git a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php index 954393b6..557fe808 100644 --- a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php +++ b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php @@ -65,7 +65,7 @@ final class TrailingCommentHandlingNewlineTest extends UtilityMethodTestCase /** * Set the name of a sniff to pass to PHPCS to limit the run (and force it to record errors). * - * @var array + * @var string[] */ protected static $selectedSniff = ['PHPCSUtils.SpacesFixer.Test']; diff --git a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php index 037a689c..5c480866 100644 --- a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php +++ b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php @@ -65,7 +65,7 @@ final class TrailingCommentHandlingTest extends UtilityMethodTestCase /** * Set the name of a sniff to pass to PHPCS to limit the run (and force it to record errors). * - * @var array + * @var string[] */ protected static $selectedSniff = ['PHPCSUtils.SpacesFixer.Test']; diff --git a/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php b/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php index a0785fc2..52ae8546 100644 --- a/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php +++ b/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php @@ -30,7 +30,7 @@ final class GetDoubleArrowPtrTest extends UtilityMethodTestCase /** * Cache for the parsed parameters array. * - * @var array => + * @var array> */ private static $parameters = []; @@ -106,8 +106,8 @@ public function testInvalidStartEndPositionException() * * @dataProvider dataGetDoubleArrowPtr * - * @param string $testMarker The comment which is part of the target array item in the test file. - * @param array $expected The expected function call result. + * @param string $testMarker The comment which is part of the target array item in the test file. + * @param int|bool $expected The expected function call result. * * @return void */ diff --git a/Tests/Utils/FunctionDeclarations/GetParametersDiffTest.php b/Tests/Utils/FunctionDeclarations/GetParametersDiffTest.php index 51303ffc..742e8076 100644 --- a/Tests/Utils/FunctionDeclarations/GetParametersDiffTest.php +++ b/Tests/Utils/FunctionDeclarations/GetParametersDiffTest.php @@ -124,10 +124,11 @@ protected function getMethodParametersTestHelper($marker, $expected, $targetType /** * Test helper to translate token offsets to absolute positions in an "expected" array. * - * @param string $targetPtr The token pointer to the target token from which the offset is calculated. - * @param array $expected The expected function output containing offsets. + * @param int $targetPtr The token pointer to the target token from which + * the offset is calculated. + * @param array> $expected The expected function output containing offsets. * - * @return array + * @return array> */ private function updateExpectedTokenPositions($targetPtr, $expected) { diff --git a/Tests/Utils/MessageHelper/AddMessageTest.php b/Tests/Utils/MessageHelper/AddMessageTest.php index 6313a584..5dd7a969 100644 --- a/Tests/Utils/MessageHelper/AddMessageTest.php +++ b/Tests/Utils/MessageHelper/AddMessageTest.php @@ -41,7 +41,7 @@ final class AddMessageTest extends UtilityMethodTestCase /** * Set the name of a sniff to pass to PHPCS to limit the run (and force it to record errors). * - * @var array + * @var string[] */ protected static $selectedSniff = ['PHPCSUtils.MessageHelper.AddMessageTest']; diff --git a/Tests/Utils/Numbers/NumberTypesTest.php b/Tests/Utils/Numbers/NumberTypesTest.php index 60cffb6b..960dbbe1 100644 --- a/Tests/Utils/Numbers/NumberTypesTest.php +++ b/Tests/Utils/Numbers/NumberTypesTest.php @@ -36,7 +36,7 @@ final class NumberTypesTest extends TestCase * @covers ::isDecimalInt * * @param string $input The input string. - * @param string $expected The expected output for the various functions. + * @param array $expected The expected output for the various functions. * * @return void */ @@ -52,7 +52,7 @@ public function testIsDecimalInt($input, $expected) * @covers ::isHexidecimalInt * * @param string $input The input string. - * @param string $expected The expected output for the various functions. + * @param array $expected The expected output for the various functions. * * @return void */ @@ -68,7 +68,7 @@ public function testIsHexidecimalInt($input, $expected) * @covers ::isBinaryInt * * @param string $input The input string. - * @param string $expected The expected output for the various functions. + * @param array $expected The expected output for the various functions. * * @return void */ @@ -84,7 +84,7 @@ public function testIsBinaryInt($input, $expected) * @covers ::isOctalInt * * @param string $input The input string. - * @param string $expected The expected output for the various functions. + * @param array $expected The expected output for the various functions. * * @return void */ @@ -100,7 +100,7 @@ public function testIsOctalInt($input, $expected) * @covers ::isFloat * * @param string $input The input string. - * @param string $expected The expected output for the various functions. + * @param array $expected The expected output for the various functions. * * @return void */ diff --git a/Tests/Utils/Parentheses/ParenthesesTest.php b/Tests/Utils/Parentheses/ParenthesesTest.php index 4f2dd4d0..5028607c 100644 --- a/Tests/Utils/Parentheses/ParenthesesTest.php +++ b/Tests/Utils/Parentheses/ParenthesesTest.php @@ -29,7 +29,7 @@ final class ParenthesesTest extends UtilityMethodTestCase /** * List of all the test markers with their target token info in the test case file. * - * @var array + * @var array> */ public static $testTargets = [ 'testIfWithArray-$a' => [ @@ -194,7 +194,7 @@ final class ParenthesesTest extends UtilityMethodTestCase /** * Cache for the test token stack pointers. * - * @var array => + * @var array */ private static $testTokens = []; @@ -210,7 +210,7 @@ final class ParenthesesTest extends UtilityMethodTestCase * This array isn't auto-generated based on the array in Tokens as for these * tests we want to have access to the token constant names, not just their values. * - * @var array => + * @var array */ private $ownerDefaults = [ 'T_ARRAY' => false, diff --git a/Tests/Utils/PassedParameters/GetParameterFromStackTest.php b/Tests/Utils/PassedParameters/GetParameterFromStackTest.php index ab79308f..878772fa 100644 --- a/Tests/Utils/PassedParameters/GetParameterFromStackTest.php +++ b/Tests/Utils/PassedParameters/GetParameterFromStackTest.php @@ -415,7 +415,7 @@ public static function dataGetParameterFromStack() * * @dataProvider dataGetParameterFromStackNamedAfterVariadic * - * @param string $offset The positional offfset to pass. + * @param int $offset The positional offfset to pass. * @param array $names The parameter names to pass. * @param array|false $expected The expected result array for the parameter. * diff --git a/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php b/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php index 03a5ebe1..fe097363 100644 --- a/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php +++ b/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php @@ -92,7 +92,7 @@ public static function dataGetParametersWithIneffectiveLimit() * * @param string $testMarker The comment which prefaces the target token in the test file. * @param int|string $targetType The type of token to look for. - * @param array $limit The number of parameters to limit this call to. + * @param int $limit The number of parameters to limit this call to. * Should match the expected count. * @param array $expected Optional. The expected return value. Only tested when not empty. * diff --git a/Tests/Utils/TextStrings/GetCompleteTextStringTest.php b/Tests/Utils/TextStrings/GetCompleteTextStringTest.php index d658f1b9..8a575231 100644 --- a/Tests/Utils/TextStrings/GetCompleteTextStringTest.php +++ b/Tests/Utils/TextStrings/GetCompleteTextStringTest.php @@ -31,7 +31,7 @@ final class GetCompleteTextStringTest extends UtilityMethodTestCase /** * Token types to target for these tests. * - * @var array + * @var array */ private $targets = [ \T_START_HEREDOC, diff --git a/Tests/Utils/TextStrings/InterpolatedVariablesTest.php b/Tests/Utils/TextStrings/InterpolatedVariablesTest.php index 240be1f4..abc3d131 100644 --- a/Tests/Utils/TextStrings/InterpolatedVariablesTest.php +++ b/Tests/Utils/TextStrings/InterpolatedVariablesTest.php @@ -31,7 +31,7 @@ final class InterpolatedVariablesTest extends TestCase /** * Collection of various variables and other embeds which are valid in double quoted strings. * - * @var array + * @var string[] */ private static $embeds = [ // Simple. diff --git a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php index f1e072ca..8786f5cd 100644 --- a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php +++ b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php @@ -79,7 +79,7 @@ public static function dataNotClassPropertyException() * @dataProvider dataGetMemberProperties * * @param string $identifier Comment which precedes the test case. - * @param bool $expected Expected function output. + * @param array $expected Expected function output. * * @return void */ diff --git a/Tests/Xtra/Messages/HasNewLineSupportTest.php b/Tests/Xtra/Messages/HasNewLineSupportTest.php index e9e399fe..614c4c20 100644 --- a/Tests/Xtra/Messages/HasNewLineSupportTest.php +++ b/Tests/Xtra/Messages/HasNewLineSupportTest.php @@ -41,7 +41,7 @@ final class HasNewLineSupportTest extends PolyfilledTestCase /** * Set the name of a sniff to pass to PHPCS to limit the run (and force it to record errors). * - * @var array + * @var string[] */ protected static $selectedSniff = ['PHPCSUtils.Xtra.HasNewLineSupportTest']; diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 90596a78..8129b2a3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -48,6 +48,19 @@ + + + + + + + + + From 09bae7108cddd654814d76ca43b27c3ddb13523b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 13 Nov 2023 19:07:55 +0100 Subject: [PATCH 27/32] Composer: raise the minimum supported PHPCS version to 3.8.0 ... to prevent end-users from running into trouble with the name change. The files in the Composer `vendor/bin` will only be replaced when the `replace...` directive is found and that is only available in the 3.8.0 tag. When the files in the Composer `vendor/bin` are not replaced, they will continue to point to the `vendor/squizlabs/php_codesniffer` directory which will no longer exist, leading to fatal "File not found" errors for end-users trying to run PHPCS/PHPCBF. Includes updating references to the PHPCS version whenever relevant throughout the codebase. --- PHPCSUtils/BackCompat/BCFile.php | 20 ++++++++++---------- PHPCSUtils/BackCompat/BCTokens.php | 2 +- README.md | 6 +++--- Tests/BackCompat/Helper/GetVersionTest.php | 4 ++-- Tests/Tokens/TokenHelper/TokenExistsTest.php | 2 +- Tests/Utils/Arrays/GetDoubleArrowPtrTest.php | 3 ++- composer.json | 2 +- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/PHPCSUtils/BackCompat/BCFile.php b/PHPCSUtils/BackCompat/BCFile.php index 994eb516..0fc4fed3 100644 --- a/PHPCSUtils/BackCompat/BCFile.php +++ b/PHPCSUtils/BackCompat/BCFile.php @@ -498,7 +498,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr) * * Changelog for the PHPCS native function: * - Introduced in PHPCS 0.0.5. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source. * @see \PHPCSUtils\Utils\FunctionDeclarations::getProperties() PHPCSUtils native improved version. @@ -543,7 +543,7 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr) * * Changelog for the PHPCS native function: * - Introduced in PHPCS 0.0.5. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source. * @see \PHPCSUtils\Utils\Variables::getMemberProperties() PHPCSUtils native improved version. @@ -653,7 +653,7 @@ public static function getClassProperties(File $phpcsFile, $stackPtr) * * Changelog for the PHPCS native function: * - Introduced in PHPCS 0.0.5. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::isReference() Original source. * @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version. @@ -679,7 +679,7 @@ public static function isReference(File $phpcsFile, $stackPtr) * * Changelog for the PHPCS native function: * - Introduced in PHPCS 0.0.5. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::getTokensAsString() Original source. * @see \PHPCSUtils\Utils\GetTokensAsString Related set of functions. @@ -708,7 +708,7 @@ public static function getTokensAsString(File $phpcsFile, $start, $length, $orig * * Changelog for the PHPCS native function: * - Introduced in PHPCS 2.1.0. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::findStartOfStatement() Original source. * @@ -732,7 +732,7 @@ public static function findStartOfStatement(File $phpcsFile, $start, $ignore = n * * Changelog for the PHPCS native function: * - Introduced in PHPCS 2.1.0. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::findEndOfStatement() Original source. * @@ -756,7 +756,7 @@ public static function findEndOfStatement(File $phpcsFile, $start, $ignore = nul * * Changelog for the PHPCS native function: * - Introduced in PHPCS 0.0.5. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::hasCondition() Original source. * @see \PHPCSUtils\Utils\Conditions::hasCondition() PHPCSUtils native alternative. @@ -781,7 +781,7 @@ public static function hasCondition(File $phpcsFile, $stackPtr, $types) * * Changelog for the PHPCS native function: * - Introduced in PHPCS 1.3.0. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::getCondition() Original source. * @see \PHPCSUtils\Utils\Conditions::getCondition() More versatile alternative. @@ -812,7 +812,7 @@ public static function getCondition(File $phpcsFile, $stackPtr, $type, $first = * * Changelog for the PHPCS native function: * - Introduced in PHPCS 1.2.0. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::findExtendedClassName() Original source. * @see \PHPCSUtils\Utils\ObjectDeclarations::findExtendedClassName() PHPCSUtils native improved version. @@ -837,7 +837,7 @@ public static function findExtendedClassName(File $phpcsFile, $stackPtr) * * Changelog for the PHPCS native function: * - Introduced in PHPCS 2.7.0. - * - The upstream method has received no significant updates since PHPCS 3.7.1. + * - The upstream method has received no significant updates since PHPCS 3.8.0. * * @see \PHP_CodeSniffer\Files\File::findImplementedInterfaceNames() Original source. * @see \PHPCSUtils\Utils\ObjectDeclarations::findImplementedInterfaceNames() PHPCSUtils native improved version. diff --git a/PHPCSUtils/BackCompat/BCTokens.php b/PHPCSUtils/BackCompat/BCTokens.php index c7ac15fb..9424f70c 100644 --- a/PHPCSUtils/BackCompat/BCTokens.php +++ b/PHPCSUtils/BackCompat/BCTokens.php @@ -74,7 +74,7 @@ final class BCTokens /** * Handle calls to (undeclared) methods for token arrays which haven't received any - * changes since PHPCS 3.7.1. + * changes since PHPCS 3.8.0. * * @since 1.0.0 * diff --git a/README.md b/README.md index 23e83036..430855ea 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Whether you need to split an `array` into the individual items, are trying to de Includes improved versions of the PHPCS native utility functions and plenty of new utility functions. -These functions are compatible with PHPCS 3.7.1 up to PHPCS `master`. +These functions are compatible with PHPCS 3.8.0 up to PHPCS `master`. ### A collection of static properties and methods for often-used token groups @@ -66,7 +66,7 @@ Supports PHPUnit 4.x up to 9.x. Normally to use the latest version of PHP_CodeSniffer native utility functions, you would have to raise the minimum requirements of your external PHPCS standard. -Now you won't have to anymore. This package allows you to use the latest version of those utility functions in all PHP_CodeSniffer versions from PHPCS 3.7.1 and up. +Now you won't have to anymore. This package allows you to use the latest version of those utility functions in all PHP_CodeSniffer versions from PHPCS 3.8.0 and up. ### Fully documented @@ -78,7 +78,7 @@ To see detailed information about all the available abstract sniffs, utility fun ## Minimum Requirements * PHP 5.4 or higher. -* [PHP_CodeSniffer] 3.7.1+. +* [PHP_CodeSniffer] 3.8.0+. * Recommended PHP extensions for optimal functionality: - PCRE with Unicode support (normally enabled by default) diff --git a/Tests/BackCompat/Helper/GetVersionTest.php b/Tests/BackCompat/Helper/GetVersionTest.php index 1667387e..16b0d4a9 100644 --- a/Tests/BackCompat/Helper/GetVersionTest.php +++ b/Tests/BackCompat/Helper/GetVersionTest.php @@ -32,7 +32,7 @@ final class GetVersionTest extends TestCase * * @var string */ - const DEVMASTER = '3.7.2'; + const DEVMASTER = '3.8.0'; /** * Test the method. @@ -49,7 +49,7 @@ public function testGetVersion() } if ($expected === 'lowest') { - $expected = '3.7.1'; + $expected = '3.8.0'; } $result = Helper::getVersion(); diff --git a/Tests/Tokens/TokenHelper/TokenExistsTest.php b/Tests/Tokens/TokenHelper/TokenExistsTest.php index 711f8c4b..0dc01ee3 100644 --- a/Tests/Tokens/TokenHelper/TokenExistsTest.php +++ b/Tests/Tokens/TokenHelper/TokenExistsTest.php @@ -58,7 +58,7 @@ public function testTokenExists($name, $expected) * {@internal This dataprovider does not currently contain any tests for * PHP native tokens which may not exist (depending on the PHPCS version). * These tests are not relevant at this time with the current minimum - * PHPCS version of 3.7.1, but this may change again in the future.} + * PHPCS version, but this may change again in the future.} * * @return array */ diff --git a/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php b/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php index 52ae8546..1ef4f0f2 100644 --- a/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php +++ b/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php @@ -210,7 +210,8 @@ public static function dataGetDoubleArrowPtr() 'expected' => 8, ], // Test specifically for PHPCS 3.5.3 and 3.5.4 in which all "fn" tokens were tokenized as T_FN. - // While PHPCS < 3.7.1 is no longer supported, the test remains to safeguard against tokenizer regressions. + // While these PHPCS versions are no longer supported, the test remains to safeguard against + // tokenizer regressions. 'test-arrow-access-to-property-named-fn-as-key-phpcs-3.5.3-3.5.4' => [ 'testMarker' => '/* testKeyPropertyAccessFnPHPCS353-354 */', 'expected' => 12, diff --git a/composer.json b/composer.json index a820d0af..bd5c4ae0 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require" : { "php" : ">=5.4", - "squizlabs/php_codesniffer" : "^3.7.1 || 4.0.x-dev@dev", + "squizlabs/php_codesniffer" : "^3.8.0 || 4.0.x-dev@dev", "dealerdirect/phpcodesniffer-composer-installer" : "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0" }, "require-dev" : { From 2f73b9664a68d99d546adbad8d4f13930354c73a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 13 Nov 2023 22:21:11 +0100 Subject: [PATCH 28/32] Remove work-arounds which were in place for PHPCS < 3.8.0 --- PHPCSUtils/Tokens/Collections.php | 60 +++---------------- .../Collections/ArrayOpenTokensBCTest.php | 4 -- .../Tokens/Collections/ArrayTokensBCTest.php | 5 -- .../Collections/ListOpenTokensBCTest.php | 4 -- Tests/Tokens/Collections/ListTokensBCTest.php | 5 -- .../ParameterPassingTokensTest.php | 4 -- .../ShortArrayListOpenTokensBCTest.php | 4 -- .../Collections/ShortArrayTokensBCTest.php | 5 -- .../Collections/ShortListTokensBCTest.php | 5 -- 9 files changed, 7 insertions(+), 89 deletions(-) diff --git a/PHPCSUtils/Tokens/Collections.php b/PHPCSUtils/Tokens/Collections.php index a84846f0..c8465152 100644 --- a/PHPCSUtils/Tokens/Collections.php +++ b/PHPCSUtils/Tokens/Collections.php @@ -596,13 +596,7 @@ private static function triggerDeprecation($method, $version, $replacement) */ public static function arrayOpenTokensBC() { - $tokens = self::$arrayOpenTokensBC; - - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $tokens[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - } - - return $tokens; + return self::$arrayOpenTokensBC; } /** @@ -623,14 +617,7 @@ public static function arrayOpenTokensBC() */ public static function arrayTokensBC() { - $tokens = self::$arrayTokens; - - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $tokens[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - $tokens[\T_CLOSE_SQUARE_BRACKET] = \T_CLOSE_SQUARE_BRACKET; - } - - return $tokens; + return self::$arrayTokens; } /** @@ -673,13 +660,7 @@ public static function functionCallTokens() */ public static function listOpenTokensBC() { - $tokens = self::$listOpenTokensBC; - - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $tokens[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - } - - return $tokens; + return self::$listOpenTokensBC; } /** @@ -698,14 +679,7 @@ public static function listOpenTokensBC() */ public static function listTokensBC() { - $tokens = self::$listTokens; - - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $tokens[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - $tokens[\T_CLOSE_SQUARE_BRACKET] = \T_CLOSE_SQUARE_BRACKET; - } - - return $tokens; + return self::$listTokens; } /** @@ -815,13 +789,7 @@ public static function returnTypeTokens() */ public static function shortArrayListOpenTokensBC() { - $tokens = self::$shortArrayListOpenTokensBC; - - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $tokens[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - } - - return $tokens; + return self::$shortArrayListOpenTokensBC; } /** @@ -840,14 +808,7 @@ public static function shortArrayListOpenTokensBC() */ public static function shortArrayTokensBC() { - $tokens = self::$shortArrayTokens; - - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $tokens[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - $tokens[\T_CLOSE_SQUARE_BRACKET] = \T_CLOSE_SQUARE_BRACKET; - } - - return $tokens; + return self::$shortArrayTokens; } /** @@ -866,13 +827,6 @@ public static function shortArrayTokensBC() */ public static function shortListTokensBC() { - $tokens = self::$shortListTokens; - - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $tokens[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - $tokens[\T_CLOSE_SQUARE_BRACKET] = \T_CLOSE_SQUARE_BRACKET; - } - - return $tokens; + return self::$shortListTokens; } } diff --git a/Tests/Tokens/Collections/ArrayOpenTokensBCTest.php b/Tests/Tokens/Collections/ArrayOpenTokensBCTest.php index 12568b4e..2f581b75 100644 --- a/Tests/Tokens/Collections/ArrayOpenTokensBCTest.php +++ b/Tests/Tokens/Collections/ArrayOpenTokensBCTest.php @@ -38,10 +38,6 @@ public function testArrayOpenTokensBC() \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, ]; - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $expected[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - } - $this->assertSame($expected, Collections::arrayOpenTokensBC()); } } diff --git a/Tests/Tokens/Collections/ArrayTokensBCTest.php b/Tests/Tokens/Collections/ArrayTokensBCTest.php index 009b825e..7a5be5ba 100644 --- a/Tests/Tokens/Collections/ArrayTokensBCTest.php +++ b/Tests/Tokens/Collections/ArrayTokensBCTest.php @@ -39,11 +39,6 @@ public function testArrayTokensBC() \T_CLOSE_SHORT_ARRAY => \T_CLOSE_SHORT_ARRAY, ]; - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $expected[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - $expected[\T_CLOSE_SQUARE_BRACKET] = \T_CLOSE_SQUARE_BRACKET; - } - $this->assertSame($expected, Collections::arrayTokensBC()); } } diff --git a/Tests/Tokens/Collections/ListOpenTokensBCTest.php b/Tests/Tokens/Collections/ListOpenTokensBCTest.php index 487d8942..ddbcc615 100644 --- a/Tests/Tokens/Collections/ListOpenTokensBCTest.php +++ b/Tests/Tokens/Collections/ListOpenTokensBCTest.php @@ -38,10 +38,6 @@ public function testListOpenTokensBC() \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, ]; - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $expected[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - } - $this->assertSame($expected, Collections::listOpenTokensBC()); } } diff --git a/Tests/Tokens/Collections/ListTokensBCTest.php b/Tests/Tokens/Collections/ListTokensBCTest.php index fd94860b..d7a2eff8 100644 --- a/Tests/Tokens/Collections/ListTokensBCTest.php +++ b/Tests/Tokens/Collections/ListTokensBCTest.php @@ -39,11 +39,6 @@ public function testListTokensBC() \T_CLOSE_SHORT_ARRAY => \T_CLOSE_SHORT_ARRAY, ]; - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $expected[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - $expected[\T_CLOSE_SQUARE_BRACKET] = \T_CLOSE_SQUARE_BRACKET; - } - $this->assertSame($expected, Collections::listTokensBC()); } } diff --git a/Tests/Tokens/Collections/ParameterPassingTokensTest.php b/Tests/Tokens/Collections/ParameterPassingTokensTest.php index 9638edd6..e457f90d 100644 --- a/Tests/Tokens/Collections/ParameterPassingTokensTest.php +++ b/Tests/Tokens/Collections/ParameterPassingTokensTest.php @@ -49,10 +49,6 @@ public function testParameterPassingTokens() \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, ]; - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $expected[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - } - $this->assertSame($expected, Collections::parameterPassingTokens()); } } diff --git a/Tests/Tokens/Collections/ShortArrayListOpenTokensBCTest.php b/Tests/Tokens/Collections/ShortArrayListOpenTokensBCTest.php index 81526b2e..d85bf8c1 100644 --- a/Tests/Tokens/Collections/ShortArrayListOpenTokensBCTest.php +++ b/Tests/Tokens/Collections/ShortArrayListOpenTokensBCTest.php @@ -37,10 +37,6 @@ public function testShortArrayListOpenTokensBC() \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, ]; - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $expected[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - } - $this->assertSame($expected, Collections::shortArrayListOpenTokensBC()); } } diff --git a/Tests/Tokens/Collections/ShortArrayTokensBCTest.php b/Tests/Tokens/Collections/ShortArrayTokensBCTest.php index 4c023e26..0d8d75bd 100644 --- a/Tests/Tokens/Collections/ShortArrayTokensBCTest.php +++ b/Tests/Tokens/Collections/ShortArrayTokensBCTest.php @@ -38,11 +38,6 @@ public function testShortArrayTokensBC() \T_CLOSE_SHORT_ARRAY => \T_CLOSE_SHORT_ARRAY, ]; - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $expected[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - $expected[\T_CLOSE_SQUARE_BRACKET] = \T_CLOSE_SQUARE_BRACKET; - } - $this->assertSame($expected, Collections::shortArrayTokensBC()); } } diff --git a/Tests/Tokens/Collections/ShortListTokensBCTest.php b/Tests/Tokens/Collections/ShortListTokensBCTest.php index e2775f0a..5b403d4a 100644 --- a/Tests/Tokens/Collections/ShortListTokensBCTest.php +++ b/Tests/Tokens/Collections/ShortListTokensBCTest.php @@ -38,11 +38,6 @@ public function testShortListTokensBC() \T_CLOSE_SHORT_ARRAY => \T_CLOSE_SHORT_ARRAY, ]; - if (\version_compare(Helper::getVersion(), '3.7.1', '<=')) { - $expected[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET; - $expected[\T_CLOSE_SQUARE_BRACKET] = \T_CLOSE_SQUARE_BRACKET; - } - $this->assertSame($expected, Collections::shortListTokensBC()); } } From 7c8f0f2da462e7046270b6df5f2b00add82a83d1 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 5 Oct 2022 02:14:22 +0200 Subject: [PATCH 29/32] PHP 8.2 | BCFile::getMemberProperties(): sync with upstream / add support for true pseudotype As pulled in upstream PR squizlabs/PHP_CodeSniffer 3662 / PHPCSStandards/PHP_CodeSniffer 49. Includes unit tests. Includes moving some tests to allow the tests to still work as expected. Support for the `true` type was previously already added to the `Variables::getMemberProperties()` method in PR 368. Refs: * squizlabs/PHP_CodeSniffer 3662 * PHPCSStandards/PHP_CodeSniffer 49 * PHPCSStandards/PHPCSUtils 368 --- PHPCSUtils/Utils/Variables.php | 7 - .../BCFile/GetMemberPropertiesTest.inc | 19 ++- .../BCFile/GetMemberPropertiesTest.php | 54 +++++++- .../Variables/GetMemberPropertiesDiffTest.inc | 15 -- .../Variables/GetMemberPropertiesDiffTest.php | 130 ------------------ .../Variables/GetMemberPropertiesTest.php | 41 ++++++ 6 files changed, 111 insertions(+), 155 deletions(-) diff --git a/PHPCSUtils/Utils/Variables.php b/PHPCSUtils/Utils/Variables.php index 4b5e70e9..a97135f4 100644 --- a/PHPCSUtils/Utils/Variables.php +++ b/PHPCSUtils/Utils/Variables.php @@ -82,7 +82,6 @@ final class Variables * other non-property variables passed to the method. * - Defensive coding against incorrect calls to this method. * - Support PHP 8.0 identifier name tokens in property types, cross-version PHP & PHPCS. - * - Support for the PHP 8.2 `true` type. * - The results of this function call are cached during a PHPCS run for faster response times. * * @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source. @@ -183,12 +182,6 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr) $nullableType = false; $propertyTypeTokens = Collections::propertyTypeTokens(); - /* - * BC PHPCS < 3.x.x: The union type separator is not (yet) retokenized correctly - * for union types containing the `true` type. - */ - $propertyTypeTokens[\T_BITWISE_OR] = \T_BITWISE_OR; - if ($i < $stackPtr) { // We've found a type. for ($i; $i < $stackPtr; $i++) { diff --git a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.inc b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.inc index 743db513..eca7b4ac 100644 --- a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.inc +++ b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.inc @@ -220,11 +220,11 @@ $anon = class() { public ?int|float $unionTypesNullable; /* testPHP8PseudoTypeNull */ - // Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. + // PHP 8.0 - 8.1: Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. public null $pseudoTypeNull; /* testPHP8PseudoTypeFalse */ - // Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. + // PHP 8.0 - 8.1: Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. public false $pseudoTypeFalse; /* testPHP8PseudoTypeFalseAndBool */ @@ -316,6 +316,21 @@ $anon = class() { public ?Foo&Bar $nullableIntersectionType; }; +$anon = class() { + /* testPHP82PseudoTypeTrue */ + public true $pseudoTypeTrue; + + /* testPHP82NullablePseudoTypeTrue */ + static protected ?true $pseudoTypeNullableTrue; + + /* testPHP82PseudoTypeTrueInUnion */ + private int|string|true $pseudoTypeTrueInUnion; + + /* testPHP82PseudoTypeFalseAndTrue */ + // Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method. + readonly true|FALSE $pseudoTypeFalseAndTrue; +}; + class WhitespaceAndCommentsInTypes { /* testUnionTypeWithWhitespaceAndComment */ public int | /*comment*/ string $hasWhitespaceAndComment; diff --git a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php index 67b2ff90..61964fc6 100644 --- a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php +++ b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php @@ -721,7 +721,7 @@ public static function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, // Missing static, but that's OK as not an allowed syntax. - 'type' => 'callable||void', + 'type' => 'callable|void', 'type_token' => -6, // Offset from the T_VARIABLE token. 'type_end_token' => -2, // Offset from the T_VARIABLE token. 'nullable_type' => false, @@ -1044,6 +1044,58 @@ public static function dataGetMemberProperties() 'nullable_type' => false, ], ], + 'php8.2-pseudo-type-true' => [ + '/* testPHP82PseudoTypeTrue */', + [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => false, + 'type' => 'true', + 'type_token' => -2, // Offset from the T_VARIABLE token. + 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'nullable_type' => false, + ], + ], + 'php8.2-pseudo-type-true-nullable' => [ + '/* testPHP82NullablePseudoTypeTrue */', + [ + 'scope' => 'protected', + 'scope_specified' => true, + 'is_static' => true, + 'is_readonly' => false, + 'type' => '?true', + 'type_token' => -2, // Offset from the T_VARIABLE token. + 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'nullable_type' => true, + ], + ], + 'php8.2-pseudo-type-true-in-union' => [ + '/* testPHP82PseudoTypeTrueInUnion */', + [ + 'scope' => 'private', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => false, + 'type' => 'int|string|true', + 'type_token' => -6, // Offset from the T_VARIABLE token. + 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'nullable_type' => false, + ], + ], + 'php8.2-pseudo-type-invalid-true-false-union' => [ + '/* testPHP82PseudoTypeFalseAndTrue */', + [ + 'scope' => 'public', + 'scope_specified' => false, + 'is_static' => false, + 'is_readonly' => true, + 'type' => 'true|FALSE', + 'type_token' => -4, // Offset from the T_VARIABLE token. + 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'nullable_type' => false, + ], + ], ]; } diff --git a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.inc b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.inc index affc1f2e..055ad9c6 100644 --- a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.inc +++ b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.inc @@ -11,18 +11,3 @@ enum Suit /* testEnumProperty */ protected $anonymous; } - -$anon = class() { - /* testPHP82PseudoTypeTrue */ - public true $pseudoTypeTrue; - - /* testPHP82NullablePseudoTypeTrue */ - static protected ?true $pseudoTypeNullableTrue; - - /* testPHP82PseudoTypeTrueInUnion */ - private int|string|true $pseudoTypeTrueInUnion; - - /* testPHP82PseudoTypeFalseAndTrue */ - // Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method. - readonly true|FALSE $pseudoTypeFalseAndTrue; -}; diff --git a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php index 8786f5cd..1fdd4d82 100644 --- a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php +++ b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tests\Utils\Variables; -use PHPCSUtils\Internal\Cache; use PHPCSUtils\TestUtils\UtilityMethodTestCase; use PHPCSUtils\Utils\Variables; @@ -72,133 +71,4 @@ public static function dataNotClassPropertyException() 'enum property' => ['/* testEnumProperty */'], ]; } - - /** - * Test the getMemberProperties() method. - * - * @dataProvider dataGetMemberProperties - * - * @param string $identifier Comment which precedes the test case. - * @param array $expected Expected function output. - * - * @return void - */ - public function testGetMemberProperties($identifier, $expected) - { - $variable = $this->getTargetToken($identifier, \T_VARIABLE); - $result = Variables::getMemberProperties(self::$phpcsFile, $variable); - - if (isset($expected['type_token']) && $expected['type_token'] !== false) { - $expected['type_token'] += $variable; - } - if (isset($expected['type_end_token']) && $expected['type_end_token'] !== false) { - $expected['type_end_token'] += $variable; - } - - $this->assertSame($expected, $result); - } - - /** - * Data provider. - * - * @see testGetMemberProperties() - * - * @return array - */ - public static function dataGetMemberProperties() - { - return [ - 'php8.2-pseudo-type-true' => [ - 'identifier' => '/* testPHP82PseudoTypeTrue */', - 'expected' => [ - 'scope' => 'public', - 'scope_specified' => true, - 'is_static' => false, - 'is_readonly' => false, - 'type' => 'true', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. - 'nullable_type' => false, - ], - ], - 'php8.2-pseudo-type-true-nullable' => [ - 'identifier' => '/* testPHP82NullablePseudoTypeTrue */', - 'expected' => [ - 'scope' => 'protected', - 'scope_specified' => true, - 'is_static' => true, - 'is_readonly' => false, - 'type' => '?true', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. - 'nullable_type' => true, - ], - ], - 'php8.2-pseudo-type-true-in-union' => [ - 'identifier' => '/* testPHP82PseudoTypeTrueInUnion */', - 'expected' => [ - 'scope' => 'private', - 'scope_specified' => true, - 'is_static' => false, - 'is_readonly' => false, - 'type' => 'int|string|true', - 'type_token' => -6, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. - 'nullable_type' => false, - ], - ], - 'php8.2-pseudo-type-invalid-true-false-union' => [ - 'identifier' => '/* testPHP82PseudoTypeFalseAndTrue */', - 'expected' => [ - 'scope' => 'public', - 'scope_specified' => false, - 'is_static' => false, - 'is_readonly' => true, - 'type' => 'true|FALSE', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. - 'nullable_type' => false, - ], - ], - ]; - } - - /** - * Verify that the build-in caching is used when caching is enabled. - * - * @return void - */ - public function testResultIsCached() - { - $methodName = 'PHPCSUtils\\Utils\\Variables::getMemberProperties'; - $cases = $this->dataGetMemberProperties(); - $identifier = $cases['php8.2-pseudo-type-true-in-union']['identifier']; - $expected = $cases['php8.2-pseudo-type-true-in-union']['expected']; - - $variable = $this->getTargetToken($identifier, \T_VARIABLE); - - if (isset($expected['type_token']) && $expected['type_token'] !== false) { - $expected['type_token'] += $variable; - } - if (isset($expected['type_end_token']) && $expected['type_end_token'] !== false) { - $expected['type_end_token'] += $variable; - } - - // Verify the caching works. - $origStatus = Cache::$enabled; - Cache::$enabled = true; - - $resultFirstRun = Variables::getMemberProperties(self::$phpcsFile, $variable); - $isCached = Cache::isCached(self::$phpcsFile, $methodName, $variable); - $resultSecondRun = Variables::getMemberProperties(self::$phpcsFile, $variable); - - if ($origStatus === false) { - Cache::clear(); - } - Cache::$enabled = $origStatus; - - $this->assertSame($expected, $resultFirstRun, 'First result did not match expectation'); - $this->assertTrue($isCached, 'Cache::isCached() could not find the cached value'); - $this->assertSame($resultFirstRun, $resultSecondRun, 'Second result did not match first'); - } } diff --git a/Tests/Utils/Variables/GetMemberPropertiesTest.php b/Tests/Utils/Variables/GetMemberPropertiesTest.php index 30e07e5b..ed3ccd80 100644 --- a/Tests/Utils/Variables/GetMemberPropertiesTest.php +++ b/Tests/Utils/Variables/GetMemberPropertiesTest.php @@ -10,7 +10,9 @@ namespace PHPCSUtils\Tests\Utils\Variables; +use PHPCSUtils\Internal\Cache; use PHPCSUtils\Tests\BackCompat\BCFile\GetMemberPropertiesTest as BCFile_GetMemberPropertiesTest; +use PHPCSUtils\Utils\Variables; /** * Tests for the \PHPCSUtils\Utils\Variables::getMemberProperties method. @@ -79,4 +81,43 @@ public static function dataGetMemberProperties() return $data; } + + /** + * Verify that the build-in caching is used when caching is enabled. + * + * @return void + */ + public function testResultIsCached() + { + $methodName = 'PHPCSUtils\\Utils\\Variables::getMemberProperties'; + $cases = self::dataGetMemberProperties(); + $identifier = $cases['php8.2-pseudo-type-true-in-union'][0]; + $expected = $cases['php8.2-pseudo-type-true-in-union'][1]; + + $variable = $this->getTargetToken($identifier, \T_VARIABLE); + + if (isset($expected['type_token']) && $expected['type_token'] !== false) { + $expected['type_token'] += $variable; + } + if (isset($expected['type_end_token']) && $expected['type_end_token'] !== false) { + $expected['type_end_token'] += $variable; + } + + // Verify the caching works. + $origStatus = Cache::$enabled; + Cache::$enabled = true; + + $resultFirstRun = Variables::getMemberProperties(self::$phpcsFile, $variable); + $isCached = Cache::isCached(self::$phpcsFile, $methodName, $variable); + $resultSecondRun = Variables::getMemberProperties(self::$phpcsFile, $variable); + + if ($origStatus === false) { + Cache::clear(); + } + Cache::$enabled = $origStatus; + + $this->assertSame($expected, $resultFirstRun, 'First result did not match expectation'); + $this->assertTrue($isCached, 'Cache::isCached() could not find the cached value'); + $this->assertSame($resultFirstRun, $resultSecondRun, 'Second result did not match first'); + } } From f6ec3828b078c186a79c4b001574fd227d9f2941 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 9 Oct 2022 01:26:14 +0200 Subject: [PATCH 30/32] PHP 8.2 | BCFile::getMethodProperties(): sync with upstream / add support for true pseudotype As pulled in upstream PR squizlabs/PHP_CodeSniffer 3662 / PHPCSStandards/PHP_CodeSniffer 49. Includes unit tests. Support for the `true` type was previously already added to the `FunctionDeclarations::getProperties()` method in PR 368. Refs: * squizlabs/PHP_CodeSniffer 3662 * PHPCSStandards/PHP_CodeSniffer 49 * PHPCSStandards/PHPCSUtils 368 --- PHPCSUtils/Utils/FunctionDeclarations.php | 7 --- .../BCFile/GetMethodPropertiesTest.inc | 11 ++++- .../BCFile/GetMethodPropertiesTest.php | 46 +++++++++++++++++++ .../GetPropertiesDiffTest.inc | 7 --- .../GetPropertiesDiffTest.php | 46 ------------------- 5 files changed, 55 insertions(+), 62 deletions(-) diff --git a/PHPCSUtils/Utils/FunctionDeclarations.php b/PHPCSUtils/Utils/FunctionDeclarations.php index 26872ea2..1ca398a0 100644 --- a/PHPCSUtils/Utils/FunctionDeclarations.php +++ b/PHPCSUtils/Utils/FunctionDeclarations.php @@ -148,7 +148,6 @@ public static function getName(File $phpcsFile, $stackPtr) * - Defensive coding against incorrect calls to this method. * - More efficient checking whether a function has a body. * - Support for PHP 8.0 identifier name tokens in return types, cross-version PHP & PHPCS. - * - Support for the PHP 8.2 `true` type. * - The results of this function call are cached during a PHPCS run for faster response times. * * @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source. @@ -248,12 +247,6 @@ public static function getProperties(File $phpcsFile, $stackPtr) $hasBody = false; $returnTypeTokens = Collections::returnTypeTokens(); - /* - * BC PHPCS < 3.x.x: The union type separator is not (yet) retokenized correctly - * for union types containing the `true` type. - */ - $returnTypeTokens[\T_BITWISE_OR] = \T_BITWISE_OR; - $parenthesisCloser = null; if (isset($tokens[$stackPtr]['parenthesis_closer']) === true) { $parenthesisCloser = $tokens[$stackPtr]['parenthesis_closer']; diff --git a/Tests/BackCompat/BCFile/GetMethodPropertiesTest.inc b/Tests/BackCompat/BCFile/GetMethodPropertiesTest.inc index 3d149e83..94ffdd1e 100644 --- a/Tests/BackCompat/BCFile/GetMethodPropertiesTest.inc +++ b/Tests/BackCompat/BCFile/GetMethodPropertiesTest.inc @@ -109,11 +109,11 @@ function unionTypesAllPseudoTypes($var) : false|MIXED|self|parent|static|iterabl $closure = function () use($a) :?int|float {}; /* testPHP8PseudoTypeNull */ -// Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. +// PHP 8.0 - 8.1: Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. function pseudoTypeNull(): null {} /* testPHP8PseudoTypeFalse */ -// Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. +// PHP 8.0 - 8.1: Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. function pseudoTypeFalse(): false {} /* testPHP8PseudoTypeFalseAndBool */ @@ -158,6 +158,13 @@ $closure = function (): string&int {}; // Intentional fatal error - nullability is not allowed with intersection types, but that's not the concern of the method. $closure = function (): ?Foo&Bar {}; +/* testPHP82PseudoTypeTrue */ +function pseudoTypeTrue(): ?true {} + +/* testPHP82PseudoTypeFalseAndTrue */ +// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method. +function pseudoTypeFalseAndTrue(): true|false {} + /* testNotAFunction */ return true; diff --git a/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php b/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php index 75ed7da7..365c49c6 100644 --- a/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php +++ b/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php @@ -1014,6 +1014,52 @@ public function testPHP81NullableIntersectionTypes() $this->getMethodPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected); } + /** + * Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability. + * + * @return void + */ + public function testPHP82PseudoTypeTrue() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => '?true', + 'return_type_token' => 8, // Offset from the T_FUNCTION token. + 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. + 'nullable_return_type' => true, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected); + } + + /** + * Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability. + * + * @return void + */ + public function testPHP82PseudoTypeFalseAndTrue() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => 'true|false', + 'return_type_token' => 7, // Offset from the T_FUNCTION token. + 'return_type_end_token' => 9, // Offset from the T_FUNCTION token. + 'nullable_return_type' => false, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected); + } + /** * Test for incorrect tokenization of array return type declarations in PHPCS < 2.8.0. * diff --git a/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.inc b/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.inc index e78b70e9..391ff60f 100644 --- a/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.inc +++ b/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.inc @@ -17,10 +17,3 @@ trait FooTrait { $func(); } } - -/* testPHP82PseudoTypeTrue */ -function pseudoTypeTrue(): ?true {} - -/* testPHP82PseudoTypeFalseAndTrue */ -// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method. -function pseudoTypeFalseAndTrue(): true|false {} diff --git a/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.php b/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.php index 03259499..f02460f8 100644 --- a/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.php +++ b/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.php @@ -88,52 +88,6 @@ public function testMessyPhpcsAnnotationsStaticClosure() $this->getPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected); } - /** - * Verify recognition of PHP 8.2 stand-alone `true` type. - * - * @return void - */ - public function testPHP82PseudoTypeTrue() - { - $expected = [ - 'scope' => 'public', - 'scope_specified' => false, - 'return_type' => '?true', - 'return_type_token' => 8, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. - 'nullable_return_type' => true, - 'is_abstract' => false, - 'is_final' => false, - 'is_static' => false, - 'has_body' => true, - ]; - - $this->getPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected); - } - - /** - * Verify recognition of PHP 8.2 type declaration with (illegal) type false combined with type true. - * - * @return void - */ - public function testPHP82PseudoTypeFalseAndTrue() - { - $expected = [ - 'scope' => 'public', - 'scope_specified' => false, - 'return_type' => 'true|false', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 9, // Offset from the T_FUNCTION token. - 'nullable_return_type' => false, - 'is_abstract' => false, - 'is_final' => false, - 'is_static' => false, - 'has_body' => true, - ]; - - $this->getPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected); - } - /** * Test helper. * From d1ddb2c95c1fa4e4bed0bd9692fb01dff10471db Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 9 Oct 2022 01:45:41 +0200 Subject: [PATCH 31/32] PHP 8.2 | BCFile::getMethodParameters(): sync with upstream / add support for true pseudotype As pulled in upstream PR squizlabs/PHP_CodeSniffer3662 / PHPCSStandards/PHP_CodeSniffer 49. Includes unit tests. Includes moving some tests to allow the tests to still work as expected. Support for the `true` type was previously already added to the `FunctionDeclarations::getParameters()` method in PR 368. Refs: * squizlabs/PHP_CodeSniffer 3662 * PHPCSStandards/PHP_CodeSniffer 49 * PHPCSStandards/PHPCSUtils 368 --- PHPCSUtils/BackCompat/BCFile.php | 1 + PHPCSUtils/Utils/FunctionDeclarations.php | 7 - .../BCFile/GetMethodParametersTest.inc | 11 +- .../BCFile/GetMethodParametersTest.php | 60 ++++++ .../GetParametersDiffTest.inc | 8 - .../GetParametersDiffTest.php | 184 +----------------- .../GetParametersTest.php | 95 +++++++-- 7 files changed, 161 insertions(+), 205 deletions(-) delete mode 100644 Tests/Utils/FunctionDeclarations/GetParametersDiffTest.inc diff --git a/PHPCSUtils/BackCompat/BCFile.php b/PHPCSUtils/BackCompat/BCFile.php index 0fc4fed3..af4ec95e 100644 --- a/PHPCSUtils/BackCompat/BCFile.php +++ b/PHPCSUtils/BackCompat/BCFile.php @@ -362,6 +362,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr) case T_TYPE_UNION: case T_TYPE_INTERSECTION: case T_FALSE: + case T_TRUE: case T_NULL: // Part of a type hint or default value. if ($defaultStart === null) { diff --git a/PHPCSUtils/Utils/FunctionDeclarations.php b/PHPCSUtils/Utils/FunctionDeclarations.php index 1ca398a0..e24bcf27 100644 --- a/PHPCSUtils/Utils/FunctionDeclarations.php +++ b/PHPCSUtils/Utils/FunctionDeclarations.php @@ -360,7 +360,6 @@ public static function getProperties(File $phpcsFile, $stackPtr) * - More efficient and more stable looping of the default value. * - Clearer exception message when a non-closure use token was passed to the function. * - Support for PHP 8.0 identifier name tokens in parameter types, cross-version PHP & PHPCS. - * - Support for the PHP 8.2 `true` type. * - The results of this function call are cached during a PHPCS run for faster response times. * * @see \PHP_CodeSniffer\Files\File::getMethodParameters() Original source. @@ -440,12 +439,6 @@ public static function getParameters(File $phpcsFile, $stackPtr) $parameterTypeTokens = Collections::parameterTypeTokens(); - /* - * BC PHPCS < 3.x.x: The union type separator is not (yet) retokenized correctly - * for union types containing the `true` type. - */ - $parameterTypeTokens[\T_BITWISE_OR] = \T_BITWISE_OR; - for ($i = $paramStart; $i <= $closer; $i++) { if (isset($parameterTypeTokens[$tokens[$i]['code']]) === true /* diff --git a/Tests/BackCompat/BCFile/GetMethodParametersTest.inc b/Tests/BackCompat/BCFile/GetMethodParametersTest.inc index 17ba4a98..17c8417e 100644 --- a/Tests/BackCompat/BCFile/GetMethodParametersTest.inc +++ b/Tests/BackCompat/BCFile/GetMethodParametersTest.inc @@ -159,11 +159,11 @@ function unionTypesAllPseudoTypes(false|mixed|self|parent|iterable|Resource $var $closure = function (?int|float $number) {}; /* testPHP8PseudoTypeNull */ -// Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. +// PHP 8.0 - 8.1: Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. function pseudoTypeNull(null $var = null) {} /* testPHP8PseudoTypeFalse */ -// Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. +// PHP 8.0 - 8.1: Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. function pseudoTypeFalse(false $var = false) {} /* testPHP8PseudoTypeFalseAndBool */ @@ -267,6 +267,13 @@ $closure = function (string&int $numeric_string) {}; // Intentional fatal error - nullability is not allowed with intersection types, but that's not the concern of the method. $closure = function (?Foo&Bar $object) {}; +/* testPHP82PseudoTypeTrue */ +function pseudoTypeTrue(?true $var = true) {} + +/* testPHP82PseudoTypeFalseAndTrue */ +// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method. +function pseudoTypeFalseAndTrue(true|false $var = true) {} + /* testPHP81NewInInitializers */ function newInInitializers( TypeA $new = new TypeA(self::CONST_VALUE), diff --git a/Tests/BackCompat/BCFile/GetMethodParametersTest.php b/Tests/BackCompat/BCFile/GetMethodParametersTest.php index d23ed800..1e94026e 100644 --- a/Tests/BackCompat/BCFile/GetMethodParametersTest.php +++ b/Tests/BackCompat/BCFile/GetMethodParametersTest.php @@ -2436,6 +2436,66 @@ public function testPHP81NullableIntersectionTypes() $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected); } + /** + * Verify recognition of PHP 8.2 stand-alone `true` type. + * + * @return void + */ + public function testPHP82PseudoTypeTrue() + { + $expected = []; + $expected[0] = [ + 'token' => 7, // Offset from the T_FUNCTION token. + 'name' => '$var', + 'content' => '?true $var = true', + 'default' => 'true', + 'default_token' => 11, // Offset from the T_FUNCTION token. + 'default_equal_token' => 9, // Offset from the T_FUNCTION token. + 'has_attributes' => false, + 'pass_by_reference' => false, + 'reference_token' => false, + 'variable_length' => false, + 'variadic_token' => false, + 'type_hint' => '?true', + 'type_hint_token' => 5, // Offset from the T_FUNCTION token. + 'type_hint_end_token' => 5, // Offset from the T_FUNCTION token. + 'nullable_type' => true, + 'comma_token' => false, + ]; + + $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected); + } + + /** + * Verify recognition of PHP 8.2 type declaration with (illegal) type false combined with type true. + * + * @return void + */ + public function testPHP82PseudoTypeFalseAndTrue() + { + $expected = []; + $expected[0] = [ + 'token' => 8, // Offset from the T_FUNCTION token. + 'name' => '$var', + 'content' => 'true|false $var = true', + 'default' => 'true', + 'default_token' => 12, // Offset from the T_FUNCTION token. + 'default_equal_token' => 10, // Offset from the T_FUNCTION token. + 'has_attributes' => false, + 'pass_by_reference' => false, + 'reference_token' => false, + 'variable_length' => false, + 'variadic_token' => false, + 'type_hint' => 'true|false', + 'type_hint_token' => 4, // Offset from the T_FUNCTION token. + 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'nullable_type' => false, + 'comma_token' => false, + ]; + + $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected); + } + /** * Verify behaviour when the default value uses the "new" keyword, as is allowed per PHP 8.1. * diff --git a/Tests/Utils/FunctionDeclarations/GetParametersDiffTest.inc b/Tests/Utils/FunctionDeclarations/GetParametersDiffTest.inc deleted file mode 100644 index d9f8c995..00000000 --- a/Tests/Utils/FunctionDeclarations/GetParametersDiffTest.inc +++ /dev/null @@ -1,8 +0,0 @@ -expectPhpcsException('$stackPtr must be of type T_FUNCTION, T_CLOSURE or T_USE or an arrow function'); - - FunctionDeclarations::getParameters(self::$phpcsFile, 10000); - } - - /** - * Verify recognition of PHP 8.2 stand-alone `true` type. - * - * @return void - */ - public function testPHP82PseudoTypeTrue() - { - $expected = []; - $expected[0] = [ - 'token' => 7, // Offset from the T_FUNCTION token. - 'name' => '$var', - 'content' => '?true $var = true', - 'default' => 'true', - 'default_token' => 11, // Offset from the T_FUNCTION token. - 'default_equal_token' => 9, // Offset from the T_FUNCTION token. - 'has_attributes' => false, - 'pass_by_reference' => false, - 'reference_token' => false, - 'variable_length' => false, - 'variadic_token' => false, - 'type_hint' => '?true', - 'type_hint_token' => 5, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 5, // Offset from the T_FUNCTION token. - 'nullable_type' => true, - 'comma_token' => false, - ]; - - $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected); - } - - /** - * Verify recognition of PHP 8.2 type declaration with (illegal) type false combined with type true. - * - * @return void - */ - public function testPHP82PseudoTypeFalseAndTrue() - { - $expected = []; - $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. - 'name' => '$var', - 'content' => 'true|false $var = true', - 'default' => 'true', - 'default_token' => 12, // Offset from the T_FUNCTION token. - 'default_equal_token' => 10, // Offset from the T_FUNCTION token. - 'has_attributes' => false, - 'pass_by_reference' => false, - 'reference_token' => false, - 'variable_length' => false, - 'variadic_token' => false, - 'type_hint' => 'true|false', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. - 'nullable_type' => false, - 'comma_token' => false, - ]; - - $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected); - } - - /** - * Test helper. + * Initialize PHPCS & tokenize the test case file. * - * @param string $marker The comment which preceeds the test. - * @param array $expected The expected function output. - * @param array $targetType Optional. The token type to search for after $marker. - * Defaults to the function/closure/arrow tokens. + * @beforeClass * * @return void */ - protected function getMethodParametersTestHelper($marker, $expected, $targetType = [\T_FUNCTION, \T_CLOSURE, \T_FN]) + public static function setUpTestFile() { - $target = $this->getTargetToken($marker, $targetType); - $found = FunctionDeclarations::getParameters(self::$phpcsFile, $target); - $expected = $this->updateExpectedTokenPositions($target, $expected); - - $this->assertSame($expected, $found); + self::$caseFile = \dirname(\dirname(__DIR__)) . '/DummyFile.inc'; + parent::setUpTestFile(); } /** - * Test helper to translate token offsets to absolute positions in an "expected" array. - * - * @param int $targetPtr The token pointer to the target token from which - * the offset is calculated. - * @param array> $expected The expected function output containing offsets. - * - * @return array> - */ - private function updateExpectedTokenPositions($targetPtr, $expected) - { - foreach ($expected as $key => $param) { - $expected[$key]['token'] += $targetPtr; - - if ($param['reference_token'] !== false) { - $expected[$key]['reference_token'] += $targetPtr; - } - if ($param['variadic_token'] !== false) { - $expected[$key]['variadic_token'] += $targetPtr; - } - if ($param['type_hint_token'] !== false) { - $expected[$key]['type_hint_token'] += $targetPtr; - } - if ($param['type_hint_end_token'] !== false) { - $expected[$key]['type_hint_end_token'] += $targetPtr; - } - if ($param['comma_token'] !== false) { - $expected[$key]['comma_token'] += $targetPtr; - } - if (isset($param['default_token'])) { - $expected[$key]['default_token'] += $targetPtr; - } - if (isset($param['default_equal_token'])) { - $expected[$key]['default_equal_token'] += $targetPtr; - } - if (isset($param['visibility_token']) && $param['visibility_token'] !== false) { - $expected[$key]['visibility_token'] += $targetPtr; - } - if (isset($param['readonly_token'])) { - $expected[$key]['readonly_token'] += $targetPtr; - } - } - - return $expected; - } - - /** - * Verify that the build-in caching is used when caching is enabled. + * Test passing a non-existent token pointer. * * @return void */ - public function testResultIsCached() + public function testNonExistentToken() { - // The test case used is specifically selected to be one which will always reach the cache check. - $methodName = 'PHPCSUtils\\Utils\\FunctionDeclarations::getParameters'; - $testMarker = '/* testPHP82PseudoTypeTrue */'; - $expected = [ - 0 => [ - 'token' => 7, // Offset from the T_FUNCTION token. - 'name' => '$var', - 'content' => '?true $var = true', - 'default' => 'true', - 'default_token' => 11, // Offset from the T_FUNCTION token. - 'default_equal_token' => 9, // Offset from the T_FUNCTION token. - 'has_attributes' => false, - 'pass_by_reference' => false, - 'reference_token' => false, - 'variable_length' => false, - 'variadic_token' => false, - 'type_hint' => '?true', - 'type_hint_token' => 5, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 5, // Offset from the T_FUNCTION token. - 'nullable_type' => true, - 'comma_token' => false, - ], - ]; - - $stackPtr = $this->getTargetToken($testMarker, Collections::functionDeclarationTokens()); - $expected = $this->updateExpectedTokenPositions($stackPtr, $expected); - - // Verify the caching works. - $origStatus = Cache::$enabled; - Cache::$enabled = true; - - $resultFirstRun = FunctionDeclarations::getParameters(self::$phpcsFile, $stackPtr); - $isCached = Cache::isCached(self::$phpcsFile, $methodName, $stackPtr); - $resultSecondRun = FunctionDeclarations::getParameters(self::$phpcsFile, $stackPtr); - - if ($origStatus === false) { - Cache::clear(); - } - Cache::$enabled = $origStatus; + $this->expectPhpcsException('$stackPtr must be of type T_FUNCTION, T_CLOSURE or T_USE or an arrow function'); - $this->assertSame($expected, $resultFirstRun, 'First result did not match expectation'); - $this->assertTrue($isCached, 'Cache::isCached() could not find the cached value'); - $this->assertSame($resultFirstRun, $resultSecondRun, 'Second result did not match first'); + FunctionDeclarations::getParameters(self::$phpcsFile, 10000); } } diff --git a/Tests/Utils/FunctionDeclarations/GetParametersTest.php b/Tests/Utils/FunctionDeclarations/GetParametersTest.php index 995501a0..d0ad91c7 100644 --- a/Tests/Utils/FunctionDeclarations/GetParametersTest.php +++ b/Tests/Utils/FunctionDeclarations/GetParametersTest.php @@ -10,7 +10,9 @@ namespace PHPCSUtils\Tests\Utils\FunctionDeclarations; +use PHPCSUtils\Internal\Cache; use PHPCSUtils\Tests\BackCompat\BCFile\GetMethodParametersTest as BCFile_GetMethodParametersTest; +use PHPCSUtils\Tokens\Collections; use PHPCSUtils\Utils\FunctionDeclarations; /** @@ -113,41 +115,108 @@ public function testNoParams($commentString, $targetTokenType = [\T_FUNCTION, \T */ protected function getMethodParametersTestHelper($marker, $expected, $targetType = [\T_FUNCTION, \T_CLOSURE, \T_FN]) { - $target = $this->getTargetToken($marker, $targetType); - $found = FunctionDeclarations::getParameters(self::$phpcsFile, $target); + $target = $this->getTargetToken($marker, $targetType); + $found = FunctionDeclarations::getParameters(self::$phpcsFile, $target); + $expected = $this->updateExpectedTokenPositions($target, $expected); + $this->assertSame($expected, $found); + } + + /** + * Test helper to translate token offsets to absolute positions in an "expected" array. + * + * @param int $targetPtr The token pointer to the target token from which + * the offset is calculated. + * @param array> $expected The expected function output containing offsets. + * + * @return array> + */ + private function updateExpectedTokenPositions($targetPtr, $expected) + { foreach ($expected as $key => $param) { - $expected[$key]['token'] += $target; + $expected[$key]['token'] += $targetPtr; if ($param['reference_token'] !== false) { - $expected[$key]['reference_token'] += $target; + $expected[$key]['reference_token'] += $targetPtr; } if ($param['variadic_token'] !== false) { - $expected[$key]['variadic_token'] += $target; + $expected[$key]['variadic_token'] += $targetPtr; } if ($param['type_hint_token'] !== false) { - $expected[$key]['type_hint_token'] += $target; + $expected[$key]['type_hint_token'] += $targetPtr; } if ($param['type_hint_end_token'] !== false) { - $expected[$key]['type_hint_end_token'] += $target; + $expected[$key]['type_hint_end_token'] += $targetPtr; } if ($param['comma_token'] !== false) { - $expected[$key]['comma_token'] += $target; + $expected[$key]['comma_token'] += $targetPtr; } if (isset($param['default_token'])) { - $expected[$key]['default_token'] += $target; + $expected[$key]['default_token'] += $targetPtr; } if (isset($param['default_equal_token'])) { - $expected[$key]['default_equal_token'] += $target; + $expected[$key]['default_equal_token'] += $targetPtr; } if (isset($param['visibility_token']) && $param['visibility_token'] !== false) { - $expected[$key]['visibility_token'] += $target; + $expected[$key]['visibility_token'] += $targetPtr; } if (isset($param['readonly_token'])) { - $expected[$key]['readonly_token'] += $target; + $expected[$key]['readonly_token'] += $targetPtr; } } - $this->assertSame($expected, $found); + return $expected; + } + + /** + * Verify that the build-in caching is used when caching is enabled. + * + * @return void + */ + public function testResultIsCached() + { + // The test case used is specifically selected to be one which will always reach the cache check. + $methodName = 'PHPCSUtils\\Utils\\FunctionDeclarations::getParameters'; + $testMarker = '/* testPHP82PseudoTypeTrue */'; + $expected = [ + 0 => [ + 'token' => 7, // Offset from the T_FUNCTION token. + 'name' => '$var', + 'content' => '?true $var = true', + 'default' => 'true', + 'default_token' => 11, // Offset from the T_FUNCTION token. + 'default_equal_token' => 9, // Offset from the T_FUNCTION token. + 'has_attributes' => false, + 'pass_by_reference' => false, + 'reference_token' => false, + 'variable_length' => false, + 'variadic_token' => false, + 'type_hint' => '?true', + 'type_hint_token' => 5, // Offset from the T_FUNCTION token. + 'type_hint_end_token' => 5, // Offset from the T_FUNCTION token. + 'nullable_type' => true, + 'comma_token' => false, + ], + ]; + + $stackPtr = $this->getTargetToken($testMarker, Collections::functionDeclarationTokens()); + $expected = $this->updateExpectedTokenPositions($stackPtr, $expected); + + // Verify the caching works. + $origStatus = Cache::$enabled; + Cache::$enabled = true; + + $resultFirstRun = FunctionDeclarations::getParameters(self::$phpcsFile, $stackPtr); + $isCached = Cache::isCached(self::$phpcsFile, $methodName, $stackPtr); + $resultSecondRun = FunctionDeclarations::getParameters(self::$phpcsFile, $stackPtr); + + if ($origStatus === false) { + Cache::clear(); + } + Cache::$enabled = $origStatus; + + $this->assertSame($expected, $resultFirstRun, 'First result did not match expectation'); + $this->assertTrue($isCached, 'Cache::isCached() could not find the cached value'); + $this->assertSame($resultFirstRun, $resultSecondRun, 'Second result did not match first'); } } From 871ad96d2d88aa46442b523305898dad680d70e6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 13 Nov 2023 22:36:35 +0100 Subject: [PATCH 32/32] Changelog for PHPCSUtils 1.0.9 --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4094d4ab..cc5bb53d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,34 @@ This projects adheres to [Keep a CHANGELOG](https://keepachangelog.com/) and use _Nothing yet._ +## [1.0.9] - 2023-12-08 + +### Added + +#### PHPCS BackCompat + +* `BCFile::getMemberProperties()`: sync with PHPCS 3.8.0 - support for PHP 8.2 `true` type. [#524] +* `BCFile::getMethodProperties()`: sync with PHPCS 3.8.0 - support for PHP 8.2 `true` type. [#524] +* `BCFile::getMethodParameters()`: sync with PHPCS 3.8.0 - support for PHP 8.2 `true` type. [#524] + +### Changed + +#### TestUtils + +* Significant performance improvement for the [`UtilityMethodTestCase`]. [#525] + +#### Other + +* Dropped support for [PHP_CodeSniffer] < 3.8.0. [#523] + Please ensure you run `composer update phpcsstandards/phpcsutils --with-dependencies` to benefit from this. +* Small improvements to the documentation website generation. Includes a contribution from [@fredden]. +* Various housekeeping and documentation improvements. Includes a contribution from [@fredden]. + +[#523]: https://github.com/PHPCSStandards/PHPCSUtils/pull/523 +[#524]: https://github.com/PHPCSStandards/PHPCSUtils/pull/524 +[#525]: https://github.com/PHPCSStandards/PHPCSUtils/pull/525 + + ## [1.0.8] - 2023-07-17 ### Changed @@ -928,6 +956,7 @@ This initial alpha release contains the following utility classes: [Unreleased]: https://github.com/PHPCSStandards/PHPCSUtils/compare/stable...HEAD +[1.0.9]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.8...1.0.9 [1.0.8]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.7...1.0.8 [1.0.7]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.6...1.0.7 [1.0.6]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.5...1.0.6 @@ -943,6 +972,7 @@ This initial alpha release contains the following utility classes: [1.0.0-alpha2]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.0-alpha1...1.0.0-alpha2 [Composer PHPCS plugin]: https://github.com/PHPCSStandards/composer-installer +[PHP_CodeSniffer]: https://github.com/PHPCSStandards/PHP_CodeSniffer [`AbstractArrayDeclarationSniff`]: https://phpcsutils.com/phpdoc/classes/PHPCSUtils-AbstractSniffs-AbstractArrayDeclarationSniff.html [`BCFile`]: https://phpcsutils.com/phpdoc/classes/PHPCSUtils-BackCompat-BCFile.html @@ -973,5 +1003,6 @@ This initial alpha release contains the following utility classes: [`UseStatements`]: https://phpcsutils.com/phpdoc/classes/PHPCSUtils-Utils-UseStatements.html [`Variables`]: https://phpcsutils.com/phpdoc/classes/PHPCSUtils-Utils-Variables.html +[@fredden]: https://github.com/fredden [@GaryJones]: https://github.com/GaryJones [@szepeviktor]: https://github.com/szepeviktor