diff --git a/.github/workflows/basics.yml b/.github/workflows/basics.yml index 912ca0cd..a3f48115 100644 --- a/.github/workflows/basics.yml +++ b/.github/workflows/basics.yml @@ -50,7 +50,7 @@ jobs: # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") @@ -102,7 +102,7 @@ jobs: # Dependencies need to be installed to make sure the PHPCS and PHPUnit classes are recognized. # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") @@ -132,7 +132,7 @@ jobs: # @link https://github.com/marketplace/actions/problem-matcher-for-markdownlint-cli - name: Enable showing issue in PRs - uses: xt0rted/markdownlint-problem-matcher@v2 + uses: xt0rted/markdownlint-problem-matcher@v3 - name: Check markdown with CLI2 run: markdownlint-cli2 diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 267effcf..687acbcd 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -67,7 +67,7 @@ jobs: # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 234990a5..ab9c4530 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,7 +50,7 @@ jobs: - name: Install Composer dependencies - normal if: ${{ matrix.php < 8.4 }} - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") @@ -58,7 +58,7 @@ jobs: # For the PHP "nightly", we need to install with ignore platform reqs as not all dependencies allow it yet. - name: Install Composer dependencies - with ignore platform if: ${{ matrix.php >= 8.4 }} - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: composer-options: --ignore-platform-req=php+ custom-cache-suffix: $(date -u "+%Y-%m") @@ -184,7 +184,7 @@ jobs: # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - normal if: ${{ matrix.php < 8.4 }} - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") @@ -192,7 +192,7 @@ jobs: # For PHP "nightly", we need to install with ignore platform reqs as not all dependencies allow it yet. - name: Install Composer dependencies - with ignore platform if: ${{ matrix.php >= 8.4 }} - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: composer-options: --ignore-platform-req=php+ custom-cache-suffix: $(date -u "+%Y-%m") @@ -309,7 +309,7 @@ jobs: run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") diff --git a/.github/workflows/update-docs.yml b/.github/workflows/update-docs.yml index 6d19cac3..65bc564e 100644 --- a/.github/workflows/update-docs.yml +++ b/.github/workflows/update-docs.yml @@ -112,7 +112,7 @@ jobs: # Retention is normally 90 days, but this artifact is only for reviewing # and debugging the generated files for the website. - name: Upload the generated files - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: generated-files path: ./docs/ @@ -120,7 +120,7 @@ jobs: retention-days: 5 - name: Setup GH Pages - uses: actions/configure-pages@v3 + uses: actions/configure-pages@v4 - name: Build the GH Pages site with Jekyll uses: actions/jekyll-build-pages@v1 @@ -129,7 +129,7 @@ jobs: destination: ./docs/_site - name: Upload GH Pages artifact - uses: actions/upload-pages-artifact@v2 + uses: actions/upload-pages-artifact@v3 with: path: ./docs/_site @@ -153,4 +153,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v2 + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/update-phpcs-versionnr.yml b/.github/workflows/update-phpcs-versionnr.yml index edb9b201..6ffeae45 100644 --- a/.github/workflows/update-phpcs-versionnr.yml +++ b/.github/workflows/update-phpcs-versionnr.yml @@ -68,7 +68,7 @@ jobs: run: git status -vv --untracked=all - name: Create pull request - uses: peter-evans/create-pull-request@v5 + uses: peter-evans/create-pull-request@v6 with: base: ${{ steps.branches.outputs.BASE }} branch: ${{ steps.branches.outputs.PR_BRANCH }} diff --git a/CHANGELOG.md b/CHANGELOG.md index cc5bb53d..12cfc3e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,34 @@ This projects adheres to [Keep a CHANGELOG](https://keepachangelog.com/) and use _Nothing yet._ +## [1.0.10] - 2024-03-18 + +### Changed + +#### Other + +* Dropped support for [PHP_CodeSniffer] < 3.9.0. [#561] + Please ensure you run `composer update phpcsstandards/phpcsutils --with-dependencies` to benefit from this. +* Various housekeeping and documentation improvements. + +### Deprecated + +#### Utils + +* `NamingConventions::AZ_UPPER` constant. [#563] +* `NamingConventions::AZ_LOWER` constant. [#563] + +### Fixed + +#### PHPCS BackCompat + +* `BackCompat\Helper::getEncoding()`: PHP 8.4 deprecation notice. [#568] +* `BackCompat\Helper::ignoreAnnotations()`: PHP 8.4 deprecation notice. [#568] + +[#561]: https://github.com/PHPCSStandards/PHPCSUtils/pull/561 +[#563]: https://github.com/PHPCSStandards/PHPCSUtils/pull/563 +[#568]: https://github.com/PHPCSStandards/PHPCSUtils/pull/568 + ## [1.0.9] - 2023-12-08 @@ -956,6 +984,7 @@ This initial alpha release contains the following utility classes: [Unreleased]: https://github.com/PHPCSStandards/PHPCSUtils/compare/stable...HEAD +[1.0.10]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.9...1.0.10 [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 diff --git a/PHPCSUtils/BackCompat/BCFile.php b/PHPCSUtils/BackCompat/BCFile.php index af4ec95e..14c6adf6 100644 --- a/PHPCSUtils/BackCompat/BCFile.php +++ b/PHPCSUtils/BackCompat/BCFile.php @@ -76,7 +76,7 @@ final class BCFile * * Changelog for the PHPCS native function: * - Introduced in PHPCS 0.0.5. - * - PHPCS 3.8.0: OO methods called `self`, `parent` or `static` are now correctly recognized. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::getDeclarationName() Original source. * @see \PHPCSUtils\Utils\ObjectDeclarations::getName() PHPCSUtils native improved version. @@ -98,44 +98,7 @@ final class BCFile */ public static function getDeclarationName(File $phpcsFile, $stackPtr) { - $tokens = $phpcsFile->getTokens(); - $tokenCode = $tokens[$stackPtr]['code']; - - if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) { - return null; - } - - if ($tokenCode !== T_FUNCTION - && $tokenCode !== T_CLASS - && $tokenCode !== T_INTERFACE - && $tokenCode !== T_TRAIT - && $tokenCode !== T_ENUM - ) { - throw new RuntimeException('Token type "' . $tokens[$stackPtr]['type'] . '" is not T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM'); - } - - if ($tokenCode === T_FUNCTION - && strtolower($tokens[$stackPtr]['content']) !== 'function' - ) { - // This is a function declared without the "function" keyword. - // So this token is the function name. - return $tokens[$stackPtr]['content']; - } - - $content = null; - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - if ($tokens[$i]['code'] === T_STRING - // BC: PHPCS < 3.8.0. - || $tokens[$i]['code'] === T_SELF - || $tokens[$i]['code'] === T_PARENT - || $tokens[$i]['code'] === T_STATIC - ) { - $content = $tokens[$i]['content']; - break; - } - } - - return $content; + return $phpcsFile->getDeclarationName($stackPtr); } /** @@ -161,7 +124,7 @@ public static function getDeclarationName(File $phpcsFile, $stackPtr) * // or FALSE if there is no type hint. * 'type_hint_end_token' => integer|false, // The stack pointer to the end of the type hint * // or FALSE if there is no type hint. - * 'nullable_type' => boolean, // TRUE if the var type is preceded by the nullability + * 'nullable_type' => boolean, // TRUE if the param type is preceded by the nullability * // operator. * 'comma_token' => integer|false, // The stack pointer to the comma after the param * // or FALSE if this is the last param. @@ -178,9 +141,9 @@ public static function getDeclarationName(File $phpcsFile, $stackPtr) * Parameters declared using PHP 8 constructor property promotion, have these additional array indexes: * ```php * 'property_visibility' => string, // The property visibility as declared. - * 'visibility_token' => integer,|false // The stack pointer to the visibility modifier token. + * 'visibility_token' => integer|false, // The stack pointer to the visibility modifier token. * // or FALSE if the visibility is not explicitly declared. - * 'property_readonly' => bool, // TRUE if the readonly keyword was found. + * 'property_readonly' => boolean, // TRUE if the readonly keyword was found. * 'readonly_token' => integer, // The stack pointer to the readonly modifier token. * // This index will only be set if the property is readonly. * ``` @@ -499,7 +462,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source. * @see \PHPCSUtils\Utils\FunctionDeclarations::getProperties() PHPCSUtils native improved version. @@ -544,7 +507,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source. * @see \PHPCSUtils\Utils\Variables::getMemberProperties() PHPCSUtils native improved version. @@ -582,13 +545,12 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr) * * Changelog for the PHPCS native function: * - Introduced in PHPCS 1.3.0. - * - PHPCS 3.8.0: Added support for PHP 8.2 `readonly` classes. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::getClassProperties() Original source. * @see \PHPCSUtils\Utils\ObjectDeclarations::getClassProperties() PHPCSUtils native improved version. * * @since 1.0.0 - * @since 1.0.6 Sync with PHPCS 3.8.0, support for readonly classes. PHPCS#3686. * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position in the stack of the `T_CLASS` @@ -601,50 +563,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr) */ public static function getClassProperties(File $phpcsFile, $stackPtr) { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['code'] !== T_CLASS) { - throw new RuntimeException('$stackPtr must be of type T_CLASS'); - } - - $valid = [ - T_FINAL => T_FINAL, - T_ABSTRACT => T_ABSTRACT, - T_READONLY => T_READONLY, - T_WHITESPACE => T_WHITESPACE, - T_COMMENT => T_COMMENT, - T_DOC_COMMENT => T_DOC_COMMENT, - ]; - - $isAbstract = false; - $isFinal = false; - $isReadonly = false; - - for ($i = ($stackPtr - 1); $i > 0; $i--) { - if (isset($valid[$tokens[$i]['code']]) === false) { - break; - } - - switch ($tokens[$i]['code']) { - case T_ABSTRACT: - $isAbstract = true; - break; - - case T_FINAL: - $isFinal = true; - break; - - case T_READONLY: - $isReadonly = true; - break; - } - } - - return [ - 'is_abstract' => $isAbstract, - 'is_final' => $isFinal, - 'is_readonly' => $isReadonly, - ]; + return $phpcsFile->getClassProperties($stackPtr); } /** @@ -654,7 +573,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::isReference() Original source. * @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version. @@ -680,7 +599,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::getTokensAsString() Original source. * @see \PHPCSUtils\Utils\GetTokensAsString Related set of functions. @@ -709,7 +628,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::findStartOfStatement() Original source. * @@ -733,7 +652,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::findEndOfStatement() Original source. * @@ -757,7 +676,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::hasCondition() Original source. * @see \PHPCSUtils\Utils\Conditions::hasCondition() PHPCSUtils native alternative. @@ -782,7 +701,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::getCondition() Original source. * @see \PHPCSUtils\Utils\Conditions::getCondition() More versatile alternative. @@ -813,7 +732,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::findExtendedClassName() Original source. * @see \PHPCSUtils\Utils\ObjectDeclarations::findExtendedClassName() PHPCSUtils native improved version. @@ -838,7 +757,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.8.0. + * - The upstream method has received no significant updates since PHPCS 3.9.0. * * @see \PHP_CodeSniffer\Files\File::findImplementedInterfaceNames() Original source. * @see \PHPCSUtils\Utils\ObjectDeclarations::findImplementedInterfaceNames() PHPCSUtils native improved version. @@ -848,8 +767,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 string[]|false Array with names of the implemented interfaces or `FALSE` on - * error or if there are no implemented interface names. + * @return array|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 9424f70c..dac8feb1 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.8.0. + * changes since PHPCS 3.9.0. * * @since 1.0.0 * diff --git a/PHPCSUtils/BackCompat/Helper.php b/PHPCSUtils/BackCompat/Helper.php index 7352a8cb..aa033e92 100644 --- a/PHPCSUtils/BackCompat/Helper.php +++ b/PHPCSUtils/BackCompat/Helper.php @@ -143,13 +143,14 @@ public static function getTabWidth(File $phpcsFile) * command-line or the ruleset. * * @since 1.0.0 + * @since 1.0.10 The `File` type declaration has been removed from the parameter declaration. * * @param \PHP_CodeSniffer\Files\File|null $phpcsFile Optional. The current file being processed. * * @return string Encoding. Defaults to the PHPCS native default, which is 'utf-8' * for PHPCS 3.x. */ - public static function getEncoding(File $phpcsFile = null) + public static function getEncoding($phpcsFile = null) { $default = 'utf-8'; @@ -176,14 +177,18 @@ public static function getEncoding(File $phpcsFile = null) * Check whether the "--ignore-annotations" option is in effect. * * @since 1.0.0 + * @since 1.0.10 The `File` type declaration has been removed from the parameter declaration. * * @param \PHP_CodeSniffer\Files\File|null $phpcsFile Optional. The current file being processed. * * @return bool `TRUE` if annotations should be ignored, `FALSE` otherwise. */ - public static function ignoreAnnotations(File $phpcsFile = null) + public static function ignoreAnnotations($phpcsFile = null) { - if (isset($phpcsFile, $phpcsFile->config->annotations)) { + if (isset($phpcsFile) + && $phpcsFile instanceof File + && isset($phpcsFile->config->annotations) + ) { return ! $phpcsFile->config->annotations; } diff --git a/PHPCSUtils/Internal/IsShortArrayOrList.php b/PHPCSUtils/Internal/IsShortArrayOrList.php index 28a38989..36eb7a42 100644 --- a/PHPCSUtils/Internal/IsShortArrayOrList.php +++ b/PHPCSUtils/Internal/IsShortArrayOrList.php @@ -161,7 +161,7 @@ final class IsShortArrayOrList * * @var string */ - private $phpcsVersion; + private $phpcsVersion; // @phpstan-ignore-line /** * Tokens which can open a short array or short list (PHPCS cross-version compatible). @@ -362,27 +362,7 @@ private function isSquareBracket() private function isShortArrayBracket() { if ($this->tokens[$this->opener]['code'] === \T_OPEN_SQUARE_BRACKET) { - if (\version_compare($this->phpcsVersion, '3.7.2', '>=') === true) { - // These will just be properly tokenized, plain square brackets. No need for further checks. - return false; - } - - /* - * BC: Work around a bug in the tokenizer of PHPCS < 3.7.2, where a `[` would be - * tokenized as T_OPEN_SQUARE_BRACKET instead of T_OPEN_SHORT_ARRAY if it was - * preceded by the close parenthesis of a non-braced control structure. - * - * @link https://github.com/squizlabs/PHP_CodeSniffer/issues/3632 - */ - if ($this->tokens[$this->beforeOpener]['code'] === \T_CLOSE_PARENTHESIS - && isset($this->tokens[$this->beforeOpener]['parenthesis_owner']) === true - // phpcs:ignore Generic.Files.LineLength.TooLong - && isset(Tokens::$scopeOpeners[$this->tokens[$this->tokens[$this->beforeOpener]['parenthesis_owner']]['code']]) === true - ) { - return true; - } - - // These are really just plain square brackets. + // Currently there are no known issues with the tokenization in PHPCS 3.9.0 and higher. return false; } diff --git a/PHPCSUtils/Internal/IsShortArrayOrListWithCache.php b/PHPCSUtils/Internal/IsShortArrayOrListWithCache.php index b1b8c47e..b4772bb5 100644 --- a/PHPCSUtils/Internal/IsShortArrayOrListWithCache.php +++ b/PHPCSUtils/Internal/IsShortArrayOrListWithCache.php @@ -138,7 +138,7 @@ public static function isShortList(File $phpcsFile, $stackPtr) * * @return string|false The type of construct this bracket was determined to be. * Either 'short array', 'short list' or 'square brackets'. - * Or FALSE is this was not a bracket token. + * Or FALSE if this was not a bracket token. */ public static function getType(File $phpcsFile, $stackPtr) { diff --git a/PHPCSUtils/TestUtils/UtilityMethodTestCase.php b/PHPCSUtils/TestUtils/UtilityMethodTestCase.php index 2de11a2d..55904857 100644 --- a/PHPCSUtils/TestUtils/UtilityMethodTestCase.php +++ b/PHPCSUtils/TestUtils/UtilityMethodTestCase.php @@ -10,8 +10,11 @@ namespace PHPCSUtils\TestUtils; +use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Exceptions\TokenizerException; +use PHP_CodeSniffer\Files\DummyFile; use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Ruleset; use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Exceptions\TestFileNotFound; use PHPCSUtils\Exceptions\TestMarkerNotFound; @@ -169,7 +172,7 @@ abstract class UtilityMethodTestCase extends TestCase * * @since 1.0.0 * - * @var string[] + * @var array */ protected static $selectedSniff = ['Dummy.Dummy.Dummy']; @@ -220,7 +223,7 @@ public static function setUpTestFile() self::setStaticConfigProperty('configData', ['report_width' => 80]); self::setStaticConfigProperty('configDataFile', ''); - $config = new \PHP_CodeSniffer\Config(); + $config = new Config(); /* * Set to a usable value to circumvent Config trying to find a phpcs.xml config file. @@ -243,12 +246,12 @@ public static function setUpTestFile() // Also set a tab-width to enable testing tab-replaced vs `orig_content`. $config->tabWidth = static::$tabWidth; - $ruleset = new \PHP_CodeSniffer\Ruleset($config); + $ruleset = new Ruleset($config); // Make sure the file gets parsed correctly based on the file type. $contents = 'phpcs_input_file: ' . $caseFile . \PHP_EOL . $contents; - self::$phpcsFile = new \PHP_CodeSniffer\Files\DummyFile($contents, $ruleset, $config); + self::$phpcsFile = new DummyFile($contents, $ruleset, $config); // Only tokenize the file, do not process it. try { @@ -322,6 +325,8 @@ public static function resetTestFile() /** * Helper function to set the value of a private static property on the PHPCS Config class. * + * @since 1.0.9 + * * @param string $name The name of the property to set. * @param mixed $value The value to set the property to. * @@ -367,7 +372,7 @@ public static function usesPhp8NameTokens() * @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|null $tokenContent Optional. The token content for the target token. * * @return int * diff --git a/PHPCSUtils/Tokens/Collections.php b/PHPCSUtils/Tokens/Collections.php index c8465152..a842c9ec 100644 --- a/PHPCSUtils/Tokens/Collections.php +++ b/PHPCSUtils/Tokens/Collections.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tokens; -use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Exceptions\InvalidTokenArray; /** @@ -447,7 +446,7 @@ final class Collections * @var array */ private static $propertyTypeTokens = [ - \T_CALLABLE => \T_CALLABLE, + \T_CALLABLE => \T_CALLABLE, // Not allowed in PHP, but in this list to allow for (flagging) code errors. \T_SELF => \T_SELF, \T_PARENT => \T_PARENT, \T_FALSE => \T_FALSE, diff --git a/PHPCSUtils/Utils/NamingConventions.php b/PHPCSUtils/Utils/NamingConventions.php index c13d0a21..49554580 100644 --- a/PHPCSUtils/Utils/NamingConventions.php +++ b/PHPCSUtils/Utils/NamingConventions.php @@ -40,7 +40,8 @@ final class NamingConventions /** * Uppercase A-Z. * - * @since 1.0.0 + * @since 1.0.0 + * @deprecated 1.0.10 * * @var string */ @@ -49,7 +50,8 @@ final class NamingConventions /** * Lowercase a-z. * - * @since 1.0.0 + * @since 1.0.0 + * @deprecated 1.0.10 * * @var string */ @@ -108,10 +110,7 @@ public static function isEqual($nameA, $nameB) return true; } - // OK, so these may be different names or they may be the same name with case differences. - $nameA = \strtr($nameA, self::AZ_UPPER, self::AZ_LOWER); - $nameB = \strtr($nameB, self::AZ_UPPER, self::AZ_LOWER); - - return ($nameA === $nameB); + // Comparing via strcasecmp will only compare ASCII letters case-insensitively. + return (strcasecmp($nameA, $nameB) === 0); } } diff --git a/PHPCSUtils/Utils/ObjectDeclarations.php b/PHPCSUtils/Utils/ObjectDeclarations.php index cb45bd4f..ffa346ae 100644 --- a/PHPCSUtils/Utils/ObjectDeclarations.php +++ b/PHPCSUtils/Utils/ObjectDeclarations.php @@ -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 string[]|false Array with names of the implemented interfaces or `FALSE` on - * error or if there are no implemented interface names. + * @return array|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 string[]|false Array with names of the extended interfaces or `FALSE` on - * error or if there are no extended interface names. + * @return array|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) { @@ -317,8 +317,8 @@ public static function findExtendedInterfaceNames(File $phpcsFile, $stackPtr) * @param array $allowedFor Array of OO types for which use of the keyword * is allowed. * - * @return string[]|false Returns an array of names or `FALSE` on error or when the object - * being declared does not extend/implement another object. + * @return array|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/PassedParameters.php b/PHPCSUtils/Utils/PassedParameters.php index 35f1f391..00c6311d 100644 --- a/PHPCSUtils/Utils/PassedParameters.php +++ b/PHPCSUtils/Utils/PassedParameters.php @@ -170,7 +170,7 @@ public static function hasParameters(File $phpcsFile, $stackPtr, $isShortArray = * Efficiency tweak for when this has already been established, * Use with EXTREME care. * - * @return array> + * @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 @@ -367,7 +367,7 @@ public static function getParameters(File $phpcsFile, $stackPtr, $limit = 0, $is * @param int $stackPtr The position of function call name, * language construct or array open token. * @param int $paramOffset The 1-based index position of the parameter to retrieve. - * @param string|string[] $paramNames Optional. Either the name of the target parameter + * @param string|array $paramNames Optional. Either the name of the target parameter * to retrieve as a string or an array of names for the * same target parameter. * Only relevant for function calls. @@ -453,17 +453,17 @@ 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|array $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. diff --git a/README.md b/README.md index 430855ea..60cfe41d 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.8.0 up to PHPCS `master`. +These functions are compatible with PHPCS 3.9.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.8.0 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.9.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.8.0+. +* [PHP_CodeSniffer] 3.9.0+. * Recommended PHP extensions for optimal functionality: - PCRE with Unicode support (normally enabled by default) diff --git a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php index 2f34f7b5..6235f41c 100644 --- a/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php +++ b/Tests/AbstractSniffs/AbstractArrayDeclaration/AbstractArrayDeclarationSniffTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff * - * @group abstracts - * * @since 1.0.0 */ final class AbstractArrayDeclarationSniffTest extends PolyfilledTestCase @@ -31,7 +29,7 @@ final class AbstractArrayDeclarationSniffTest extends PolyfilledTestCase * Needed for PHPUnit cross-version support as PHPUnit 4.x does not have a * `setMethodsExcept()` method yet. * - * @var string[] + * @var array */ public $methodsToMock = [ 'processOpenClose', diff --git a/Tests/AbstractSniffs/AbstractArrayDeclaration/GetActualArrayKeyTest.php b/Tests/AbstractSniffs/AbstractArrayDeclaration/GetActualArrayKeyTest.php index dd3e3fed..993cab77 100644 --- a/Tests/AbstractSniffs/AbstractArrayDeclaration/GetActualArrayKeyTest.php +++ b/Tests/AbstractSniffs/AbstractArrayDeclaration/GetActualArrayKeyTest.php @@ -20,8 +20,6 @@ * * @covers \PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff::getActualArrayKey * - * @group abstracts - * * @since 1.0.0 */ final class GetActualArrayKeyTest extends UtilityMethodTestCase @@ -57,8 +55,8 @@ public function testGetActualArrayKey($testMarker, $expected, $expectedFrom) $this->assertSame( $expected, $result, - 'Failed: actual key ' . $result . ' is not the same as the expected key ' . $expected - . ' for item number ' . $itemNr + 'Failed: actual key ' . \var_export($result, true) . ' is not the same as the expected key ' + . \var_export($expected, true) . ' for item number ' . $itemNr ); } } @@ -69,7 +67,7 @@ public function testGetActualArrayKey($testMarker, $expected, $expectedFrom) * * @see testGetActualArrayKey() For the array format. * - * @return array + * @return array> */ public static function dataGetActualArrayKey() { @@ -135,8 +133,8 @@ public function testGetActualArrayKeyFromHeredocWithEscapedVarInKey() $this->assertSame( $expected[$itemNr], $result, - 'Failed: actual key ' . $result . ' is not the same as the expected key ' . $expected[$itemNr] - . ' for item number ' . $itemNr + 'Failed: actual key ' . \var_export($result, true) . ' is not the same as the expected key ' + . \var_export($expected[$itemNr], true) . ' for item number ' . $itemNr ); } } diff --git a/Tests/BackCompat/BCFile/FindExtendedClassNameTest.inc b/Tests/BackCompat/BCFile/FindExtendedClassNameTest.inc index 58b73505..d9885d27 100644 --- a/Tests/BackCompat/BCFile/FindExtendedClassNameTest.inc +++ b/Tests/BackCompat/BCFile/FindExtendedClassNameTest.inc @@ -3,26 +3,30 @@ /* testNotAClass */ function notAClass() {} -class testFECNClass {} +/* testNonExtendedClass */ +class testFECNNonExtendedClass {} -/* testExtendedClass */ +/* testExtendsUnqualifiedClass */ class testFECNExtendedClass extends testFECNClass {} -/* testNamespacedClass */ +/* testExtendsFullyQualifiedClass */ class testFECNNamespacedClass extends \PHP_CodeSniffer\Tests\Core\File\testFECNClass {} -/* testNonExtendedClass */ -class testFECNNonExtendedClass {} +/* testExtendsPartiallyQualifiedClass */ +class testFECNQualifiedClass extends Core\File\RelativeClass {} -/* testInterface */ +/* testNonExtendedInterface */ interface testFECNInterface {} -/* testInterfaceThatExtendsInterface */ +/* testInterfaceExtendsUnqualifiedInterface */ interface testInterfaceThatExtendsInterface extends testFECNInterface{} -/* testInterfaceThatExtendsFQCNInterface */ +/* testInterfaceExtendsFullyQualifiedInterface */ interface testInterfaceThatExtendsFQCNInterface extends \PHP_CodeSniffer\Tests\Core\File\testFECNInterface{} +/* testExtendedAnonClass */ +$anon = new class( $a, $b ) extends testFECNExtendedAnonClass {}; + /* testNestedExtendedClass */ class testFECNNestedExtendedClass { public function someMethod() { @@ -31,18 +35,12 @@ class testFECNNestedExtendedClass { } } -/* testNamespaceRelativeQualifiedClass */ -class testFECNQualifiedClass extends Core\File\RelativeClass {} - /* testClassThatExtendsAndImplements */ class testFECNClassThatExtendsAndImplements extends testFECNClass implements InterfaceA, InterfaceB {} /* testClassThatImplementsAndExtends */ class testFECNClassThatImplementsAndExtends implements InterfaceA, InterfaceB extends testFECNClass {} -/* testExtendedAnonClass */ -$anon = new class( $a, $b ) extends testFECNExtendedAnonClass {}; - /* testInterfaceMultiExtends */ interface Multi extends \Package\FooInterface, \BarInterface {}; diff --git a/Tests/BackCompat/BCFile/FindExtendedClassNameTest.php b/Tests/BackCompat/BCFile/FindExtendedClassNameTest.php index d826541d..254d99a8 100644 --- a/Tests/BackCompat/BCFile/FindExtendedClassNameTest.php +++ b/Tests/BackCompat/BCFile/FindExtendedClassNameTest.php @@ -81,8 +81,8 @@ public function testNotAClass() * * @dataProvider dataExtendedClass * - * @param string $identifier Comment which precedes the test case. - * @param bool $expected Expected function output. + * @param string $identifier Comment which precedes the test case. + * @param string|false $expected Expected function output. * * @return void */ @@ -100,70 +100,70 @@ public function testFindExtendedClassName($identifier, $expected) * * @see testFindExtendedClassName() * - * @return array + * @return array> */ public static function dataExtendedClass() { return [ - [ - '/* testExtendedClass */', - 'testFECNClass', + 'class does not extend' => [ + 'identifier' => '/* testNonExtendedClass */', + 'expected' => false, ], - [ - '/* testNamespacedClass */', - '\PHP_CodeSniffer\Tests\Core\File\testFECNClass', + 'class extends unqualified class' => [ + 'identifier' => '/* testExtendsUnqualifiedClass */', + 'expected' => 'testFECNClass', ], - [ - '/* testNonExtendedClass */', - false, + 'class extends fully qualified class' => [ + 'identifier' => '/* testExtendsFullyQualifiedClass */', + 'expected' => '\PHP_CodeSniffer\Tests\Core\File\testFECNClass', ], - [ - '/* testInterface */', - false, + 'class extends partially qualified class' => [ + 'identifier' => '/* testExtendsPartiallyQualifiedClass */', + 'expected' => 'Core\File\RelativeClass', ], - [ - '/* testInterfaceThatExtendsInterface */', - 'testFECNInterface', + 'interface does not extend' => [ + 'identifier' => '/* testNonExtendedInterface */', + 'expected' => false, ], - [ - '/* testInterfaceThatExtendsFQCNInterface */', - '\PHP_CodeSniffer\Tests\Core\File\testFECNInterface', + 'interface extends unqualified interface' => [ + 'identifier' => '/* testInterfaceExtendsUnqualifiedInterface */', + 'expected' => 'testFECNInterface', ], - [ - '/* testNestedExtendedClass */', - false, + 'interface extends fully qualified interface' => [ + 'identifier' => '/* testInterfaceExtendsFullyQualifiedInterface */', + 'expected' => '\PHP_CodeSniffer\Tests\Core\File\testFECNInterface', ], - [ - '/* testNestedExtendedAnonClass */', - 'testFECNAnonClass', + 'anon class extends unqualified class' => [ + 'identifier' => '/* testExtendedAnonClass */', + 'expected' => 'testFECNExtendedAnonClass', ], - [ - '/* testNamespaceRelativeQualifiedClass */', - 'Core\File\RelativeClass', + 'class does not extend but contains anon class which extends' => [ + 'identifier' => '/* testNestedExtendedClass */', + 'expected' => false, ], - [ - '/* testClassThatExtendsAndImplements */', - 'testFECNClass', + 'anon class extends, nested in non-extended class' => [ + 'identifier' => '/* testNestedExtendedAnonClass */', + 'expected' => 'testFECNAnonClass', ], - [ - '/* testClassThatImplementsAndExtends */', - 'testFECNClass', + 'class extends and implements' => [ + 'identifier' => '/* testClassThatExtendsAndImplements */', + 'expected' => 'testFECNClass', ], - [ - '/* testExtendedAnonClass */', - 'testFECNExtendedAnonClass', + 'class implements and extends' => [ + 'identifier' => '/* testClassThatImplementsAndExtends */', + 'expected' => 'testFECNClass', ], - [ - '/* testInterfaceMultiExtends */', - '\Package\FooInterface', + 'interface extends multiple interfaces (not supported)' => [ + 'identifier' => '/* testInterfaceMultiExtends */', + 'expected' => '\Package\FooInterface', ], - [ - '/* testMissingExtendsName */', - false, + 'parse error - extends keyword, but no class name' => [ + 'identifier' => '/* testMissingExtendsName */', + 'expected' => false, ], - [ - '/* testParseError */', - false, + 'parse error - live coding - no curly braces' => [ + 'identifier' => '/* testParseError */', + 'expected' => false, ], ]; } diff --git a/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.inc b/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.inc index e1cc427a..3246efa2 100644 --- a/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.inc +++ b/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.inc @@ -3,24 +3,22 @@ /* testNotAClass */ function notAClass() {} -interface testFIINInterface2 {} - -/* testInterface */ +/* testPlainInterface */ interface testFIINInterface {} -/* testImplementedClass */ +/* testNonImplementedClass */ +class testFIINNonImplementedClass {} + +/* testClassImplementsSingle */ class testFIINImplementedClass implements testFIINInterface {} -/* testMultiImplementedClass */ +/* testClassImplementsMultiple */ class testFIINMultiImplementedClass implements testFIINInterface, testFIINInterface2 {} -/* testNamespacedClass */ +/* testImplementsFullyQualified */ class testFIINNamespacedClass implements \PHP_CodeSniffer\Tests\Core\File\testFIINInterface {} -/* testNonImplementedClass */ -class testFIINNonImplementedClass {} - -/* testNamespaceRelativeQualifiedClass */ +/* testImplementsPartiallyQualified */ class testFIINQualifiedClass implements Core\File\RelativeInterface {} /* testClassThatExtendsAndImplements */ @@ -32,13 +30,13 @@ class testFECNClassThatImplementsAndExtends implements \InterfaceA, InterfaceB e /* testBackedEnumWithoutImplements */ enum Suit:string {} -/* testEnumImplements */ +/* testEnumImplementsSingle */ enum Suit implements Colorful {} -/* testBackedEnumImplements */ +/* testBackedEnumImplementsMulti */ enum Suit: string implements Colorful, \Deck {} -/* testAnonClassImplements */ +/* testAnonClassImplementsSingle */ $anon = class() implements testFIINInterface {} /* testMissingImplementsName */ diff --git a/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.php b/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.php index d31f4105..7b24f254 100644 --- a/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.php +++ b/Tests/BackCompat/BCFile/FindImplementedInterfaceNamesTest.php @@ -79,8 +79,8 @@ public function testNotAClass() * * @dataProvider dataImplementedInterface * - * @param string $identifier Comment which precedes the test case. - * @param bool $expected Expected function output. + * @param string $identifier Comment which precedes the test case. + * @param array|false $expected Expected function output. * * @return void */ @@ -98,78 +98,78 @@ public function testFindImplementedInterfaceNames($identifier, $expected) * * @see testFindImplementedInterfaceNames() * - * @return array + * @return array|false>> */ public static function dataImplementedInterface() { return [ - [ - '/* testImplementedClass */', - ['testFIINInterface'], + 'interface declaration, no implements' => [ + 'identifier' => '/* testPlainInterface */', + 'expected' => false, ], - [ - '/* testMultiImplementedClass */', - [ + 'class does not implement' => [ + 'identifier' => '/* testNonImplementedClass */', + 'expected' => false, + ], + 'class implements single interface, unqualified' => [ + 'identifier' => '/* testClassImplementsSingle */', + 'expected' => ['testFIINInterface'], + ], + 'class implements multiple interfaces' => [ + 'identifier' => '/* testClassImplementsMultiple */', + 'expected' => [ 'testFIINInterface', 'testFIINInterface2', ], ], - [ - '/* testNamespacedClass */', - ['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface'], - ], - [ - '/* testNonImplementedClass */', - false, - ], - [ - '/* testInterface */', - false, + 'class implements single interface, fully qualified' => [ + 'identifier' => '/* testImplementsFullyQualified */', + 'expected' => ['\PHP_CodeSniffer\Tests\Core\File\testFIINInterface'], ], - [ - '/* testNamespaceRelativeQualifiedClass */', - ['Core\File\RelativeInterface'], + 'class implements single interface, partially qualified' => [ + 'identifier' => '/* testImplementsPartiallyQualified */', + 'expected' => ['Core\File\RelativeInterface'], ], - [ - '/* testClassThatExtendsAndImplements */', - [ + 'class extends and implements' => [ + 'identifier' => '/* testClassThatExtendsAndImplements */', + 'expected' => [ 'InterfaceA', '\NameSpaced\Cat\InterfaceB', ], ], - [ - '/* testClassThatImplementsAndExtends */', - [ + 'class implements and extends' => [ + 'identifier' => '/* testClassThatImplementsAndExtends */', + 'expected' => [ '\InterfaceA', 'InterfaceB', ], ], - [ - '/* testBackedEnumWithoutImplements */', - false, + 'enum does not implement' => [ + 'identifier' => '/* testBackedEnumWithoutImplements */', + 'expected' => false, ], - [ - '/* testEnumImplements */', - ['Colorful'], + 'enum implements single interface, unqualified' => [ + 'identifier' => '/* testEnumImplementsSingle */', + 'expected' => ['Colorful'], ], - [ - '/* testBackedEnumImplements */', - [ + 'enum implements multiple interfaces, unqualified + fully qualified' => [ + 'identifier' => '/* testBackedEnumImplementsMulti */', + 'expected' => [ 'Colorful', '\Deck', ], ], - [ - '/* testAnonClassImplements */', - ['testFIINInterface'], + 'anon class implements single interface, unqualified' => [ + 'identifier' => '/* testAnonClassImplementsSingle */', + 'expected' => ['testFIINInterface'], ], - [ - '/* testMissingImplementsName */', - false, + 'parse error - implements keyword, but no interface name' => [ + 'identifier' => '/* testMissingImplementsName */', + 'expected' => false, ], - [ - '/* testParseError */', - false, + 'parse error - live coding - no curly braces' => [ + 'identifier' => '/* testParseError */', + 'expected' => false, ], ]; } diff --git a/Tests/BackCompat/BCFile/FindStartOfStatementTest.inc b/Tests/BackCompat/BCFile/FindStartOfStatementTest.inc index 7061c473..148d8103 100644 --- a/Tests/BackCompat/BCFile/FindStartOfStatementTest.inc +++ b/Tests/BackCompat/BCFile/FindStartOfStatementTest.inc @@ -1,9 +1,5 @@ Test ', foo(), ''; -?> $song->url()) diff --git a/Tests/BackCompat/BCFile/FindStartOfStatementTest.php b/Tests/BackCompat/BCFile/FindStartOfStatementTest.php index de3d91ec..8f6aeeb6 100644 --- a/Tests/BackCompat/BCFile/FindStartOfStatementTest.php +++ b/Tests/BackCompat/BCFile/FindStartOfStatementTest.php @@ -485,9 +485,9 @@ public function testObjectCallPrecededByArrowFunctionAsFunctionCallParameterInAr * * @dataProvider dataFindStartInsideSwitchCaseDefaultStatements * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array|string|int $targets The token to search for after the test marker. - * @param string|int $expectedTarget Token code of the expected start of statement stack pointer. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targets The token to search for after the test marker. + * @param string|int $expectedTarget Token code of the expected start of statement stack pointer. * * @return void */ @@ -504,7 +504,7 @@ public function testFindStartInsideSwitchCaseDefaultStatements($testMarker, $tar /** * Data provider. * - * @return array + * @return array> */ public static function dataFindStartInsideSwitchCaseDefaultStatements() { diff --git a/Tests/BackCompat/BCFile/GetClassPropertiesTest.php b/Tests/BackCompat/BCFile/GetClassPropertiesTest.php index 9ccfef3a..df30cd02 100644 --- a/Tests/BackCompat/BCFile/GetClassPropertiesTest.php +++ b/Tests/BackCompat/BCFile/GetClassPropertiesTest.php @@ -40,8 +40,8 @@ class GetClassPropertiesTest extends UtilityMethodTestCase * * @dataProvider dataNotAClassException * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $tokenType The type of token to look for after the marker. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $tokenType The type of token to look for after the marker. * * @return void */ @@ -59,22 +59,22 @@ public function testNotAClassException($testMarker, $tokenType) * * @see testNotAClassException() For the array format. * - * @return array + * @return array> */ public static function dataNotAClassException() { return [ 'interface' => [ - '/* testNotAClass */', - \T_INTERFACE, + 'testMarker' => '/* testNotAClass */', + 'tokenType' => \T_INTERFACE, ], 'anon-class' => [ - '/* testAnonClass */', - \T_ANON_CLASS, + 'testMarker' => '/* testAnonClass */', + 'tokenType' => \T_ANON_CLASS, ], 'enum' => [ - '/* testEnum */', - \T_ENUM, + 'testMarker' => '/* testEnum */', + 'tokenType' => \T_ENUM, ], ]; } @@ -84,8 +84,8 @@ public static function dataNotAClassException() * * @dataProvider dataGetClassProperties * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected Expected function output. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected Expected function output. * * @return void */ @@ -104,14 +104,14 @@ public function testGetClassProperties($testMarker, $expected) * * @see testGetClassProperties() For the array format. * - * @return array + * @return array>> */ public static function dataGetClassProperties() { return [ 'no-properties' => [ - '/* testClassWithoutProperties */', - [ + 'testMarker' => '/* testClassWithoutProperties */', + 'expected' => [ 'is_abstract' => false, 'abstract_token' => false, 'is_final' => false, @@ -121,8 +121,8 @@ public static function dataGetClassProperties() ], ], 'abstract' => [ - '/* testAbstractClass */', - [ + 'testMarker' => '/* testAbstractClass */', + 'expected' => [ 'is_abstract' => true, 'abstract_token' => -2, 'is_final' => false, @@ -132,8 +132,8 @@ public static function dataGetClassProperties() ], ], 'final' => [ - '/* testFinalClass */', - [ + 'testMarker' => '/* testFinalClass */', + 'expected' => [ 'is_abstract' => false, 'abstract_token' => false, 'is_final' => true, @@ -143,8 +143,8 @@ public static function dataGetClassProperties() ], ], 'readonly' => [ - '/* testReadonlyClass */', - [ + 'testMarker' => '/* testReadonlyClass */', + 'expected' => [ 'is_abstract' => false, 'abstract_token' => false, 'is_final' => false, @@ -154,8 +154,8 @@ public static function dataGetClassProperties() ], ], 'final-readonly' => [ - '/* testFinalReadonlyClass */', - [ + 'testMarker' => '/* testFinalReadonlyClass */', + 'expected' => [ 'is_abstract' => false, 'abstract_token' => false, 'is_final' => true, @@ -165,8 +165,8 @@ public static function dataGetClassProperties() ], ], 'readonly-final' => [ - '/* testReadonlyFinalClass */', - [ + 'testMarker' => '/* testReadonlyFinalClass */', + 'expected' => [ 'is_abstract' => false, 'abstract_token' => false, 'is_final' => true, @@ -176,8 +176,8 @@ public static function dataGetClassProperties() ], ], 'abstract-readonly' => [ - '/* testAbstractReadonlyClass */', - [ + 'testMarker' => '/* testAbstractReadonlyClass */', + 'expected' => [ 'is_abstract' => true, 'abstract_token' => -4, 'is_final' => false, @@ -187,8 +187,8 @@ public static function dataGetClassProperties() ], ], 'readonly-abstract' => [ - '/* testReadonlyAbstractClass */', - [ + 'testMarker' => '/* testReadonlyAbstractClass */', + 'expected' => [ 'is_abstract' => true, 'abstract_token' => -2, 'is_final' => false, @@ -198,8 +198,8 @@ public static function dataGetClassProperties() ], ], 'comments-and-new-lines' => [ - '/* testWithCommentsAndNewLines */', - [ + 'testMarker' => '/* testWithCommentsAndNewLines */', + 'expected' => [ 'is_abstract' => true, 'abstract_token' => -6, 'is_final' => false, @@ -209,8 +209,8 @@ public static function dataGetClassProperties() ], ], 'no-properties-with-docblock' => [ - '/* testWithDocblockWithoutProperties */', - [ + 'testMarker' => '/* testWithDocblockWithoutProperties */', + 'expected' => [ 'is_abstract' => false, 'abstract_token' => false, 'is_final' => false, @@ -220,8 +220,8 @@ public static function dataGetClassProperties() ], ], 'abstract-final-parse-error' => [ - '/* testParseErrorAbstractFinal */', - [ + 'testMarker' => '/* testParseErrorAbstractFinal */', + 'expected' => [ 'is_abstract' => true, 'abstract_token' => -5, 'is_final' => true, diff --git a/Tests/BackCompat/BCFile/GetConditionTest.php b/Tests/BackCompat/BCFile/GetConditionTest.php index 1c6e0f46..c66b24e9 100644 --- a/Tests/BackCompat/BCFile/GetConditionTest.php +++ b/Tests/BackCompat/BCFile/GetConditionTest.php @@ -56,7 +56,7 @@ class GetConditionTest extends UtilityMethodTestCase /** * List of all the condition markers in the test case file. * - * @var string[] + * @var array */ protected $conditionMarkers = [ '/* condition 0: namespace */', @@ -212,9 +212,9 @@ public function testNonConditionalToken() * * @dataProvider dataGetCondition * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expectedResults Array with the condition token type to search for as key - * and the marker for the expected stack pointer result as a value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expectedResults Array with the condition token type to search for as key + * and the marker for the expected stack pointer result as a value. * * @return void */ @@ -227,7 +227,7 @@ public function testGetCondition($testMarker, $expectedResults) $expectedResults += $this->conditionDefaults; foreach ($expectedResults as $conditionType => $expected) { - if ($expected !== false) { + if (\is_string($expected)) { $expected = self::$markerTokens[$expected]; } @@ -249,14 +249,14 @@ public function testGetCondition($testMarker, $expectedResults) * * @see testGetCondition() For the array format. * - * @return array + * @return array>> */ public static function dataGetCondition() { return [ 'testSeriouslyNestedMethod' => [ - '/* testSeriouslyNestedMethod */', - [ + 'testMarker' => '/* testSeriouslyNestedMethod */', + 'expectedResults' => [ 'T_CLASS' => '/* condition 5: nested class */', 'T_NAMESPACE' => '/* condition 0: namespace */', 'T_FUNCTION' => '/* condition 2: function */', @@ -265,8 +265,8 @@ public static function dataGetCondition() ], ], 'testDeepestNested' => [ - '/* testDeepestNested */', - [ + 'testMarker' => '/* testDeepestNested */', + 'expectedResults' => [ 'T_CLASS' => '/* condition 5: nested class */', 'T_ANON_CLASS' => '/* condition 11-1: nested anonymous class */', 'T_NAMESPACE' => '/* condition 0: namespace */', @@ -280,8 +280,8 @@ public static function dataGetCondition() ], ], 'testInException' => [ - '/* testInException */', - [ + 'testMarker' => '/* testInException */', + 'expectedResults' => [ 'T_CLASS' => '/* condition 5: nested class */', 'T_NAMESPACE' => '/* condition 0: namespace */', 'T_FUNCTION' => '/* condition 2: function */', @@ -295,8 +295,8 @@ public static function dataGetCondition() ], ], 'testInDefault' => [ - '/* testInDefault */', - [ + 'testMarker' => '/* testInDefault */', + 'expectedResults' => [ 'T_CLASS' => '/* condition 5: nested class */', 'T_NAMESPACE' => '/* condition 0: namespace */', 'T_FUNCTION' => '/* condition 2: function */', @@ -314,9 +314,9 @@ public static function dataGetCondition() * * @dataProvider dataGetConditionReversed * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expectedResults Array with the condition token type to search for as key - * and the marker for the expected stack pointer result as a value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expectedResults Array with the condition token type to search for as key + * and the marker for the expected stack pointer result as a value. * * @return void */ @@ -329,7 +329,7 @@ public function testGetConditionReversed($testMarker, $expectedResults) $expectedResults += $this->conditionDefaults; foreach ($expectedResults as $conditionType => $expected) { - if ($expected !== false) { + if (\is_string($expected)) { $expected = self::$markerTokens[$expected]; } @@ -351,23 +351,23 @@ public function testGetConditionReversed($testMarker, $expectedResults) * * @see testGetConditionReversed() For the array format. * - * @return array + * @return array>> */ public static function dataGetConditionReversed() { $data = self::dataGetCondition(); // Set up the data for the reversed results. - $data['testSeriouslyNestedMethod'][1]['T_IF'] = '/* condition 4: if */'; + $data['testSeriouslyNestedMethod']['expectedResults']['T_IF'] = '/* condition 4: if */'; - $data['testDeepestNested'][1]['T_FUNCTION'] = '/* condition 12: nested anonymous class method */'; - $data['testDeepestNested'][1]['T_IF'] = '/* condition 10-1: if */'; + $data['testDeepestNested']['expectedResults']['T_FUNCTION'] = '/* condition 12: nested anonymous class method */'; + $data['testDeepestNested']['expectedResults']['T_IF'] = '/* condition 10-1: if */'; - $data['testInException'][1]['T_FUNCTION'] = '/* condition 6: class method */'; - $data['testInException'][1]['T_IF'] = '/* condition 4: if */'; + $data['testInException']['expectedResults']['T_FUNCTION'] = '/* condition 6: class method */'; + $data['testInException']['expectedResults']['T_IF'] = '/* condition 4: if */'; - $data['testInDefault'][1]['T_FUNCTION'] = '/* condition 6: class method */'; - $data['testInDefault'][1]['T_IF'] = '/* condition 4: if */'; + $data['testInDefault']['expectedResults']['T_FUNCTION'] = '/* condition 6: class method */'; + $data['testInDefault']['expectedResults']['T_IF'] = '/* condition 4: if */'; return $data; } @@ -377,9 +377,9 @@ public static function dataGetConditionReversed() * * @dataProvider dataHasCondition * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expectedResults Array with the condition token type to search for as key - * and the expected result as a value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expectedResults Array with the condition token type to search for as key + * and the expected result as a value. * * @return void */ @@ -410,14 +410,14 @@ public function testHasCondition($testMarker, $expectedResults) * * @see testHasCondition() For the array format. * - * @return array + * @return array>> */ public static function dataHasCondition() { return [ 'testSeriouslyNestedMethod' => [ - '/* testSeriouslyNestedMethod */', - [ + 'testMarker' => '/* testSeriouslyNestedMethod */', + 'expectedResults' => [ 'T_CLASS' => true, 'T_NAMESPACE' => true, 'T_FUNCTION' => true, @@ -426,8 +426,8 @@ public static function dataHasCondition() ], ], 'testDeepestNested' => [ - '/* testDeepestNested */', - [ + 'testMarker' => '/* testDeepestNested */', + 'expectedResults' => [ 'T_CLASS' => true, 'T_ANON_CLASS' => true, 'T_NAMESPACE' => true, @@ -441,8 +441,8 @@ public static function dataHasCondition() ], ], 'testInException' => [ - '/* testInException */', - [ + 'testMarker' => '/* testInException */', + 'expectedResults' => [ 'T_CLASS' => true, 'T_NAMESPACE' => true, 'T_FUNCTION' => true, @@ -456,8 +456,8 @@ public static function dataHasCondition() ], ], 'testInDefault' => [ - '/* testInDefault */', - [ + 'testMarker' => '/* testInDefault */', + 'expectedResults' => [ 'T_CLASS' => true, 'T_NAMESPACE' => true, 'T_FUNCTION' => true, diff --git a/Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php b/Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php index eb58af1a..c1245a3c 100644 --- a/Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php +++ b/Tests/BackCompat/BCFile/GetDeclarationNameJSTest.php @@ -67,14 +67,14 @@ public function testGetDeclarationNameNull($testMarker, $targetType) * * @see GetDeclarationNameTest::testGetDeclarationNameNull() * - * @return array + * @return array> */ public static function dataGetDeclarationNameNull() { return [ 'closure' => [ - '/* testClosure */', - \T_CLOSURE, + 'testMarker' => '/* testClosure */', + 'targetType' => \T_CLOSURE, ], ]; } @@ -84,9 +84,9 @@ public static function dataGetDeclarationNameNull() * * @dataProvider dataGetDeclarationName * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param string $expected Expected function output. - * @param int|string $targetType Token type of the token to get as stackPtr. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expected Expected function output. + * @param array|null $targetType Token type of the token to get as stackPtr. * * @return void */ @@ -106,23 +106,23 @@ public function testGetDeclarationName($testMarker, $expected, $targetType = nul * * @see GetDeclarationNameTest::testGetDeclarationName() * - * @return array + * @return array>> */ public static function dataGetDeclarationName() { return [ 'function' => [ - '/* testFunction */', - 'functionName', + 'testMarker' => '/* testFunction */', + 'expected' => 'functionName', ], 'class' => [ - '/* testClass */', - 'ClassName', - [\T_CLASS, \T_STRING], + 'testMarker' => '/* testClass */', + 'expected' => 'ClassName', + 'targetType' => [\T_CLASS, \T_STRING], ], 'function-unicode-name' => [ - '/* testFunctionUnicode */', - 'π', + 'testMarker' => '/* testFunctionUnicode */', + 'expected' => 'π', ], ]; } diff --git a/Tests/BackCompat/BCFile/GetDeclarationNameTest.php b/Tests/BackCompat/BCFile/GetDeclarationNameTest.php index f7c8a358..466ec7a6 100644 --- a/Tests/BackCompat/BCFile/GetDeclarationNameTest.php +++ b/Tests/BackCompat/BCFile/GetDeclarationNameTest.php @@ -60,34 +60,34 @@ public function testGetDeclarationNameNull($testMarker, $targetType) * * @see testGetDeclarationNameNull() For the array format. * - * @return array + * @return array> */ public static function dataGetDeclarationNameNull() { return [ 'closure' => [ - '/* testClosure */', - \T_CLOSURE, + 'testMarker' => '/* testClosure */', + 'targetType' => \T_CLOSURE, ], 'anon-class-with-parentheses' => [ - '/* testAnonClassWithParens */', - \T_ANON_CLASS, + 'testMarker' => '/* testAnonClassWithParens */', + 'targetType' => \T_ANON_CLASS, ], 'anon-class-with-parentheses-2' => [ - '/* testAnonClassWithParens2 */', - \T_ANON_CLASS, + 'testMarker' => '/* testAnonClassWithParens2 */', + 'targetType' => \T_ANON_CLASS, ], 'anon-class-without-parentheses' => [ - '/* testAnonClassWithoutParens */', - \T_ANON_CLASS, + 'testMarker' => '/* testAnonClassWithoutParens */', + 'targetType' => \T_ANON_CLASS, ], 'anon-class-extends-without-parentheses' => [ - '/* testAnonClassExtendsWithoutParens */', - \T_ANON_CLASS, + 'testMarker' => '/* testAnonClassExtendsWithoutParens */', + 'targetType' => \T_ANON_CLASS, ], 'live-coding' => [ - '/* testLiveCoding */', - \T_FUNCTION, + 'testMarker' => '/* testLiveCoding */', + 'targetType' => \T_FUNCTION, ], ]; } @@ -97,9 +97,9 @@ public static function dataGetDeclarationNameNull() * * @dataProvider dataGetDeclarationName * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param string $expected Expected function output. - * @param int|string $targetType Token type of the token to get as stackPtr. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expected Expected function output. + * @param int|string|null $targetType Token type of the token to get as stackPtr. * * @return void */ @@ -119,94 +119,94 @@ public function testGetDeclarationName($testMarker, $expected, $targetType = nul * * @see testGetDeclarationName() For the array format. * - * @return array + * @return array> */ public static function dataGetDeclarationName() { return [ 'function' => [ - '/* testFunction */', - 'functionName', + 'testMarker' => '/* testFunction */', + 'expected' => 'functionName', ], 'function-return-by-reference' => [ - '/* testFunctionReturnByRef */', - 'functionNameByRef', + 'testMarker' => '/* testFunctionReturnByRef */', + 'expected' => 'functionNameByRef', ], 'class' => [ - '/* testClass */', - 'ClassName', + 'testMarker' => '/* testClass */', + 'expected' => 'ClassName', ], 'method' => [ - '/* testMethod */', - 'methodName', + 'testMarker' => '/* testMethod */', + 'expected' => 'methodName', ], 'abstract-method' => [ - '/* testAbstractMethod */', - 'abstractMethodName', + 'testMarker' => '/* testAbstractMethod */', + 'expected' => 'abstractMethodName', ], 'method-return-by-reference' => [ - '/* testMethodReturnByRef */', - 'MethodNameByRef', + 'testMarker' => '/* testMethodReturnByRef */', + 'expected' => 'MethodNameByRef', ], 'extended-class' => [ - '/* testExtendedClass */', - 'ExtendedClass', + 'testMarker' => '/* testExtendedClass */', + 'expected' => 'ExtendedClass', ], 'interface' => [ - '/* testInterface */', - 'InterfaceName', + 'testMarker' => '/* testInterface */', + 'expected' => 'InterfaceName', ], 'trait' => [ - '/* testTrait */', - 'TraitName', + 'testMarker' => '/* testTrait */', + 'expected' => 'TraitName', ], 'function-name-ends-with-number' => [ - '/* testFunctionEndingWithNumber */', - 'ValidNameEndingWithNumber5', + 'testMarker' => '/* testFunctionEndingWithNumber */', + 'expected' => 'ValidNameEndingWithNumber5', ], 'class-with-numbers-in-name' => [ - '/* testClassWithNumber */', - 'ClassWith1Number', + 'testMarker' => '/* testClassWithNumber */', + 'expected' => 'ClassWith1Number', ], 'interface-with-numbers-in-name' => [ - '/* testInterfaceWithNumbers */', - 'InterfaceWith12345Numbers', + 'testMarker' => '/* testInterfaceWithNumbers */', + 'expected' => 'InterfaceWith12345Numbers', ], 'class-with-comments-and-new-lines' => [ - '/* testClassWithCommentsAndNewLines */', - 'ClassWithCommentsAndNewLines', + 'testMarker' => '/* testClassWithCommentsAndNewLines */', + 'expected' => 'ClassWithCommentsAndNewLines', ], 'function-named-fn' => [ - '/* testFunctionFn */', - 'fn', + 'testMarker' => '/* testFunctionFn */', + 'expected' => 'fn', ], 'enum-pure' => [ - '/* testPureEnum */', - 'Foo', + 'testMarker' => '/* testPureEnum */', + 'expected' => 'Foo', ], 'enum-backed-space-between-name-and-colon' => [ - '/* testBackedEnumSpaceBetweenNameAndColon */', - 'Hoo', + 'testMarker' => '/* testBackedEnumSpaceBetweenNameAndColon */', + 'expected' => 'Hoo', ], 'enum-backed-no-space-between-name-and-colon' => [ - '/* testBackedEnumNoSpaceBetweenNameAndColon */', - 'Suit', + 'testMarker' => '/* testBackedEnumNoSpaceBetweenNameAndColon */', + 'expected' => 'Suit', ], 'function-return-by-reference-with-reserved-keyword-each' => [ - '/* testFunctionReturnByRefWithReservedKeywordEach */', - 'each', + 'testMarker' => '/* testFunctionReturnByRefWithReservedKeywordEach */', + 'expected' => 'each', ], 'function-return-by-reference-with-reserved-keyword-parent' => [ - '/* testFunctionReturnByRefWithReservedKeywordParent */', - 'parent', + 'testMarker' => '/* testFunctionReturnByRefWithReservedKeywordParent */', + 'expected' => 'parent', ], 'function-return-by-reference-with-reserved-keyword-self' => [ - '/* testFunctionReturnByRefWithReservedKeywordSelf */', - 'self', + 'testMarker' => '/* testFunctionReturnByRefWithReservedKeywordSelf */', + 'expected' => 'self', ], 'function-return-by-reference-with-reserved-keyword-static' => [ - '/* testFunctionReturnByRefWithReservedKeywordStatic */', - 'static', + 'testMarker' => '/* testFunctionReturnByRefWithReservedKeywordStatic */', + 'expected' => 'static', ], ]; } diff --git a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.inc b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.inc index eca7b4ac..e5b6d306 100644 --- a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.inc +++ b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.inc @@ -213,6 +213,7 @@ $anon = class() { /* testPHP8UnionTypesIllegalTypes */ // Intentional fatal error - types which are not allowed for properties, but that's not the concern of the method. + // Note: static is also not allowed as a type, but using static for a property type is not supported by the tokenizer. public callable|static|void $unionTypesIllegalTypes; /* testPHP8UnionTypesNullable */ diff --git a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php index 61964fc6..a1c397da 100644 --- a/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php +++ b/Tests/BackCompat/BCFile/GetMemberPropertiesTest.php @@ -51,8 +51,8 @@ class GetMemberPropertiesTest extends UtilityMethodTestCase * * @dataProvider dataGetMemberProperties * - * @param string $identifier Comment which precedes the test case. - * @param array $expected Expected function output. + * @param string $identifier Comment which precedes the test case. + * @param array $expected Expected function output. * * @return void */ @@ -63,10 +63,11 @@ public function testGetMemberProperties($identifier, $expected) $variable = $this->getTargetToken($identifier, T_VARIABLE); $result = $testClass::getMemberProperties(self::$phpcsFile, $variable); - if (isset($expected['type_token']) && $expected['type_token'] !== false) { + // Convert offsets to absolute positions in the token stream. + if (isset($expected['type_token']) && \is_int($expected['type_token']) === true) { $expected['type_token'] += $variable; } - if (isset($expected['type_end_token']) && $expected['type_end_token'] !== false) { + if (isset($expected['type_end_token']) && \is_int($expected['type_end_token']) === true) { $expected['type_end_token'] += $variable; } @@ -76,9 +77,13 @@ public function testGetMemberProperties($identifier, $expected) /** * Data provider. * + * Note: the `expected - type_token` and `expected - type_end_token` indexes should + * contain either `false` (no type) or the _offset_ of the type start/end token in + * relation to the `T_VARIABLE` token which is passed to the getMemberProperties() method. + * * @see testGetMemberProperties() * - * @return array + * @return array>> */ public static function dataGetMemberProperties() { @@ -86,8 +91,8 @@ public static function dataGetMemberProperties() return [ 'var-modifier' => [ - '/* testVar */', - [ + 'identifier' => '/* testVar */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, @@ -99,21 +104,21 @@ public static function dataGetMemberProperties() ], ], 'var-modifier-and-type' => [ - '/* testVarType */', - [ + 'identifier' => '/* testVarType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, 'is_readonly' => false, 'type' => '?int', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'public-modifier' => [ - '/* testPublic */', - [ + 'identifier' => '/* testPublic */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -125,21 +130,21 @@ public static function dataGetMemberProperties() ], ], 'public-modifier-and-type' => [ - '/* testPublicType */', - [ + 'identifier' => '/* testPublicType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'string', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'protected-modifier' => [ - '/* testProtected */', - [ + 'identifier' => '/* testProtected */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, @@ -151,21 +156,21 @@ public static function dataGetMemberProperties() ], ], 'protected-modifier-and-type' => [ - '/* testProtectedType */', - [ + 'identifier' => '/* testProtectedType */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'bool', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'private-modifier' => [ - '/* testPrivate */', - [ + 'identifier' => '/* testPrivate */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -177,21 +182,21 @@ public static function dataGetMemberProperties() ], ], 'private-modifier-and-type' => [ - '/* testPrivateType */', - [ + 'identifier' => '/* testPrivateType */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'array', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'static-modifier' => [ - '/* testStatic */', - [ + 'identifier' => '/* testStatic */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, @@ -203,21 +208,21 @@ public static function dataGetMemberProperties() ], ], 'static-modifier-and-type' => [ - '/* testStaticType */', - [ + 'identifier' => '/* testStaticType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, 'is_readonly' => false, 'type' => '?string', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'static-and-var-modifier' => [ - '/* testStaticVar */', - [ + 'identifier' => '/* testStaticVar */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, @@ -229,8 +234,8 @@ public static function dataGetMemberProperties() ], ], 'var-and-static-modifier' => [ - '/* testVarStatic */', - [ + 'identifier' => '/* testVarStatic */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, @@ -242,8 +247,8 @@ public static function dataGetMemberProperties() ], ], 'public-static-modifiers' => [ - '/* testPublicStatic */', - [ + 'identifier' => '/* testPublicStatic */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, @@ -255,8 +260,8 @@ public static function dataGetMemberProperties() ], ], 'protected-static-modifiers' => [ - '/* testProtectedStatic */', - [ + 'identifier' => '/* testProtectedStatic */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -268,8 +273,8 @@ public static function dataGetMemberProperties() ], ], 'private-static-modifiers' => [ - '/* testPrivateStatic */', - [ + 'identifier' => '/* testPrivateStatic */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, @@ -281,8 +286,8 @@ public static function dataGetMemberProperties() ], ], 'no-modifier' => [ - '/* testNoPrefix */', - [ + 'identifier' => '/* testNoPrefix */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, @@ -294,8 +299,8 @@ public static function dataGetMemberProperties() ], ], 'public-and-static-modifier-with-docblock' => [ - '/* testPublicStaticWithDocblock */', - [ + 'identifier' => '/* testPublicStaticWithDocblock */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, @@ -307,8 +312,8 @@ public static function dataGetMemberProperties() ], ], 'protected-and-static-modifier-with-docblock' => [ - '/* testProtectedStaticWithDocblock */', - [ + 'identifier' => '/* testProtectedStaticWithDocblock */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -320,8 +325,8 @@ public static function dataGetMemberProperties() ], ], 'private-and-static-modifier-with-docblock' => [ - '/* testPrivateStaticWithDocblock */', - [ + 'identifier' => '/* testPrivateStaticWithDocblock */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, @@ -333,60 +338,60 @@ public static function dataGetMemberProperties() ], ], 'property-group-simple-type-prop-1' => [ - '/* testGroupType 1 */', - [ + 'identifier' => '/* testGroupType 1 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'float', - 'type_token' => -6, // Offset from the T_VARIABLE token. - 'type_end_token' => -6, // Offset from the T_VARIABLE token. + 'type_token' => -6, + 'type_end_token' => -6, 'nullable_type' => false, ], ], 'property-group-simple-type-prop-2' => [ - '/* testGroupType 2 */', - [ + 'identifier' => '/* testGroupType 2 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'float', - 'type_token' => -13, // Offset from the T_VARIABLE token. - 'type_end_token' => -13, // Offset from the T_VARIABLE token. + 'type_token' => -13, + 'type_end_token' => -13, 'nullable_type' => false, ], ], 'property-group-nullable-type-prop-1' => [ - '/* testGroupNullableType 1 */', - [ + 'identifier' => '/* testGroupNullableType 1 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, 'is_readonly' => false, 'type' => '?string', - 'type_token' => -6, // Offset from the T_VARIABLE token. - 'type_end_token' => -6, // Offset from the T_VARIABLE token. + 'type_token' => -6, + 'type_end_token' => -6, 'nullable_type' => true, ], ], 'property-group-nullable-type-prop-2' => [ - '/* testGroupNullableType 2 */', - [ + 'identifier' => '/* testGroupNullableType 2 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, 'is_readonly' => false, 'type' => '?string', - 'type_token' => -17, // Offset from the T_VARIABLE token. - 'type_end_token' => -17, // Offset from the T_VARIABLE token. + 'type_token' => -17, + 'type_end_token' => -17, 'nullable_type' => true, ], ], 'property-group-protected-static-prop-1' => [ - '/* testGroupProtectedStatic 1 */', - [ + 'identifier' => '/* testGroupProtectedStatic 1 */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -398,8 +403,8 @@ public static function dataGetMemberProperties() ], ], 'property-group-protected-static-prop-2' => [ - '/* testGroupProtectedStatic 2 */', - [ + 'identifier' => '/* testGroupProtectedStatic 2 */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -411,8 +416,8 @@ public static function dataGetMemberProperties() ], ], 'property-group-protected-static-prop-3' => [ - '/* testGroupProtectedStatic 3 */', - [ + 'identifier' => '/* testGroupProtectedStatic 3 */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -424,8 +429,8 @@ public static function dataGetMemberProperties() ], ], 'property-group-private-prop-1' => [ - '/* testGroupPrivate 1 */', - [ + 'identifier' => '/* testGroupPrivate 1 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -437,8 +442,8 @@ public static function dataGetMemberProperties() ], ], 'property-group-private-prop-2' => [ - '/* testGroupPrivate 2 */', - [ + 'identifier' => '/* testGroupPrivate 2 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -450,8 +455,8 @@ public static function dataGetMemberProperties() ], ], 'property-group-private-prop-3' => [ - '/* testGroupPrivate 3 */', - [ + 'identifier' => '/* testGroupPrivate 3 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -463,8 +468,8 @@ public static function dataGetMemberProperties() ], ], 'property-group-private-prop-4' => [ - '/* testGroupPrivate 4 */', - [ + 'identifier' => '/* testGroupPrivate 4 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -476,8 +481,8 @@ public static function dataGetMemberProperties() ], ], 'property-group-private-prop-5' => [ - '/* testGroupPrivate 5 */', - [ + 'identifier' => '/* testGroupPrivate 5 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -489,8 +494,8 @@ public static function dataGetMemberProperties() ], ], 'property-group-private-prop-6' => [ - '/* testGroupPrivate 6 */', - [ + 'identifier' => '/* testGroupPrivate 6 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -502,8 +507,8 @@ public static function dataGetMemberProperties() ], ], 'property-group-private-prop-7' => [ - '/* testGroupPrivate 7 */', - [ + 'identifier' => '/* testGroupPrivate 7 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -515,73 +520,73 @@ public static function dataGetMemberProperties() ], ], 'messy-nullable-type' => [ - '/* testMessyNullableType */', - [ + 'identifier' => '/* testMessyNullableType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '?array', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'fqn-type' => [ - '/* testNamespaceType */', - [ + 'identifier' => '/* testNamespaceType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '\MyNamespace\MyClass', - 'type_token' => ($php8Names === true) ? -2 : -5, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => ($php8Names === true) ? -2 : -5, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'nullable-classname-type' => [ - '/* testNullableNamespaceType 1 */', - [ + 'identifier' => '/* testNullableNamespaceType 1 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '?ClassName', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'nullable-namespace-relative-class-type' => [ - '/* testNullableNamespaceType 2 */', - [ + 'identifier' => '/* testNullableNamespaceType 2 */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '?Folder\ClassName', - 'type_token' => ($php8Names === true) ? -2 : -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => ($php8Names === true) ? -2 : -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'multiline-namespaced-type' => [ - '/* testMultilineNamespaceType */', - [ + 'identifier' => '/* testMultilineNamespaceType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '\MyNamespace\MyClass\Foo', - 'type_token' => ($php8Names === true) ? -15 : -18, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => ($php8Names === true) ? -15 : -18, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'property-after-method' => [ - '/* testPropertyAfterMethod */', - [ + 'identifier' => '/* testPropertyAfterMethod */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, @@ -593,12 +598,12 @@ public static function dataGetMemberProperties() ], ], 'invalid-property-in-interface' => [ - '/* testInterfaceProperty */', - [], + 'identifier' => '/* testInterfaceProperty */', + 'expected' => [], ], 'property-in-nested-class-1' => [ - '/* testNestedProperty 1 */', - [ + 'identifier' => '/* testNestedProperty 1 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -610,8 +615,8 @@ public static function dataGetMemberProperties() ], ], 'property-in-nested-class-2' => [ - '/* testNestedProperty 2 */', - [ + 'identifier' => '/* testNestedProperty 2 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -623,295 +628,295 @@ public static function dataGetMemberProperties() ], ], 'php8-mixed-type' => [ - '/* testPHP8MixedTypeHint */', - [ + 'identifier' => '/* testPHP8MixedTypeHint */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, 'is_readonly' => false, 'type' => 'miXed', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-nullable-mixed-type' => [ - '/* testPHP8MixedTypeHintNullable */', - [ + 'identifier' => '/* testPHP8MixedTypeHintNullable */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '?mixed', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'namespace-operator-type-declaration' => [ - '/* testNamespaceOperatorTypeHint */', - [ + 'identifier' => '/* testNamespaceOperatorTypeHint */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '?namespace\Name', - 'type_token' => ($php8Names === true) ? -2 : -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => ($php8Names === true) ? -2 : -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'php8-union-types-simple' => [ - '/* testPHP8UnionTypesSimple */', - [ + 'identifier' => '/* testPHP8UnionTypesSimple */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'int|float', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-two-classes' => [ - '/* testPHP8UnionTypesTwoClasses */', - [ + 'identifier' => '/* testPHP8UnionTypesTwoClasses */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'MyClassA|\Package\MyClassB', - 'type_token' => ($php8Names === true) ? -4 : -7, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => ($php8Names === true) ? -4 : -7, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-all-base-types' => [ - '/* testPHP8UnionTypesAllBaseTypes */', - [ + 'identifier' => '/* testPHP8UnionTypesAllBaseTypes */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'array|bool|int|float|NULL|object|string', - 'type_token' => -14, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -14, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-all-pseudo-types' => [ - '/* testPHP8UnionTypesAllPseudoTypes */', - [ + 'identifier' => '/* testPHP8UnionTypesAllPseudoTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, 'is_readonly' => false, 'type' => 'false|mixed|self|parent|iterable|Resource', - 'type_token' => -12, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -12, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-illegal-types' => [ - '/* testPHP8UnionTypesIllegalTypes */', - [ + 'identifier' => '/* testPHP8UnionTypesIllegalTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, // Missing static, but that's OK as not an allowed syntax. 'type' => 'callable|void', - 'type_token' => -6, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -6, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-nullable' => [ - '/* testPHP8UnionTypesNullable */', - [ + 'identifier' => '/* testPHP8UnionTypesNullable */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '?int|float', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'php8-union-types-pseudo-type-null' => [ - '/* testPHP8PseudoTypeNull */', - [ + 'identifier' => '/* testPHP8PseudoTypeNull */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'null', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-pseudo-type-false' => [ - '/* testPHP8PseudoTypeFalse */', - [ + 'identifier' => '/* testPHP8PseudoTypeFalse */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'false', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-pseudo-type-false-and-bool' => [ - '/* testPHP8PseudoTypeFalseAndBool */', - [ + 'identifier' => '/* testPHP8PseudoTypeFalseAndBool */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'bool|FALSE', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-object-and-class' => [ - '/* testPHP8ObjectAndClass */', - [ + 'identifier' => '/* testPHP8ObjectAndClass */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'object|ClassName', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-pseudo-type-iterable-and-array' => [ - '/* testPHP8PseudoTypeIterableAndArray */', - [ + 'identifier' => '/* testPHP8PseudoTypeIterableAndArray */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'iterable|array|Traversable', - 'type_token' => -6, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -6, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-union-types-duplicate-type-with-whitespace-and-comments' => [ - '/* testPHP8DuplicateTypeInUnionWhitespaceAndComment */', - [ + 'identifier' => '/* testPHP8DuplicateTypeInUnionWhitespaceAndComment */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'int|string|INT', - 'type_token' => -10, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -10, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.1-readonly-property' => [ - '/* testPHP81Readonly */', - [ + 'identifier' => '/* testPHP81Readonly */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => true, 'type' => 'int', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.1-readonly-property-with-nullable-type' => [ - '/* testPHP81ReadonlyWithNullableType */', - [ + 'identifier' => '/* testPHP81ReadonlyWithNullableType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => true, 'type' => '?array', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'php8.1-readonly-property-with-union-type' => [ - '/* testPHP81ReadonlyWithUnionType */', - [ + 'identifier' => '/* testPHP81ReadonlyWithUnionType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => true, 'type' => 'string|int', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.1-readonly-property-with-union-type-with-null' => [ - '/* testPHP81ReadonlyWithUnionTypeWithNull */', - [ + 'identifier' => '/* testPHP81ReadonlyWithUnionTypeWithNull */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => true, 'type' => 'string|null', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.1-readonly-property-with-union-type-no-visibility' => [ - '/* testPHP81OnlyReadonlyWithUnionType */', - [ + 'identifier' => '/* testPHP81OnlyReadonlyWithUnionType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, 'is_readonly' => true, 'type' => 'string|int', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.1-readonly-property-with-multi-union-type-no-visibility' => [ - '/* testPHP81OnlyReadonlyWithUnionTypeMultiple */', - [ + 'identifier' => '/* testPHP81OnlyReadonlyWithUnionTypeMultiple */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, 'is_readonly' => true, 'type' => '\InterfaceA|\Sub\InterfaceB|false', - 'type_token' => ($php8Names === true) ? -7 : -11, // Offset from the T_VARIABLE token. - 'type_end_token' => -3, // Offset from the T_VARIABLE token. + 'type_token' => ($php8Names === true) ? -7 : -11, + 'type_end_token' => -3, 'nullable_type' => false, ], ], 'php8.1-readonly-and-static-property' => [ - '/* testPHP81ReadonlyAndStatic */', - [ + 'identifier' => '/* testPHP81ReadonlyAndStatic */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, 'is_readonly' => true, 'type' => '?string', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'php8.1-readonly-mixed-case-keyword' => [ - '/* testPHP81ReadonlyMixedCase */', - [ + 'identifier' => '/* testPHP81ReadonlyMixedCase */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, @@ -923,176 +928,176 @@ public static function dataGetMemberProperties() ], ], 'php8-property-with-single-attribute' => [ - '/* testPHP8PropertySingleAttribute */', - [ + 'identifier' => '/* testPHP8PropertySingleAttribute */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'string', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8-property-with-multiple-attributes' => [ - '/* testPHP8PropertyMultipleAttributes */', - [ + 'identifier' => '/* testPHP8PropertyMultipleAttributes */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '?int|float', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'php8-property-with-multiline-attribute' => [ - '/* testPHP8PropertyMultilineAttribute */', - [ + 'identifier' => '/* testPHP8PropertyMultilineAttribute */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'mixed', - 'type_token' => -2, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'invalid-property-in-enum' => [ - '/* testEnumProperty */', - [], + 'identifier' => '/* testEnumProperty */', + 'expected' => [], ], 'php8.1-single-intersection-type' => [ - '/* testPHP81IntersectionTypes */', - [ + 'identifier' => '/* testPHP81IntersectionTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'Foo&Bar', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.1-multi-intersection-type' => [ - '/* testPHP81MoreIntersectionTypes */', - [ + 'identifier' => '/* testPHP81MoreIntersectionTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'Foo&Bar&Baz', - 'type_token' => -6, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -6, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.1-illegal-intersection-type' => [ - '/* testPHP81IllegalIntersectionTypes */', - [ + 'identifier' => '/* testPHP81IllegalIntersectionTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'int&string', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.1-nullable-intersection-type' => [ - '/* testPHP81NullableIntersectionType */', - [ + 'identifier' => '/* testPHP81NullableIntersectionType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '?Foo&Bar', - 'type_token' => -4, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'php8.0-union-type-with-whitespace-and-comment' => [ - '/* testUnionTypeWithWhitespaceAndComment */', - [ + 'identifier' => '/* testUnionTypeWithWhitespaceAndComment */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => 'int|string', - 'type_token' => -8, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => -8, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.1-intersection-type-with-whitespace-and-comment' => [ - '/* testIntersectionTypeWithWhitespaceAndComment */', - [ + 'identifier' => '/* testIntersectionTypeWithWhitespaceAndComment */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, 'type' => '\Foo&Bar', - 'type_token' => ($php8Names === true) ? -8 : -9, // Offset from the T_VARIABLE token. - 'type_end_token' => -2, // Offset from the T_VARIABLE token. + 'type_token' => ($php8Names === true) ? -8 : -9, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.2-pseudo-type-true' => [ - '/* testPHP82PseudoTypeTrue */', - [ + '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. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.2-pseudo-type-true-nullable' => [ - '/* testPHP82NullablePseudoTypeTrue */', - [ + '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. + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], 'php8.2-pseudo-type-true-in-union' => [ - '/* testPHP82PseudoTypeTrueInUnion */', - [ + '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. + 'type_token' => -6, + 'type_end_token' => -2, 'nullable_type' => false, ], ], 'php8.2-pseudo-type-invalid-true-false-union' => [ - '/* testPHP82PseudoTypeFalseAndTrue */', - [ + '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. + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -1123,18 +1128,18 @@ public function testNotClassPropertyException($identifier) * * @see testNotClassPropertyException() * - * @return array + * @return array> */ public static function dataNotClassProperty() { return [ - ['/* testMethodParam */'], - ['/* testImportedGlobal */'], - ['/* testLocalVariable */'], - ['/* testGlobalVariable */'], - ['/* testNestedMethodParam 1 */'], - ['/* testNestedMethodParam 2 */'], - ['/* testEnumMethodParamNotProperty */'], + 'method parameter' => ['/* testMethodParam */'], + 'variable import using global keyword' => ['/* testImportedGlobal */'], + 'function local variable' => ['/* testLocalVariable */'], + 'global variable' => ['/* testGlobalVariable */'], + 'method parameter in anon class nested in ternary' => ['/* testNestedMethodParam 1 */'], + 'method parameter in anon class nested in function call' => ['/* testNestedMethodParam 2 */'], + 'method parameter in enum' => ['/* testEnumMethodParamNotProperty */'], ]; } diff --git a/Tests/BackCompat/BCFile/GetMethodParametersTest.php b/Tests/BackCompat/BCFile/GetMethodParametersTest.php index 1e94026e..38e5817c 100644 --- a/Tests/BackCompat/BCFile/GetMethodParametersTest.php +++ b/Tests/BackCompat/BCFile/GetMethodParametersTest.php @@ -43,8 +43,8 @@ class GetMethodParametersTest extends UtilityMethodTestCase * * @dataProvider dataUnexpectedTokenException * - * @param string $commentString The comment which preceeds the test. - * @param array $targetTokenType The token type to search for after $commentString. + * @param string $commentString The comment which preceeds the test. + * @param int|string|array $targetTokenType The token type to search for after $commentString. * * @return void */ @@ -61,22 +61,22 @@ public function testUnexpectedTokenException($commentString, $targetTokenType) * * @see testUnexpectedTokenException() For the array format. * - * @return array + * @return array>> */ public static function dataUnexpectedTokenException() { return [ 'interface' => [ - '/* testNotAFunction */', - T_INTERFACE, + 'commentString' => '/* testNotAFunction */', + 'targetTokenType' => T_INTERFACE, ], 'function-call-fn-phpcs-3.5.3-3.5.4' => [ - '/* testFunctionCallFnPHPCS353-354 */', - [T_FN, T_STRING], + 'commentString' => '/* testFunctionCallFnPHPCS353-354 */', + 'targetTokenType' => [T_FN, T_STRING], ], 'fn-live-coding' => [ - '/* testArrowFunctionLiveCoding */', - [T_FN, T_STRING], + 'commentString' => '/* testArrowFunctionLiveCoding */', + 'targetTokenType' => [T_FN, T_STRING], ], ]; } @@ -103,7 +103,7 @@ public function testInvalidUse($identifier) * * @see testInvalidUse() For the array format. * - * @return array + * @return array> */ public static function dataInvalidUse() { @@ -120,13 +120,13 @@ public static function dataInvalidUse() * * @dataProvider dataNoParams * - * @param string $commentString The comment which preceeds the test. - * @param array $targetTokenType Optional. The token type to search for after $commentString. - * Defaults to the function/closure/arrow tokens. + * @param string $commentString The comment which preceeds the test. + * @param int|string|array $targetTokenType Optional. The token type to search for after $commentString. + * Defaults to the function/closure/arrow tokens. * * @return void */ - public function testNoParams($commentString, $targetTokenType = [T_FUNCTION, T_CLOSURE, \T_FN]) + public function testNoParams($commentString, $targetTokenType = [T_FUNCTION, T_CLOSURE, T_FN]) { $target = $this->getTargetToken($commentString, $targetTokenType); $result = BCFile::getMethodParameters(self::$phpcsFile, $target); @@ -139,7 +139,7 @@ public function testNoParams($commentString, $targetTokenType = [T_FUNCTION, T_C * * @see testNoParams() For the array format. * - * @return array + * @return array>> */ public static function dataNoParams() { @@ -157,14 +157,15 @@ public static function dataNoParams() */ public function testPassByReference() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 5, // Offset from the T_FUNCTION token. + 'token' => 5, 'name' => '$var', 'content' => '&$var', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 4, // Offset from the T_FUNCTION token. + 'reference_token' => 4, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '', @@ -184,9 +185,10 @@ public function testPassByReference() */ public function testArrayHint() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 6, // Offset from the T_FUNCTION token. + 'token' => 6, 'name' => '$var', 'content' => 'array $var', 'has_attributes' => false, @@ -195,8 +197,8 @@ public function testArrayHint() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'array', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 4, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 4, 'nullable_type' => false, 'comma_token' => false, ]; @@ -211,9 +213,10 @@ public function testArrayHint() */ public function testVariable() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_FUNCTION token. + 'token' => 4, 'name' => '$var', 'content' => '$var', 'has_attributes' => false, @@ -238,14 +241,15 @@ public function testVariable() */ public function testSingleDefaultValue() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_FUNCTION token. + 'token' => 4, 'name' => '$var1', 'content' => '$var1=self::CONSTANT', 'default' => 'self::CONSTANT', - 'default_token' => 6, // Offset from the T_FUNCTION token. - 'default_equal_token' => 5, // Offset from the T_FUNCTION token. + 'default_token' => 6, + 'default_equal_token' => 5, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -268,14 +272,15 @@ public function testSingleDefaultValue() */ public function testDefaultValues() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_FUNCTION token. + 'token' => 4, 'name' => '$var1', 'content' => '$var1=1', 'default' => '1', - 'default_token' => 6, // Offset from the T_FUNCTION token. - 'default_equal_token' => 5, // Offset from the T_FUNCTION token. + 'default_token' => 6, + 'default_equal_token' => 5, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -285,15 +290,15 @@ public function testDefaultValues() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 7, // Offset from the T_FUNCTION token. + 'comma_token' => 7, ]; $expected[1] = [ - 'token' => 9, // Offset from the T_FUNCTION token. + 'token' => 9, 'name' => '$var2', 'content' => "\$var2='value'", 'default' => "'value'", - 'default_token' => 11, // Offset from the T_FUNCTION token. - 'default_equal_token' => 10, // Offset from the T_FUNCTION token. + 'default_token' => 11, + 'default_equal_token' => 10, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -316,9 +321,10 @@ public function testDefaultValues() */ public function testTypeHint() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 6, // Offset from the T_FUNCTION token. + 'token' => 6, 'name' => '$var1', 'content' => 'foo $var1', 'has_attributes' => false, @@ -327,14 +333,14 @@ public function testTypeHint() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'foo', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 4, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 4, 'nullable_type' => false, - 'comma_token' => 7, // Offset from the T_FUNCTION token. + 'comma_token' => 7, ]; $expected[1] = [ - 'token' => 11, // Offset from the T_FUNCTION token. + 'token' => 11, 'name' => '$var2', 'content' => 'bar $var2', 'has_attributes' => false, @@ -343,8 +349,8 @@ public function testTypeHint() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'bar', - 'type_hint_token' => 9, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 9, // Offset from the T_FUNCTION token. + 'type_hint_token' => 9, + 'type_hint_end_token' => 9, 'nullable_type' => false, 'comma_token' => false, ]; @@ -359,9 +365,10 @@ public function testTypeHint() */ public function testSelfTypeHint() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 6, // Offset from the T_FUNCTION token. + 'token' => 6, 'name' => '$var', 'content' => 'self $var', 'has_attributes' => false, @@ -370,8 +377,8 @@ public function testSelfTypeHint() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'self', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 4, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 4, 'nullable_type' => false, 'comma_token' => false, ]; @@ -388,9 +395,10 @@ public function testNullableTypeHint() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 7, // Offset from the T_FUNCTION token. + 'token' => 7, 'name' => '$var1', 'content' => '?int $var1', 'has_attributes' => false, @@ -399,14 +407,14 @@ public function testNullableTypeHint() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?int', - 'type_hint_token' => 5, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 5, // Offset from the T_FUNCTION token. + 'type_hint_token' => 5, + 'type_hint_end_token' => 5, 'nullable_type' => true, - 'comma_token' => 8, // Offset from the T_FUNCTION token. + 'comma_token' => 8, ]; $expected[1] = [ - 'token' => ($php8Names === true) ? 13 : 14, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 13 : 14, 'name' => '$var2', 'content' => '?\bar $var2', 'has_attributes' => false, @@ -415,8 +423,8 @@ public function testNullableTypeHint() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?\bar', - 'type_hint_token' => 11, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 11 : 12, // Offset from the T_FUNCTION token. + 'type_hint_token' => 11, + 'type_hint_end_token' => ($php8Names === true) ? 11 : 12, 'nullable_type' => true, 'comma_token' => false, ]; @@ -431,14 +439,15 @@ public function testNullableTypeHint() */ public function testBitwiseAndConstantExpressionDefaultValue() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_FUNCTION token. + 'token' => 4, 'name' => '$a', 'content' => '$a = 10 & 20', 'default' => '10 & 20', - 'default_token' => 8, // Offset from the T_FUNCTION token. - 'default_equal_token' => 6, // Offset from the T_FUNCTION token. + 'default_token' => 8, + 'default_equal_token' => 6, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -461,9 +470,10 @@ public function testBitwiseAndConstantExpressionDefaultValue() */ public function testArrowFunction() { + // Offsets are relative to the T_FN token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_FN token. + 'token' => 4, 'name' => '$a', 'content' => 'int $a', 'has_attributes' => false, @@ -472,21 +482,21 @@ public function testArrowFunction() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'int', - 'type_hint_token' => 2, // Offset from the T_FN token. - 'type_hint_end_token' => 2, // Offset from the T_FN token. + 'type_hint_token' => 2, + 'type_hint_end_token' => 2, 'nullable_type' => false, - 'comma_token' => 5, // Offset from the T_FN token. + 'comma_token' => 5, ]; $expected[1] = [ - 'token' => 8, // Offset from the T_FN token. + 'token' => 8, 'name' => '$b', 'content' => '...$b', 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => true, - 'variadic_token' => 7, // Offset from the T_FN token. + 'variadic_token' => 7, 'type_hint' => '', 'type_hint_token' => false, 'type_hint_end_token' => false, @@ -504,9 +514,10 @@ public function testArrowFunction() */ public function testArrowFunctionReturnByRef() { + // Offsets are relative to the T_FN token. $expected = []; $expected[0] = [ - 'token' => 6, // Offset from the T_FN token. + 'token' => 6, 'name' => '$a', 'content' => '?string $a', 'has_attributes' => false, @@ -515,8 +526,8 @@ public function testArrowFunctionReturnByRef() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?string', - 'type_hint_token' => 4, // Offset from the T_FN token. - 'type_hint_end_token' => 4, // Offset from the T_FN token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 4, 'nullable_type' => true, 'comma_token' => false, ]; @@ -531,14 +542,15 @@ public function testArrowFunctionReturnByRef() */ public function testArrayDefaultValues() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_FUNCTION token. + 'token' => 4, 'name' => '$var1', 'content' => '$var1 = []', 'default' => '[]', - 'default_token' => 8, // Offset from the T_FUNCTION token. - 'default_equal_token' => 6, // Offset from the T_FUNCTION token. + 'default_token' => 8, + 'default_equal_token' => 6, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -548,15 +560,15 @@ public function testArrayDefaultValues() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 10, // Offset from the T_FUNCTION token. + 'comma_token' => 10, ]; $expected[1] = [ - 'token' => 12, // Offset from the T_FUNCTION token. + 'token' => 12, 'name' => '$var2', 'content' => '$var2 = array(1, 2, 3)', 'default' => 'array(1, 2, 3)', - 'default_token' => 16, // Offset from the T_FUNCTION token. - 'default_equal_token' => 14, // Offset from the T_FUNCTION token. + 'default_token' => 16, + 'default_equal_token' => 14, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -579,9 +591,10 @@ public function testArrayDefaultValues() */ public function testConstantDefaultValueSecondParam() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_FUNCTION token. + 'token' => 4, 'name' => '$var1', 'content' => '$var1', 'has_attributes' => false, @@ -593,15 +606,15 @@ public function testConstantDefaultValueSecondParam() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 5, // Offset from the T_FUNCTION token. + 'comma_token' => 5, ]; $expected[1] = [ - 'token' => 7, // Offset from the T_FUNCTION token. + 'token' => 7, 'name' => '$var2', 'content' => '$var2 = M_PI', 'default' => 'M_PI', - 'default_token' => 11, // Offset from the T_FUNCTION token. - 'default_equal_token' => 9, // Offset from the T_FUNCTION token. + 'default_token' => 11, + 'default_equal_token' => 9, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -624,14 +637,15 @@ public function testConstantDefaultValueSecondParam() */ public function testScalarTernaryExpressionInDefault() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 5, // Offset from the T_FUNCTION token. + 'token' => 5, 'name' => '$a', 'content' => '$a = FOO ? \'bar\' : 10', 'default' => 'FOO ? \'bar\' : 10', - 'default_token' => 9, // Offset from the T_FUNCTION token. - 'default_equal_token' => 7, // Offset from the T_FUNCTION token. + 'default_token' => 9, + 'default_equal_token' => 7, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -641,10 +655,10 @@ public function testScalarTernaryExpressionInDefault() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 18, // Offset from the T_FUNCTION token. + 'comma_token' => 18, ]; $expected[1] = [ - 'token' => 24, // Offset from the T_FUNCTION token. + 'token' => 24, 'name' => '$b', 'content' => '? bool $b', 'has_attributes' => false, @@ -653,8 +667,8 @@ public function testScalarTernaryExpressionInDefault() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?bool', - 'type_hint_token' => 22, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 22, // Offset from the T_FUNCTION token. + 'type_hint_token' => 22, + 'type_hint_end_token' => 22, 'nullable_type' => true, 'comma_token' => false, ]; @@ -669,19 +683,20 @@ public function testScalarTernaryExpressionInDefault() */ public function testVariadicFunction() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 9, // Offset from the T_FUNCTION token. + 'token' => 9, 'name' => '$a', 'content' => 'int ... $a', 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => true, - 'variadic_token' => 7, // Offset from the T_FUNCTION token. + 'variadic_token' => 7, 'type_hint' => 'int', - 'type_hint_token' => 5, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 5, // Offset from the T_FUNCTION token. + 'type_hint_token' => 5, + 'type_hint_end_token' => 5, 'nullable_type' => false, 'comma_token' => false, ]; @@ -696,16 +711,17 @@ public function testVariadicFunction() */ public function testVariadicByRefFunction() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 7, // Offset from the T_FUNCTION token. + 'token' => 7, 'name' => '$a', 'content' => '&...$a', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 5, // Offset from the T_FUNCTION token. + 'reference_token' => 5, 'variable_length' => true, - 'variadic_token' => 6, // Offset from the T_FUNCTION token. + 'variadic_token' => 6, 'type_hint' => '', 'type_hint_token' => false, 'type_hint_end_token' => false, @@ -723,9 +739,10 @@ public function testVariadicByRefFunction() */ public function testVariadicFunctionClassType() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_FUNCTION token. + 'token' => 4, 'name' => '$unit', 'content' => '$unit', 'has_attributes' => false, @@ -737,10 +754,10 @@ public function testVariadicFunctionClassType() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 5, // Offset from the T_FUNCTION token. + 'comma_token' => 5, ]; $expected[1] = [ - 'token' => 10, // Offset from the T_FUNCTION token. + 'token' => 10, 'name' => '$intervals', 'content' => 'DateInterval ...$intervals', 'has_attributes' => false, @@ -749,8 +766,8 @@ public function testVariadicFunctionClassType() 'variable_length' => true, 'variadic_token' => 9, 'type_hint' => 'DateInterval', - 'type_hint_token' => 7, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 7, // Offset from the T_FUNCTION token. + 'type_hint_token' => 7, + 'type_hint_end_token' => 7, 'nullable_type' => false, 'comma_token' => false, ]; @@ -767,9 +784,10 @@ public function testNameSpacedTypeDeclaration() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => ($php8Names === true) ? 7 : 12, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 7 : 12, 'name' => '$a', 'content' => '\Package\Sub\ClassName $a', 'has_attributes' => false, @@ -778,13 +796,13 @@ public function testNameSpacedTypeDeclaration() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '\Package\Sub\ClassName', - 'type_hint_token' => 5, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 5 : 10, // Offset from the T_FUNCTION token. + 'type_hint_token' => 5, + 'type_hint_end_token' => ($php8Names === true) ? 5 : 10, 'nullable_type' => false, - 'comma_token' => ($php8Names === true) ? 8 : 13, // Offset from the T_FUNCTION token. + 'comma_token' => ($php8Names === true) ? 8 : 13, ]; $expected[1] = [ - 'token' => ($php8Names === true) ? 13 : 20, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 13 : 20, 'name' => '$b', 'content' => '?Sub\AnotherClass $b', 'has_attributes' => false, @@ -793,8 +811,8 @@ public function testNameSpacedTypeDeclaration() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?Sub\AnotherClass', - 'type_hint_token' => ($php8Names === true) ? 11 : 16, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 11 : 18, // Offset from the T_FUNCTION token. + 'type_hint_token' => ($php8Names === true) ? 11 : 16, + 'type_hint_end_token' => ($php8Names === true) ? 11 : 18, 'nullable_type' => true, 'comma_token' => false, ]; @@ -809,9 +827,10 @@ public function testNameSpacedTypeDeclaration() */ public function testWithAllTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 9, // Offset from the T_FUNCTION token. + 'token' => 9, 'name' => '$a', 'content' => '?ClassName $a', 'has_attributes' => false, @@ -820,13 +839,13 @@ public function testWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?ClassName', - 'type_hint_token' => 7, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 7, // Offset from the T_FUNCTION token. + 'type_hint_token' => 7, + 'type_hint_end_token' => 7, 'nullable_type' => true, - 'comma_token' => 10, // Offset from the T_FUNCTION token. + 'comma_token' => 10, ]; $expected[1] = [ - 'token' => 15, // Offset from the T_FUNCTION token. + 'token' => 15, 'name' => '$b', 'content' => 'self $b', 'has_attributes' => false, @@ -835,13 +854,13 @@ public function testWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'self', - 'type_hint_token' => 13, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 13, // Offset from the T_FUNCTION token. + 'type_hint_token' => 13, + 'type_hint_end_token' => 13, 'nullable_type' => false, - 'comma_token' => 16, // Offset from the T_FUNCTION token. + 'comma_token' => 16, ]; $expected[2] = [ - 'token' => 21, // Offset from the T_FUNCTION token. + 'token' => 21, 'name' => '$c', 'content' => 'parent $c', 'has_attributes' => false, @@ -850,13 +869,13 @@ public function testWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'parent', - 'type_hint_token' => 19, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 19, // Offset from the T_FUNCTION token. + 'type_hint_token' => 19, + 'type_hint_end_token' => 19, 'nullable_type' => false, - 'comma_token' => 22, // Offset from the T_FUNCTION token. + 'comma_token' => 22, ]; $expected[3] = [ - 'token' => 27, // Offset from the T_FUNCTION token. + 'token' => 27, 'name' => '$d', 'content' => 'object $d', 'has_attributes' => false, @@ -865,13 +884,13 @@ public function testWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'object', - 'type_hint_token' => 25, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 25, // Offset from the T_FUNCTION token. + 'type_hint_token' => 25, + 'type_hint_end_token' => 25, 'nullable_type' => false, - 'comma_token' => 28, // Offset from the T_FUNCTION token. + 'comma_token' => 28, ]; $expected[4] = [ - 'token' => 34, // Offset from the T_FUNCTION token. + 'token' => 34, 'name' => '$e', 'content' => '?int $e', 'has_attributes' => false, @@ -880,28 +899,28 @@ public function testWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?int', - 'type_hint_token' => 32, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 32, // Offset from the T_FUNCTION token. + 'type_hint_token' => 32, + 'type_hint_end_token' => 32, 'nullable_type' => true, - 'comma_token' => 35, // Offset from the T_FUNCTION token. + 'comma_token' => 35, ]; $expected[5] = [ - 'token' => 41, // Offset from the T_FUNCTION token. + 'token' => 41, 'name' => '$f', 'content' => 'string &$f', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 40, // Offset from the T_FUNCTION token. + 'reference_token' => 40, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'string', - 'type_hint_token' => 38, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 38, // Offset from the T_FUNCTION token. + 'type_hint_token' => 38, + 'type_hint_end_token' => 38, 'nullable_type' => false, - 'comma_token' => 42, // Offset from the T_FUNCTION token. + 'comma_token' => 42, ]; $expected[6] = [ - 'token' => 47, // Offset from the T_FUNCTION token. + 'token' => 47, 'name' => '$g', 'content' => 'iterable $g', 'has_attributes' => false, @@ -910,77 +929,77 @@ public function testWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'iterable', - 'type_hint_token' => 45, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 45, // Offset from the T_FUNCTION token. + 'type_hint_token' => 45, + 'type_hint_end_token' => 45, 'nullable_type' => false, - 'comma_token' => 48, // Offset from the T_FUNCTION token. + 'comma_token' => 48, ]; $expected[7] = [ - 'token' => 53, // Offset from the T_FUNCTION token. + 'token' => 53, 'name' => '$h', 'content' => 'bool $h = true', 'default' => 'true', - 'default_token' => 57, // Offset from the T_FUNCTION token. - 'default_equal_token' => 55, // Offset from the T_FUNCTION token. + 'default_token' => 57, + 'default_equal_token' => 55, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'bool', - 'type_hint_token' => 51, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 51, // Offset from the T_FUNCTION token. + 'type_hint_token' => 51, + 'type_hint_end_token' => 51, 'nullable_type' => false, - 'comma_token' => 58, // Offset from the T_FUNCTION token. + 'comma_token' => 58, ]; $expected[8] = [ - 'token' => 63, // Offset from the T_FUNCTION token. + 'token' => 63, 'name' => '$i', 'content' => 'callable $i = \'is_null\'', 'default' => "'is_null'", - 'default_token' => 67, // Offset from the T_FUNCTION token. - 'default_equal_token' => 65, // Offset from the T_FUNCTION token. + 'default_token' => 67, + 'default_equal_token' => 65, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'callable', - 'type_hint_token' => 61, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 61, // Offset from the T_FUNCTION token. + 'type_hint_token' => 61, + 'type_hint_end_token' => 61, 'nullable_type' => false, - 'comma_token' => 68, // Offset from the T_FUNCTION token. + 'comma_token' => 68, ]; $expected[9] = [ - 'token' => 73, // Offset from the T_FUNCTION token. + 'token' => 73, 'name' => '$j', 'content' => 'float $j = 1.1', 'default' => '1.1', - 'default_token' => 77, // Offset from the T_FUNCTION token. - 'default_equal_token' => 75, // Offset from the T_FUNCTION token. + 'default_token' => 77, + 'default_equal_token' => 75, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'float', - 'type_hint_token' => 71, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 71, // Offset from the T_FUNCTION token. + 'type_hint_token' => 71, + 'type_hint_end_token' => 71, 'nullable_type' => false, - 'comma_token' => 78, // Offset from the T_FUNCTION token. + 'comma_token' => 78, ]; $expected[10] = [ - 'token' => 84, // Offset from the T_FUNCTION token. + 'token' => 84, 'name' => '$k', 'content' => 'array ...$k', 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => true, - 'variadic_token' => 83, // Offset from the T_FUNCTION token. + 'variadic_token' => 83, 'type_hint' => 'array', - 'type_hint_token' => 81, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 81, // Offset from the T_FUNCTION token. + 'type_hint_token' => 81, + 'type_hint_end_token' => 81, 'nullable_type' => false, 'comma_token' => false, ]; @@ -995,9 +1014,10 @@ public function testWithAllTypes() */ public function testArrowFunctionWithAllTypes() { + // Offsets are relative to the T_FN token. $expected = []; $expected[0] = [ - 'token' => 7, // Offset from the T_FN token. + 'token' => 7, 'name' => '$a', 'content' => '?ClassName $a', 'has_attributes' => false, @@ -1006,13 +1026,13 @@ public function testArrowFunctionWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?ClassName', - 'type_hint_token' => 5, // Offset from the T_FN token. - 'type_hint_end_token' => 5, // Offset from the T_FN token. + 'type_hint_token' => 5, + 'type_hint_end_token' => 5, 'nullable_type' => true, - 'comma_token' => 8, // Offset from the T_FN token. + 'comma_token' => 8, ]; $expected[1] = [ - 'token' => 13, // Offset from the T_FN token. + 'token' => 13, 'name' => '$b', 'content' => 'self $b', 'has_attributes' => false, @@ -1021,13 +1041,13 @@ public function testArrowFunctionWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'self', - 'type_hint_token' => 11, // Offset from the T_FN token. - 'type_hint_end_token' => 11, // Offset from the T_FN token. + 'type_hint_token' => 11, + 'type_hint_end_token' => 11, 'nullable_type' => false, - 'comma_token' => 14, // Offset from the T_FN token. + 'comma_token' => 14, ]; $expected[2] = [ - 'token' => 19, // Offset from the T_FN token. + 'token' => 19, 'name' => '$c', 'content' => 'parent $c', 'has_attributes' => false, @@ -1036,13 +1056,13 @@ public function testArrowFunctionWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'parent', - 'type_hint_token' => 17, // Offset from the T_FN token. - 'type_hint_end_token' => 17, // Offset from the T_FN token. + 'type_hint_token' => 17, + 'type_hint_end_token' => 17, 'nullable_type' => false, - 'comma_token' => 20, // Offset from the T_FN token. + 'comma_token' => 20, ]; $expected[3] = [ - 'token' => 25, // Offset from the T_FN token. + 'token' => 25, 'name' => '$d', 'content' => 'object $d', 'has_attributes' => false, @@ -1051,13 +1071,13 @@ public function testArrowFunctionWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'object', - 'type_hint_token' => 23, // Offset from the T_FN token. - 'type_hint_end_token' => 23, // Offset from the T_FN token. + 'type_hint_token' => 23, + 'type_hint_end_token' => 23, 'nullable_type' => false, - 'comma_token' => 26, // Offset from the T_FN token. + 'comma_token' => 26, ]; $expected[4] = [ - 'token' => 32, // Offset from the T_FN token. + 'token' => 32, 'name' => '$e', 'content' => '?int $e', 'has_attributes' => false, @@ -1066,28 +1086,28 @@ public function testArrowFunctionWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?int', - 'type_hint_token' => 30, // Offset from the T_FN token. - 'type_hint_end_token' => 30, // Offset from the T_FN token. + 'type_hint_token' => 30, + 'type_hint_end_token' => 30, 'nullable_type' => true, - 'comma_token' => 33, // Offset from the T_FN token. + 'comma_token' => 33, ]; $expected[5] = [ - 'token' => 39, // Offset from the T_FN token. + 'token' => 39, 'name' => '$f', 'content' => 'string &$f', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 38, // Offset from the T_FN token. + 'reference_token' => 38, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'string', - 'type_hint_token' => 36, // Offset from the T_FN token. - 'type_hint_end_token' => 36, // Offset from the T_FN token. + 'type_hint_token' => 36, + 'type_hint_end_token' => 36, 'nullable_type' => false, - 'comma_token' => 40, // Offset from the T_FN token. + 'comma_token' => 40, ]; $expected[6] = [ - 'token' => 45, // Offset from the T_FN token. + 'token' => 45, 'name' => '$g', 'content' => 'iterable $g', 'has_attributes' => false, @@ -1096,77 +1116,77 @@ public function testArrowFunctionWithAllTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'iterable', - 'type_hint_token' => 43, // Offset from the T_FN token. - 'type_hint_end_token' => 43, // Offset from the T_FN token. + 'type_hint_token' => 43, + 'type_hint_end_token' => 43, 'nullable_type' => false, - 'comma_token' => 46, // Offset from the T_FN token. + 'comma_token' => 46, ]; $expected[7] = [ - 'token' => 51, // Offset from the T_FN token. + 'token' => 51, 'name' => '$h', 'content' => 'bool $h = true', 'default' => 'true', - 'default_token' => 55, // Offset from the T_FN token. - 'default_equal_token' => 53, // Offset from the T_FN token. + 'default_token' => 55, + 'default_equal_token' => 53, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'bool', - 'type_hint_token' => 49, // Offset from the T_FN token. - 'type_hint_end_token' => 49, // Offset from the T_FN token. + 'type_hint_token' => 49, + 'type_hint_end_token' => 49, 'nullable_type' => false, - 'comma_token' => 56, // Offset from the T_FN token. + 'comma_token' => 56, ]; $expected[8] = [ - 'token' => 61, // Offset from the T_FN token. + 'token' => 61, 'name' => '$i', 'content' => 'callable $i = \'is_null\'', 'default' => "'is_null'", - 'default_token' => 65, // Offset from the T_FN token. - 'default_equal_token' => 63, // Offset from the T_FN token. + 'default_token' => 65, + 'default_equal_token' => 63, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'callable', - 'type_hint_token' => 59, // Offset from the T_FN token. - 'type_hint_end_token' => 59, // Offset from the T_FN token. + 'type_hint_token' => 59, + 'type_hint_end_token' => 59, 'nullable_type' => false, - 'comma_token' => 66, // Offset from the T_FN token. + 'comma_token' => 66, ]; $expected[9] = [ - 'token' => 71, // Offset from the T_FN token. + 'token' => 71, 'name' => '$j', 'content' => 'float $j = 1.1', 'default' => '1.1', - 'default_token' => 75, // Offset from the T_FN token. - 'default_equal_token' => 73, // Offset from the T_FN token. + 'default_token' => 75, + 'default_equal_token' => 73, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'float', - 'type_hint_token' => 69, // Offset from the T_FN token. - 'type_hint_end_token' => 69, // Offset from the T_FN token. + 'type_hint_token' => 69, + 'type_hint_end_token' => 69, 'nullable_type' => false, - 'comma_token' => 76, // Offset from the T_FN token. + 'comma_token' => 76, ]; $expected[10] = [ - 'token' => 82, // Offset from the T_FN token. + 'token' => 82, 'name' => '$k', 'content' => 'array ...$k', 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => true, - 'variadic_token' => 81, // Offset from the T_FN token. + 'variadic_token' => 81, 'type_hint' => 'array', - 'type_hint_token' => 79, // Offset from the T_FN token. - 'type_hint_end_token' => 79, // Offset from the T_FN token. + 'type_hint_token' => 79, + 'type_hint_end_token' => 79, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1183,9 +1203,10 @@ public function testMessyDeclaration() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => ($php8Names === true) ? 24 : 25, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 24 : 25, 'name' => '$a', 'content' => '// comment ?\MyNS /* comment */ @@ -1200,15 +1221,15 @@ public function testMessyDeclaration() 'type_hint_token' => 9, 'type_hint_end_token' => ($php8Names === true) ? 22 : 23, 'nullable_type' => true, - 'comma_token' => ($php8Names === true) ? 25 : 26, // Offset from the T_FUNCTION token. + 'comma_token' => ($php8Names === true) ? 25 : 26, ]; $expected[1] = [ - 'token' => ($php8Names === true) ? 28 : 29, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 28 : 29, 'name' => '$b', 'content' => "\$b /* test */ = /* test */ 'default' /* test*/", 'default' => "'default' /* test*/", - 'default_token' => ($php8Names === true) ? 36 : 37, // Offset from the T_FUNCTION token. - 'default_equal_token' => ($php8Names === true) ? 32 : 33, // Offset from the T_FUNCTION token. + 'default_token' => ($php8Names === true) ? 36 : 37, + 'default_equal_token' => ($php8Names === true) ? 32 : 33, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -1218,10 +1239,10 @@ public function testMessyDeclaration() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => ($php8Names === true) ? 39 : 40, // Offset from the T_FUNCTION token. + 'comma_token' => ($php8Names === true) ? 39 : 40, ]; $expected[2] = [ - 'token' => ($php8Names === true) ? 61 : 62, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 61 : 62, 'name' => '$c', 'content' => '// phpcs:ignore Stnd.Cat.Sniff -- For reasons. ? /*comment*/ @@ -1229,12 +1250,12 @@ public function testMessyDeclaration() & /*test*/ ... /* phpcs:ignore */ $c', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => ($php8Names === true) ? 53 : 54, // Offset from the T_FUNCTION token. + 'reference_token' => ($php8Names === true) ? 53 : 54, 'variable_length' => true, - 'variadic_token' => ($php8Names === true) ? 57 : 58, // Offset from the T_FUNCTION token. + 'variadic_token' => ($php8Names === true) ? 57 : 58, 'type_hint' => '?bool', - 'type_hint_token' => ($php8Names === true) ? 49 : 50, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 49 : 50, // Offset from the T_FUNCTION token. + 'type_hint_token' => ($php8Names === true) ? 49 : 50, + 'type_hint_end_token' => ($php8Names === true) ? 49 : 50, 'nullable_type' => true, 'comma_token' => false, ]; @@ -1249,19 +1270,20 @@ public function testMessyDeclaration() */ public function testPHP8MixedTypeHint() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$var1', 'content' => 'mixed &...$var1', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 6, // Offset from the T_FUNCTION token. + 'reference_token' => 6, 'variable_length' => true, - 'variadic_token' => 7, // Offset from the T_FUNCTION token. + 'variadic_token' => 7, 'type_hint' => 'mixed', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 4, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 4, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1276,9 +1298,10 @@ public function testPHP8MixedTypeHint() */ public function testPHP8MixedTypeHintNullable() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 7, // Offset from the T_FUNCTION token. + 'token' => 7, 'name' => '$var1', 'content' => '?Mixed $var1', 'has_attributes' => false, @@ -1287,8 +1310,8 @@ public function testPHP8MixedTypeHintNullable() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?Mixed', - 'type_hint_token' => 5, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 5, // Offset from the T_FUNCTION token. + 'type_hint_token' => 5, + 'type_hint_end_token' => 5, 'nullable_type' => true, 'comma_token' => false, ]; @@ -1305,9 +1328,10 @@ public function testNamespaceOperatorTypeHint() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => ($php8Names === true) ? 7 : 9, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 7 : 9, 'name' => '$var1', 'content' => '?namespace\Name $var1', 'has_attributes' => false, @@ -1316,8 +1340,8 @@ public function testNamespaceOperatorTypeHint() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?namespace\Name', - 'type_hint_token' => 5, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 5 : 7, // Offset from the T_FUNCTION token. + 'type_hint_token' => 5, + 'type_hint_end_token' => ($php8Names === true) ? 5 : 7, 'nullable_type' => true, 'comma_token' => false, ]; @@ -1332,9 +1356,10 @@ public function testNamespaceOperatorTypeHint() */ public function testPHP8UnionTypesSimple() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$number', 'content' => 'int|float $number', 'has_attributes' => false, @@ -1343,23 +1368,23 @@ public function testPHP8UnionTypesSimple() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'int|float', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'comma_token' => 9, ]; $expected[1] = [ - 'token' => 17, // Offset from the T_FUNCTION token. + 'token' => 17, 'name' => '$obj', 'content' => 'self|parent &...$obj', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 15, // Offset from the T_FUNCTION token. + 'reference_token' => 15, 'variable_length' => true, 'variadic_token' => 16, 'type_hint' => 'self|parent', - 'type_hint_token' => 11, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 13, // Offset from the T_FUNCTION token. + 'type_hint_token' => 11, + 'type_hint_end_token' => 13, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1374,34 +1399,35 @@ public function testPHP8UnionTypesSimple() */ public function testPHP8UnionTypesWithSpreadOperatorAndReference() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 9, // Offset from the T_FUNCTION token. + 'token' => 9, 'name' => '$paramA', 'content' => 'float|null &$paramA', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 8, // Offset from the T_FUNCTION token. + 'reference_token' => 8, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'float|null', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'comma_token' => 10, ]; $expected[1] = [ - 'token' => 17, // Offset from the T_FUNCTION token. + 'token' => 17, 'name' => '$paramB', 'content' => 'string|int ...$paramB', 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => true, - 'variadic_token' => 16, // Offset from the T_FUNCTION token. + 'variadic_token' => 16, 'type_hint' => 'string|int', - 'type_hint_token' => 12, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 14, // Offset from the T_FUNCTION token. + 'type_hint_token' => 12, + 'type_hint_end_token' => 14, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1416,22 +1442,23 @@ public function testPHP8UnionTypesWithSpreadOperatorAndReference() */ public function testPHP8UnionTypesSimpleWithBitwiseOrInDefault() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 6, // Offset from the T_FUNCTION token. + 'token' => 6, 'name' => '$var', 'content' => 'int|float $var = CONSTANT_A | CONSTANT_B', 'default' => 'CONSTANT_A | CONSTANT_B', - 'default_token' => 10, // Offset from the T_FUNCTION token. - 'default_equal_token' => 8, // Offset from the T_FUNCTION token. + 'default_token' => 10, + 'default_equal_token' => 8, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'int|float', - 'type_hint_token' => 2, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 4, // Offset from the T_FUNCTION token. + 'type_hint_token' => 2, + 'type_hint_end_token' => 4, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1448,9 +1475,10 @@ public function testPHP8UnionTypesTwoClasses() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => ($php8Names === true) ? 8 : 11, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 8 : 11, 'name' => '$var', 'content' => 'MyClassA|\Package\MyClassB $var', 'has_attributes' => false, @@ -1459,8 +1487,8 @@ public function testPHP8UnionTypesTwoClasses() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'MyClassA|\Package\MyClassB', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 6 : 9, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => ($php8Names === true) ? 6 : 9, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1475,9 +1503,10 @@ public function testPHP8UnionTypesTwoClasses() */ public function testPHP8UnionTypesAllBaseTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 20, // Offset from the T_FUNCTION token. + 'token' => 20, 'name' => '$var', 'content' => 'array|bool|callable|int|float|null|object|string $var', 'has_attributes' => false, @@ -1486,8 +1515,8 @@ public function testPHP8UnionTypesAllBaseTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'array|bool|callable|int|float|null|object|string', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 18, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 18, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1504,9 +1533,10 @@ public function testPHP8UnionTypesAllBaseTypes() */ public function testPHP8UnionTypesAllPseudoTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 16, // Offset from the T_FUNCTION token. + 'token' => 16, 'name' => '$var', 'content' => 'false|mixed|self|parent|iterable|Resource $var', 'has_attributes' => false, @@ -1515,8 +1545,8 @@ public function testPHP8UnionTypesAllPseudoTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'false|mixed|self|parent|iterable|Resource', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 14, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 14, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1531,9 +1561,10 @@ public function testPHP8UnionTypesAllPseudoTypes() */ public function testPHP8UnionTypesNullable() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$number', 'content' => '?int|float $number', 'has_attributes' => false, @@ -1542,8 +1573,8 @@ public function testPHP8UnionTypesNullable() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?int|float', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 6, 'nullable_type' => true, 'comma_token' => false, ]; @@ -1558,22 +1589,23 @@ public function testPHP8UnionTypesNullable() */ public function testPHP8PseudoTypeNull() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 6, // Offset from the T_FUNCTION token. + 'token' => 6, 'name' => '$var', 'content' => 'null $var = null', 'default' => 'null', - 'default_token' => 10, // Offset from the T_FUNCTION token. - 'default_equal_token' => 8, // Offset from the T_FUNCTION token. + 'default_token' => 10, + 'default_equal_token' => 8, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'null', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 4, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 4, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1588,22 +1620,23 @@ public function testPHP8PseudoTypeNull() */ public function testPHP8PseudoTypeFalse() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 6, // Offset from the T_FUNCTION token. + 'token' => 6, 'name' => '$var', 'content' => 'false $var = false', 'default' => 'false', - 'default_token' => 10, // Offset from the T_FUNCTION token. - 'default_equal_token' => 8, // Offset from the T_FUNCTION token. + 'default_token' => 10, + 'default_equal_token' => 8, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'false', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 4, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 4, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1618,22 +1651,23 @@ public function testPHP8PseudoTypeFalse() */ public function testPHP8PseudoTypeFalseAndBool() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$var', 'content' => 'bool|false $var = false', 'default' => 'false', - 'default_token' => 12, // Offset from the T_FUNCTION token. - 'default_equal_token' => 10, // Offset from the T_FUNCTION token. + 'default_token' => 12, + 'default_equal_token' => 10, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'bool|false', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1648,9 +1682,10 @@ public function testPHP8PseudoTypeFalseAndBool() */ public function testPHP8ObjectAndClass() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$var', 'content' => 'object|ClassName $var', 'has_attributes' => false, @@ -1659,8 +1694,8 @@ public function testPHP8ObjectAndClass() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'object|ClassName', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1675,9 +1710,10 @@ public function testPHP8ObjectAndClass() */ public function testPHP8PseudoTypeIterableAndArray() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 10, // Offset from the T_FUNCTION token. + 'token' => 10, 'name' => '$var', 'content' => 'iterable|array|Traversable $var', 'has_attributes' => false, @@ -1686,8 +1722,8 @@ public function testPHP8PseudoTypeIterableAndArray() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'iterable|array|Traversable', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 8, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 8, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1702,9 +1738,10 @@ public function testPHP8PseudoTypeIterableAndArray() */ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 17, // Offset from the T_FUNCTION token. + 'token' => 17, 'name' => '$var', 'content' => 'int | string /*comment*/ | INT $var', 'has_attributes' => false, @@ -1713,8 +1750,8 @@ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'int|string|INT', - 'type_hint_token' => 5, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 15, // Offset from the T_FUNCTION token. + 'type_hint_token' => 5, + 'type_hint_end_token' => 15, 'nullable_type' => false, 'comma_token' => false, ]; @@ -1729,14 +1766,15 @@ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment() */ public function testPHP8ConstructorPropertyPromotionNoTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$x', 'content' => 'public $x = 0.0', 'default' => '0.0', - 'default_token' => 12, // Offset from the T_FUNCTION token. - 'default_equal_token' => 10, // Offset from the T_FUNCTION token. + 'default_token' => 12, + 'default_equal_token' => 10, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -1747,17 +1785,17 @@ public function testPHP8ConstructorPropertyPromotionNoTypes() 'type_hint_end_token' => false, 'nullable_type' => false, 'property_visibility' => 'public', - 'visibility_token' => 6, // Offset from the T_FUNCTION token. + 'visibility_token' => 6, 'property_readonly' => false, 'comma_token' => 13, ]; $expected[1] = [ - 'token' => 18, // Offset from the T_FUNCTION token. + 'token' => 18, 'name' => '$y', 'content' => 'protected $y = \'\'', 'default' => "''", - 'default_token' => 22, // Offset from the T_FUNCTION token. - 'default_equal_token' => 20, // Offset from the T_FUNCTION token. + 'default_token' => 22, + 'default_equal_token' => 20, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -1768,17 +1806,17 @@ public function testPHP8ConstructorPropertyPromotionNoTypes() 'type_hint_end_token' => false, 'nullable_type' => false, 'property_visibility' => 'protected', - 'visibility_token' => 16, // Offset from the T_FUNCTION token. + 'visibility_token' => 16, 'property_readonly' => false, 'comma_token' => 23, ]; $expected[2] = [ - 'token' => 28, // Offset from the T_FUNCTION token. + 'token' => 28, 'name' => '$z', 'content' => 'private $z = null', 'default' => 'null', - 'default_token' => 32, // Offset from the T_FUNCTION token. - 'default_equal_token' => 30, // Offset from the T_FUNCTION token. + 'default_token' => 32, + 'default_equal_token' => 30, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -1789,7 +1827,7 @@ public function testPHP8ConstructorPropertyPromotionNoTypes() 'type_hint_end_token' => false, 'nullable_type' => false, 'property_visibility' => 'private', - 'visibility_token' => 26, // Offset from the T_FUNCTION token. + 'visibility_token' => 26, 'property_readonly' => false, 'comma_token' => 33, ]; @@ -1804,9 +1842,10 @@ public function testPHP8ConstructorPropertyPromotionNoTypes() */ public function testPHP8ConstructorPropertyPromotionWithTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 10, // Offset from the T_FUNCTION token. + 'token' => 10, 'name' => '$x', 'content' => 'protected float|int $x', 'has_attributes' => false, @@ -1815,37 +1854,37 @@ public function testPHP8ConstructorPropertyPromotionWithTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'float|int', - 'type_hint_token' => 6, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 8, // Offset from the T_FUNCTION token. + 'type_hint_token' => 6, + 'type_hint_end_token' => 8, 'nullable_type' => false, 'property_visibility' => 'protected', - 'visibility_token' => 4, // Offset from the T_FUNCTION token. + 'visibility_token' => 4, 'property_readonly' => false, 'comma_token' => 11, ]; $expected[1] = [ - 'token' => 19, // Offset from the T_FUNCTION token. + 'token' => 19, 'name' => '$y', 'content' => 'public ?string &$y = \'test\'', 'default' => "'test'", - 'default_token' => 23, // Offset from the T_FUNCTION token. - 'default_equal_token' => 21, // Offset from the T_FUNCTION token. + 'default_token' => 23, + 'default_equal_token' => 21, 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 18, // Offset from the T_FUNCTION token. + 'reference_token' => 18, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?string', - 'type_hint_token' => 16, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 16, // Offset from the T_FUNCTION token. + 'type_hint_token' => 16, + 'type_hint_end_token' => 16, 'nullable_type' => true, 'property_visibility' => 'public', - 'visibility_token' => 13, // Offset from the T_FUNCTION token. + 'visibility_token' => 13, 'property_readonly' => false, 'comma_token' => 24, ]; $expected[2] = [ - 'token' => 30, // Offset from the T_FUNCTION token. + 'token' => 30, 'name' => '$z', 'content' => 'private mixed $z', 'has_attributes' => false, @@ -1854,11 +1893,11 @@ public function testPHP8ConstructorPropertyPromotionWithTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'mixed', - 'type_hint_token' => 28, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 28, // Offset from the T_FUNCTION token. + 'type_hint_token' => 28, + 'type_hint_end_token' => 28, 'nullable_type' => false, 'property_visibility' => 'private', - 'visibility_token' => 26, // Offset from the T_FUNCTION token. + 'visibility_token' => 26, 'property_readonly' => false, 'comma_token' => false, ]; @@ -1873,9 +1912,10 @@ public function testPHP8ConstructorPropertyPromotionWithTypes() */ public function testPHP8ConstructorPropertyPromotionAndNormalParam() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$promotedProp', 'content' => 'public int $promotedProp', 'has_attributes' => false, @@ -1884,16 +1924,16 @@ public function testPHP8ConstructorPropertyPromotionAndNormalParam() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'int', - 'type_hint_token' => 6, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 6, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'property_visibility' => 'public', - 'visibility_token' => 4, // Offset from the T_FUNCTION token. + 'visibility_token' => 4, 'property_readonly' => false, 'comma_token' => 9, ]; $expected[1] = [ - 'token' => 14, // Offset from the T_FUNCTION token. + 'token' => 14, 'name' => '$normalArg', 'content' => '?int $normalArg', 'has_attributes' => false, @@ -1902,8 +1942,8 @@ public function testPHP8ConstructorPropertyPromotionAndNormalParam() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?int', - 'type_hint_token' => 12, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 12, // Offset from the T_FUNCTION token. + 'type_hint_token' => 12, + 'type_hint_end_token' => 12, 'nullable_type' => true, 'comma_token' => false, ]; @@ -1918,9 +1958,10 @@ public function testPHP8ConstructorPropertyPromotionAndNormalParam() */ public function testPHP81ConstructorPropertyPromotionWithReadOnly() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 11, // Offset from the T_FUNCTION token. + 'token' => 11, 'name' => '$promotedProp', 'content' => 'public readonly ?int $promotedProp', 'has_attributes' => false, @@ -1929,32 +1970,32 @@ public function testPHP81ConstructorPropertyPromotionWithReadOnly() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?int', - 'type_hint_token' => 9, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 9, // Offset from the T_FUNCTION token. + 'type_hint_token' => 9, + 'type_hint_end_token' => 9, 'nullable_type' => true, 'property_visibility' => 'public', - 'visibility_token' => 4, // Offset from the T_FUNCTION token. + 'visibility_token' => 4, 'property_readonly' => true, - 'readonly_token' => 6, // Offset from the T_FUNCTION token. + 'readonly_token' => 6, 'comma_token' => 12, ]; $expected[1] = [ - 'token' => 23, // Offset from the T_FUNCTION token. + 'token' => 23, 'name' => '$promotedToo', 'content' => 'ReadOnly private string|bool &$promotedToo', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 22, // Offset from the T_FUNCTION token. + 'reference_token' => 22, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'string|bool', - 'type_hint_token' => 18, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 20, // Offset from the T_FUNCTION token. + 'type_hint_token' => 18, + 'type_hint_end_token' => 20, 'nullable_type' => false, 'property_visibility' => 'private', - 'visibility_token' => 16, // Offset from the T_FUNCTION token. + 'visibility_token' => 16, 'property_readonly' => true, - 'readonly_token' => 14, // Offset from the T_FUNCTION token. + 'readonly_token' => 14, 'comma_token' => false, ]; @@ -1969,9 +2010,10 @@ public function testPHP81ConstructorPropertyPromotionWithReadOnly() */ public function testPHP81ConstructorPropertyPromotionWithReadOnlyNoTypeDeclaration() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$promotedProp', 'content' => 'public readonly $promotedProp', 'has_attributes' => false, @@ -1984,18 +2026,18 @@ public function testPHP81ConstructorPropertyPromotionWithReadOnlyNoTypeDeclarati 'type_hint_end_token' => false, 'nullable_type' => false, 'property_visibility' => 'public', - 'visibility_token' => 4, // Offset from the T_FUNCTION token. + 'visibility_token' => 4, 'property_readonly' => true, - 'readonly_token' => 6, // Offset from the T_FUNCTION token. + 'readonly_token' => 6, 'comma_token' => 9, ]; $expected[1] = [ - 'token' => 16, // Offset from the T_FUNCTION token. + 'token' => 16, 'name' => '$promotedToo', 'content' => 'ReadOnly private &$promotedToo', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 15, // Offset from the T_FUNCTION token. + 'reference_token' => 15, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '', @@ -2003,9 +2045,9 @@ public function testPHP81ConstructorPropertyPromotionWithReadOnlyNoTypeDeclarati 'type_hint_end_token' => false, 'nullable_type' => false, 'property_visibility' => 'private', - 'visibility_token' => 13, // Offset from the T_FUNCTION token. + 'visibility_token' => 13, 'property_readonly' => true, - 'readonly_token' => 11, // Offset from the T_FUNCTION token. + 'readonly_token' => 11, 'comma_token' => false, ]; @@ -2020,9 +2062,10 @@ public function testPHP81ConstructorPropertyPromotionWithReadOnlyNoTypeDeclarati */ public function testPHP81ConstructorPropertyPromotionWithOnlyReadOnly() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 10, // Offset from the T_FUNCTION token. + 'token' => 10, 'name' => '$promotedProp', 'content' => 'readonly Foo&Bar $promotedProp', 'has_attributes' => false, @@ -2031,17 +2074,17 @@ public function testPHP81ConstructorPropertyPromotionWithOnlyReadOnly() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'Foo&Bar', - 'type_hint_token' => 6, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 8, // Offset from the T_FUNCTION token. + 'type_hint_token' => 6, + 'type_hint_end_token' => 8, 'nullable_type' => false, 'property_visibility' => 'public', 'visibility_token' => false, 'property_readonly' => true, - 'readonly_token' => 4, // Offset from the T_FUNCTION token. + 'readonly_token' => 4, 'comma_token' => 11, ]; $expected[1] = [ - 'token' => 18, // Offset from the T_FUNCTION token. + 'token' => 18, 'name' => '$promotedToo', 'content' => 'readonly ?bool $promotedToo', 'has_attributes' => false, @@ -2050,13 +2093,13 @@ public function testPHP81ConstructorPropertyPromotionWithOnlyReadOnly() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?bool', - 'type_hint_token' => 16, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 16, // Offset from the T_FUNCTION token. + 'type_hint_token' => 16, + 'type_hint_end_token' => 16, 'nullable_type' => true, 'property_visibility' => 'public', 'visibility_token' => false, 'property_readonly' => true, - 'readonly_token' => 13, // Offset from the T_FUNCTION token. + 'readonly_token' => 13, 'comma_token' => 19, ]; @@ -2070,9 +2113,10 @@ public function testPHP81ConstructorPropertyPromotionWithOnlyReadOnly() */ public function testPHP8ConstructorPropertyPromotionGlobalFunction() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 6, // Offset from the T_FUNCTION token. + 'token' => 6, 'name' => '$x', 'content' => 'private $x', 'has_attributes' => false, @@ -2085,7 +2129,7 @@ public function testPHP8ConstructorPropertyPromotionGlobalFunction() 'type_hint_end_token' => false, 'nullable_type' => false, 'property_visibility' => 'private', - 'visibility_token' => 4, // Offset from the T_FUNCTION token. + 'visibility_token' => 4, 'property_readonly' => false, 'comma_token' => false, ]; @@ -2100,9 +2144,10 @@ public function testPHP8ConstructorPropertyPromotionGlobalFunction() */ public function testPHP8ConstructorPropertyPromotionAbstractMethod() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$y', 'content' => 'public callable $y', 'has_attributes' => false, @@ -2111,29 +2156,29 @@ public function testPHP8ConstructorPropertyPromotionAbstractMethod() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'callable', - 'type_hint_token' => 6, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 6, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'property_visibility' => 'public', - 'visibility_token' => 4, // Offset from the T_FUNCTION token. + 'visibility_token' => 4, 'property_readonly' => false, 'comma_token' => 9, ]; $expected[1] = [ - 'token' => 14, // Offset from the T_FUNCTION token. + 'token' => 14, 'name' => '$x', 'content' => 'private ...$x', 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => true, - 'variadic_token' => 13, // Offset from the T_FUNCTION token. + 'variadic_token' => 13, 'type_hint' => '', 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, 'property_visibility' => 'private', - 'visibility_token' => 11, // Offset from the T_FUNCTION token. + 'visibility_token' => 11, 'property_readonly' => false, 'comma_token' => false, ]; @@ -2148,23 +2193,24 @@ public function testPHP8ConstructorPropertyPromotionAbstractMethod() */ public function testCommentsInParameter() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 19, // Offset from the T_FUNCTION token. + 'token' => 19, 'name' => '$param', 'content' => '// Leading comment. ?MyClass /*-*/ & /*-*/.../*-*/ $param /*-*/ = /*-*/ \'default value\' . /*-*/ \'second part\' // Trailing comment.', 'default' => '\'default value\' . /*-*/ \'second part\' // Trailing comment.', - 'default_token' => 27, // Offset from the T_FUNCTION token. - 'default_equal_token' => 23, // Offset from the T_FUNCTION token. + 'default_token' => 27, + 'default_equal_token' => 23, 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 13, // Offset from the T_FUNCTION token. + 'reference_token' => 13, 'variable_length' => true, - 'variadic_token' => 16, // Offset from the T_FUNCTION token. + 'variadic_token' => 16, 'type_hint' => '?MyClass', - 'type_hint_token' => 9, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 9, // Offset from the T_FUNCTION token. + 'type_hint_token' => 9, + 'type_hint_end_token' => 9, 'nullable_type' => true, 'comma_token' => false, ]; @@ -2181,9 +2227,10 @@ public function testParameterAttributesInFunctionDeclaration() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => ($php8Names === true) ? 14 : 17, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 14 : 17, 'name' => '$constructorPropPromTypedParamSingleAttribute', 'content' => '#[\MyExample\MyAttribute] private string' . ' $constructorPropPromTypedParamSingleAttribute', @@ -2193,16 +2240,16 @@ public function testParameterAttributesInFunctionDeclaration() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'string', - 'type_hint_token' => ($php8Names === true) ? 12 : 15, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 12 : 15, // Offset from the T_FUNCTION token. + 'type_hint_token' => ($php8Names === true) ? 12 : 15, + 'type_hint_end_token' => ($php8Names === true) ? 12 : 15, 'nullable_type' => false, 'property_visibility' => 'private', - 'visibility_token' => ($php8Names === true) ? 10 : 13, // Offset from the T_FUNCTION token. + 'visibility_token' => ($php8Names === true) ? 10 : 13, 'property_readonly' => false, - 'comma_token' => ($php8Names === true) ? 15 : 18, // Offset from the T_FUNCTION token. + 'comma_token' => ($php8Names === true) ? 15 : 18, ]; $expected[1] = [ - 'token' => ($php8Names === true) ? 36 : 39, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 36 : 39, 'name' => '$typedParamSingleAttribute', 'content' => '#[MyAttr([1, 2])] Type|false @@ -2213,13 +2260,13 @@ public function testParameterAttributesInFunctionDeclaration() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'Type|false', - 'type_hint_token' => ($php8Names === true) ? 31 : 34, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 33 : 36, // Offset from the T_FUNCTION token. + 'type_hint_token' => ($php8Names === true) ? 31 : 34, + 'type_hint_end_token' => ($php8Names === true) ? 33 : 36, 'nullable_type' => false, - 'comma_token' => ($php8Names === true) ? 37 : 40, // Offset from the T_FUNCTION token. + 'comma_token' => ($php8Names === true) ? 37 : 40, ]; $expected[2] = [ - 'token' => ($php8Names === true) ? 56 : 59, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 56 : 59, 'name' => '$nullableTypedParamMultiAttribute', 'content' => '#[MyAttribute(1234), MyAttribute(5678)] ?int $nullableTypedParamMultiAttribute', 'has_attributes' => true, @@ -2228,13 +2275,13 @@ public function testParameterAttributesInFunctionDeclaration() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?int', - 'type_hint_token' => ($php8Names === true) ? 54 : 57, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 54 : 57, // Offset from the T_FUNCTION token. + 'type_hint_token' => ($php8Names === true) ? 54 : 57, + 'type_hint_end_token' => ($php8Names === true) ? 54 : 57, 'nullable_type' => true, - 'comma_token' => ($php8Names === true) ? 57 : 60, // Offset from the T_FUNCTION token. + 'comma_token' => ($php8Names === true) ? 57 : 60, ]; $expected[3] = [ - 'token' => ($php8Names === true) ? 71 : 74, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 71 : 74, 'name' => '$nonTypedParamTwoAttributes', 'content' => '#[WithoutArgument] #[SingleArgument(0)] $nonTypedParamTwoAttributes', 'has_attributes' => true, @@ -2246,23 +2293,23 @@ public function testParameterAttributesInFunctionDeclaration() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => ($php8Names === true) ? 72 : 75, // Offset from the T_FUNCTION token. + 'comma_token' => ($php8Names === true) ? 72 : 75, ]; $expected[4] = [ - 'token' => ($php8Names === true) ? 92 : 95, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 92 : 95, 'name' => '$otherParam', 'content' => '#[MyAttribute(array("key" => "value"))] &...$otherParam', 'has_attributes' => true, 'pass_by_reference' => true, - 'reference_token' => ($php8Names === true) ? 90 : 93, // Offset from the T_FUNCTION token. + 'reference_token' => ($php8Names === true) ? 90 : 93, 'variable_length' => true, - 'variadic_token' => ($php8Names === true) ? 91 : 94, // Offset from the T_FUNCTION token. + 'variadic_token' => ($php8Names === true) ? 91 : 94, 'type_hint' => '', 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => ($php8Names === true) ? 93 : 96, // Offset from the T_FUNCTION token. + 'comma_token' => ($php8Names === true) ? 93 : 96, ]; $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected); @@ -2275,9 +2322,10 @@ public function testParameterAttributesInFunctionDeclaration() */ public function testPHP8IntersectionTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$obj1', 'content' => 'Foo&Bar $obj1', 'has_attributes' => false, @@ -2286,13 +2334,13 @@ public function testPHP8IntersectionTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'Foo&Bar', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'comma_token' => 9, ]; $expected[1] = [ - 'token' => 15, // Offset from the T_FUNCTION token. + 'token' => 15, 'name' => '$obj2', 'content' => 'Boo&Bar $obj2', 'has_attributes' => false, @@ -2301,8 +2349,8 @@ public function testPHP8IntersectionTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'Boo&Bar', - 'type_hint_token' => 11, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 13, // Offset from the T_FUNCTION token. + 'type_hint_token' => 11, + 'type_hint_end_token' => 13, 'nullable_type' => false, 'comma_token' => false, ]; @@ -2318,34 +2366,35 @@ public function testPHP8IntersectionTypes() */ public function testPHP81IntersectionTypesWithSpreadOperatorAndReference() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 9, // Offset from the T_FUNCTION token. + 'token' => 9, 'name' => '$paramA', 'content' => 'Boo&Bar &$paramA', 'has_attributes' => false, 'pass_by_reference' => true, - 'reference_token' => 8, // Offset from the T_FUNCTION token. + 'reference_token' => 8, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'Boo&Bar', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'comma_token' => 10, ]; $expected[1] = [ - 'token' => 17, // Offset from the T_FUNCTION token. + 'token' => 17, 'name' => '$paramB', 'content' => 'Foo&Bar ...$paramB', 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => true, - 'variadic_token' => 16, // Offset from the T_FUNCTION token. + 'variadic_token' => 16, 'type_hint' => 'Foo&Bar', - 'type_hint_token' => 12, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 14, // Offset from the T_FUNCTION token. + 'type_hint_token' => 12, + 'type_hint_end_token' => 14, 'nullable_type' => false, 'comma_token' => false, ]; @@ -2362,9 +2411,10 @@ public function testPHP81MoreIntersectionTypes() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => ($php8Names === true) ? 10 : 16, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 10 : 16, 'name' => '$var', 'content' => 'MyClassA&\Package\MyClassB&\Package\MyClassC $var', 'has_attributes' => false, @@ -2373,8 +2423,8 @@ public function testPHP81MoreIntersectionTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'MyClassA&\Package\MyClassB&\Package\MyClassC', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 8 : 14, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => ($php8Names === true) ? 8 : 14, 'nullable_type' => false, 'comma_token' => false, ]; @@ -2389,9 +2439,10 @@ public function testPHP81MoreIntersectionTypes() */ public function testPHP81IllegalIntersectionTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 7, // Offset from the T_FUNCTION token. + 'token' => 7, 'name' => '$numeric_string', 'content' => 'string&int $numeric_string', 'has_attributes' => false, @@ -2400,8 +2451,8 @@ public function testPHP81IllegalIntersectionTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'string&int', - 'type_hint_token' => 3, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 5, // Offset from the T_FUNCTION token. + 'type_hint_token' => 3, + 'type_hint_end_token' => 5, 'nullable_type' => false, 'comma_token' => false, ]; @@ -2416,9 +2467,10 @@ public function testPHP81IllegalIntersectionTypes() */ public function testPHP81NullableIntersectionTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$object', 'content' => '?Foo&Bar $object', 'has_attributes' => false, @@ -2427,8 +2479,8 @@ public function testPHP81NullableIntersectionTypes() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?Foo&Bar', - 'type_hint_token' => 4, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 6, 'nullable_type' => true, 'comma_token' => false, ]; @@ -2443,22 +2495,23 @@ public function testPHP81NullableIntersectionTypes() */ public function testPHP82PseudoTypeTrue() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 7, // Offset from the T_FUNCTION token. + 'token' => 7, '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. + 'default_token' => 11, + 'default_equal_token' => 9, '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. + 'type_hint_token' => 5, + 'type_hint_end_token' => 5, 'nullable_type' => true, 'comma_token' => false, ]; @@ -2473,22 +2526,23 @@ public function testPHP82PseudoTypeTrue() */ public function testPHP82PseudoTypeFalseAndTrue() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, '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. + 'default_token' => 12, + 'default_equal_token' => 10, '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. + 'type_hint_token' => 4, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'comma_token' => false, ]; @@ -2505,40 +2559,41 @@ public function testPHP81NewInInitializers() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$new', 'content' => 'TypeA $new = new TypeA(self::CONST_VALUE)', 'default' => 'new TypeA(self::CONST_VALUE)', - 'default_token' => 12, // Offset from the T_FUNCTION token. - 'default_equal_token' => 10, // Offset from the T_FUNCTION token. + 'default_token' => 12, + 'default_equal_token' => 10, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => 'TypeA', - 'type_hint_token' => 6, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 6, // Offset from the T_FUNCTION token. + 'type_hint_token' => 6, + 'type_hint_end_token' => 6, 'nullable_type' => false, 'comma_token' => 20, ]; $expected[1] = [ - 'token' => ($php8Names === true) ? 25 : 28, // Offset from the T_FUNCTION token. + 'token' => ($php8Names === true) ? 25 : 28, 'name' => '$newToo', 'content' => '\Package\TypeB $newToo = new \Package\TypeB(10, \'string\')', 'default' => "new \Package\TypeB(10, 'string')", - 'default_token' => ($php8Names === true) ? 29 : 32, // Offset from the T_FUNCTION token. - 'default_equal_token' => ($php8Names === true) ? 27 : 30, // Offset from the T_FUNCTION token. + 'default_token' => ($php8Names === true) ? 29 : 32, + 'default_equal_token' => ($php8Names === true) ? 27 : 30, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '\Package\TypeB', - 'type_hint_token' => 23, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => ($php8Names === true) ? 23 : 26, // Offset from the T_FUNCTION token. + 'type_hint_token' => 23, + 'type_hint_end_token' => ($php8Names === true) ? 23 : 26, 'nullable_type' => false, 'comma_token' => ($php8Names === true) ? 38 : 44, ]; @@ -2553,14 +2608,15 @@ public function testPHP81NewInInitializers() */ public function testClosure() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 3, // Offset from the T_FUNCTION token. + 'token' => 3, 'name' => '$a', 'content' => '$a = \'test\'', 'default' => "'test'", - 'default_token' => 7, // Offset from the T_FUNCTION token. - 'default_equal_token' => 5, // Offset from the T_FUNCTION token. + 'default_token' => 7, + 'default_equal_token' => 5, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -2583,9 +2639,10 @@ public function testClosure() */ public function testClosureUse() { + // Offsets are relative to the T_USE token. $expected = []; $expected[0] = [ - 'token' => 3, // Offset from the T_USE token. + 'token' => 3, 'name' => '$foo', 'content' => '$foo', 'has_attributes' => false, @@ -2597,10 +2654,10 @@ public function testClosureUse() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 4, // Offset from the T_USE token. + 'comma_token' => 4, ]; $expected[1] = [ - 'token' => 6, // Offset from the T_USE token. + 'token' => 6, 'name' => '$bar', 'content' => '$bar', 'has_attributes' => false, @@ -2625,9 +2682,10 @@ public function testClosureUse() */ public function testFunctionParamListWithTrailingComma() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 9, // Offset from the T_FUNCTION token. + 'token' => 9, 'name' => '$foo', 'content' => '?string $foo /*comment*/', 'has_attributes' => false, @@ -2636,18 +2694,18 @@ public function testFunctionParamListWithTrailingComma() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?string', - 'type_hint_token' => 7, // Offset from the T_FUNCTION token. - 'type_hint_end_token' => 7, // Offset from the T_FUNCTION token. + 'type_hint_token' => 7, + 'type_hint_end_token' => 7, 'nullable_type' => true, - 'comma_token' => 13, // Offset from the T_FUNCTION token. + 'comma_token' => 13, ]; $expected[1] = [ - 'token' => 16, // Offset from the T_FUNCTION token. + 'token' => 16, 'name' => '$bar', 'content' => '$bar = 0', 'default' => '0', - 'default_token' => 20, // Offset from the T_FUNCTION token. - 'default_equal_token' => 18, // Offset from the T_FUNCTION token. + 'default_token' => 20, + 'default_equal_token' => 18, 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, @@ -2657,7 +2715,7 @@ public function testFunctionParamListWithTrailingComma() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 21, // Offset from the T_FUNCTION token. + 'comma_token' => 21, ]; $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected); @@ -2670,9 +2728,10 @@ public function testFunctionParamListWithTrailingComma() */ public function testClosureParamListWithTrailingComma() { + // Offsets are relative to the T_FUNCTION token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_FUNCTION token. + 'token' => 4, 'name' => '$foo', 'content' => '$foo', 'has_attributes' => false, @@ -2684,10 +2743,10 @@ public function testClosureParamListWithTrailingComma() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 5, // Offset from the T_FUNCTION token. + 'comma_token' => 5, ]; $expected[1] = [ - 'token' => 8, // Offset from the T_FUNCTION token. + 'token' => 8, 'name' => '$bar', 'content' => '$bar', 'has_attributes' => false, @@ -2699,7 +2758,7 @@ public function testClosureParamListWithTrailingComma() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 9, // Offset from the T_FUNCTION token. + 'comma_token' => 9, ]; $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected); @@ -2712,9 +2771,10 @@ public function testClosureParamListWithTrailingComma() */ public function testArrowFunctionParamListWithTrailingComma() { + // Offsets are relative to the T_FN token. $expected = []; $expected[0] = [ - 'token' => 6, // Offset from the T_FN token. + 'token' => 6, 'name' => '$a', 'content' => '?int $a', 'has_attributes' => false, @@ -2723,25 +2783,25 @@ public function testArrowFunctionParamListWithTrailingComma() 'variable_length' => false, 'variadic_token' => false, 'type_hint' => '?int', - 'type_hint_token' => 4, // Offset from the T_FN token. - 'type_hint_end_token' => 4, // Offset from the T_FN token. + 'type_hint_token' => 4, + 'type_hint_end_token' => 4, 'nullable_type' => true, - 'comma_token' => 8, // Offset from the T_FN token. + 'comma_token' => 8, ]; $expected[1] = [ - 'token' => 11, // Offset from the T_FN token. + 'token' => 11, 'name' => '$b', 'content' => '...$b', 'has_attributes' => false, 'pass_by_reference' => false, 'reference_token' => false, 'variable_length' => true, - 'variadic_token' => 10, // Offset from the T_FN token. + 'variadic_token' => 10, 'type_hint' => '', 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 12, // Offset from the T_FN token. + 'comma_token' => 12, ]; $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected); @@ -2754,9 +2814,10 @@ public function testArrowFunctionParamListWithTrailingComma() */ public function testClosureUseWithTrailingComma() { + // Offsets are relative to the T_USE token. $expected = []; $expected[0] = [ - 'token' => 4, // Offset from the T_USE token. + 'token' => 4, 'name' => '$foo', 'content' => '$foo /*comment*/', 'has_attributes' => false, @@ -2768,10 +2829,10 @@ public function testClosureUseWithTrailingComma() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 8, // Offset from the T_USE token. + 'comma_token' => 8, ]; $expected[1] = [ - 'token' => 11, // Offset from the T_USE token. + 'token' => 11, 'name' => '$bar', 'content' => '$bar', 'has_attributes' => false, @@ -2783,7 +2844,7 @@ public function testClosureUseWithTrailingComma() 'type_hint_token' => false, 'type_hint_end_token' => false, 'nullable_type' => false, - 'comma_token' => 12, // Offset from the T_USE token. + 'comma_token' => 12, ]; $this->getMethodParametersTestHelper('/* ' . __FUNCTION__ . ' */', $expected, [T_USE]); @@ -2792,10 +2853,10 @@ public function testClosureUseWithTrailingComma() /** * Test helper. * - * @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. + * @param string $marker The comment which preceeds the test. + * @param array> $expected The expected function output. + * @param int|string|array $targetType Optional. The token type to search for after $marker. + * Defaults to the function/closure/arrow tokens. * * @return void */ @@ -2804,22 +2865,23 @@ protected function getMethodParametersTestHelper($marker, $expected, $targetType $target = $this->getTargetToken($marker, $targetType); $found = BCFile::getMethodParameters(self::$phpcsFile, $target); + // Convert offsets to absolute positions in the token stream. foreach ($expected as $key => $param) { $expected[$key]['token'] += $target; - if ($param['reference_token'] !== false) { + if (\is_int($param['reference_token']) === true) { $expected[$key]['reference_token'] += $target; } - if ($param['variadic_token'] !== false) { + if (\is_int($param['variadic_token']) === true) { $expected[$key]['variadic_token'] += $target; } - if ($param['type_hint_token'] !== false) { + if (\is_int($param['type_hint_token']) === true) { $expected[$key]['type_hint_token'] += $target; } - if ($param['type_hint_end_token'] !== false) { + if (\is_int($param['type_hint_end_token']) === true) { $expected[$key]['type_hint_end_token'] += $target; } - if ($param['comma_token'] !== false) { + if (\is_int($param['comma_token']) === true) { $expected[$key]['comma_token'] += $target; } if (isset($param['default_token'])) { @@ -2828,7 +2890,7 @@ protected function getMethodParametersTestHelper($marker, $expected, $targetType if (isset($param['default_equal_token'])) { $expected[$key]['default_equal_token'] += $target; } - if (isset($param['visibility_token']) && $param['visibility_token'] !== false) { + if (isset($param['visibility_token']) && \is_int($param['visibility_token']) === true) { $expected[$key]['visibility_token'] += $target; } if (isset($param['readonly_token'])) { diff --git a/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php b/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php index 365c49c6..93a61fa8 100644 --- a/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php +++ b/Tests/BackCompat/BCFile/GetMethodPropertiesTest.php @@ -40,8 +40,8 @@ class GetMethodPropertiesTest extends UtilityMethodTestCase * * @dataProvider dataNotAFunctionException * - * @param string $commentString The comment which preceeds the test. - * @param array $targetTokenType The token type to search for after $commentString. + * @param string $commentString The comment which preceeds the test. + * @param int|string|array $targetTokenType The token type to search for after $commentString. * * @return void */ @@ -58,22 +58,22 @@ public function testNotAFunctionException($commentString, $targetTokenType) * * @see testNotAFunctionException() For the array format. * - * @return array + * @return array>> */ public static function dataNotAFunctionException() { return [ 'return' => [ - '/* testNotAFunction */', - T_RETURN, + 'commentString' => '/* testNotAFunction */', + 'targetTokenType' => T_RETURN, ], 'function-call-fn-phpcs-3.5.3-3.5.4' => [ - '/* testFunctionCallFnPHPCS353-354 */', - [T_FN, T_STRING], + 'commentString' => '/* testFunctionCallFnPHPCS353-354 */', + 'targetTokenType' => [T_FN, T_STRING], ], 'fn-live-coding' => [ - '/* testArrowFunctionLiveCoding */', - [T_FN, T_STRING], + 'commentString' => '/* testArrowFunctionLiveCoding */', + 'targetTokenType' => [T_FN, T_STRING], ], ]; } @@ -108,12 +108,13 @@ public function testBasicFunction() */ public function testReturnFunction() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'array', - 'return_type_token' => 11, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 11, // Offset from the T_FUNCTION token. + 'return_type_token' => 11, + 'return_type_end_token' => 11, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -131,12 +132,13 @@ public function testReturnFunction() */ public function testNestedClosure() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'int', - 'return_type_token' => 8, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. + 'return_type_token' => 8, + 'return_type_end_token' => 8, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -223,12 +225,13 @@ public function testFinalMethod() */ public function testProtectedReturnMethod() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'protected', 'scope_specified' => true, 'return_type' => 'int', - 'return_type_token' => 8, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. + 'return_type_token' => 8, + 'return_type_end_token' => 8, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -246,12 +249,13 @@ public function testProtectedReturnMethod() */ public function testPublicReturnMethod() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => true, 'return_type' => 'array', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 7, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 7, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -269,12 +273,13 @@ public function testPublicReturnMethod() */ public function testNullableReturnMethod() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => true, 'return_type' => '?array', - 'return_type_token' => 8, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. + 'return_type_token' => 8, + 'return_type_end_token' => 8, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -292,12 +297,13 @@ public function testNullableReturnMethod() */ public function testMessyNullableReturnMethod() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => true, 'return_type' => '?array', - 'return_type_token' => 18, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 18, // Offset from the T_FUNCTION token. + 'return_type_token' => 18, + 'return_type_end_token' => 18, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -317,12 +323,13 @@ public function testReturnNamespace() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => '\MyNamespace\MyClass', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => ($php8Names === true) ? 7 : 10, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => ($php8Names === true) ? 7 : 10, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -342,12 +349,13 @@ public function testReturnMultilineNamespace() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => '\MyNamespace\MyClass\Foo', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => ($php8Names === true) ? 20 : 23, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => ($php8Names === true) ? 20 : 23, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -365,12 +373,13 @@ public function testReturnMultilineNamespace() */ public function testReturnUnqualifiedName() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'private', 'scope_specified' => true, 'return_type' => '?MyClass', - 'return_type_token' => 8, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. + 'return_type_token' => 8, + 'return_type_end_token' => 8, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -390,12 +399,13 @@ public function testReturnPartiallyQualifiedName() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'Sub\Level\MyClass', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => ($php8Names === true) ? 7 : 11, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => ($php8Names === true) ? 7 : 11, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -436,12 +446,13 @@ public function testAbstractMethod() */ public function testAbstractReturnMethod() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'protected', 'scope_specified' => true, 'return_type' => 'bool', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 7, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 7, 'nullable_return_type' => false, 'is_abstract' => true, 'is_final' => false, @@ -482,12 +493,13 @@ public function testInterfaceMethod() */ public function testArrowFunction() { + // Offsets are relative to the T_FN token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'int', - 'return_type_token' => 9, // Offset from the T_FN token. - 'return_type_end_token' => 9, // Offset from the T_FN token. + 'return_type_token' => 9, + 'return_type_end_token' => 9, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -505,12 +517,13 @@ public function testArrowFunction() */ public function testReturnTypeStatic() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'private', 'scope_specified' => true, 'return_type' => 'static', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 7, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 7, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -528,12 +541,13 @@ public function testReturnTypeStatic() */ public function testPHP8MixedTypeHint() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'mixed', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 7, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 7, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -551,12 +565,13 @@ public function testPHP8MixedTypeHint() */ public function testPHP8MixedTypeHintNullable() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => '?mixed', - 'return_type_token' => 8, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. + 'return_type_token' => 8, + 'return_type_end_token' => 8, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -576,12 +591,13 @@ public function testNamespaceOperatorTypeHint() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => '?namespace\Name', - 'return_type_token' => 9, // Offset from the T_FUNCTION token. - 'return_type_end_token' => ($php8Names === true) ? 9 : 11, // Offset from the T_FUNCTION token. + 'return_type_token' => 9, + 'return_type_end_token' => ($php8Names === true) ? 9 : 11, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -599,12 +615,13 @@ public function testNamespaceOperatorTypeHint() */ public function testPHP8UnionTypesSimple() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'int|float', - 'return_type_token' => 9, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 11, // Offset from the T_FUNCTION token. + 'return_type_token' => 9, + 'return_type_end_token' => 11, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -624,12 +641,13 @@ public function testPHP8UnionTypesTwoClasses() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'MyClassA|\Package\MyClassB', - 'return_type_token' => 6, // Offset from the T_FUNCTION token. - 'return_type_end_token' => ($php8Names === true) ? 8 : 11, // Offset from the T_FUNCTION token. + 'return_type_token' => 6, + 'return_type_end_token' => ($php8Names === true) ? 8 : 11, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -647,12 +665,13 @@ public function testPHP8UnionTypesTwoClasses() */ public function testPHP8UnionTypesAllBaseTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'array|bool|callable|int|float|null|Object|string', - 'return_type_token' => 8, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 22, // Offset from the T_FUNCTION token. + 'return_type_token' => 8, + 'return_type_end_token' => 22, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -672,12 +691,13 @@ public function testPHP8UnionTypesAllBaseTypes() */ public function testPHP8UnionTypesAllPseudoTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'false|MIXED|self|parent|static|iterable|Resource|void', - 'return_type_token' => 9, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 23, // Offset from the T_FUNCTION token. + 'return_type_token' => 9, + 'return_type_end_token' => 23, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -695,12 +715,13 @@ public function testPHP8UnionTypesAllPseudoTypes() */ public function testPHP8UnionTypesNullable() { + // Offsets are relative to the T_CLOSURE token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => '?int|float', - 'return_type_token' => 12, // Offset from the T_CLOSURE token. - 'return_type_end_token' => 14, // Offset from the T_CLOSURE token. + 'return_type_token' => 12, + 'return_type_end_token' => 14, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -718,12 +739,13 @@ public function testPHP8UnionTypesNullable() */ public function testPHP8PseudoTypeNull() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'null', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 7, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 7, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -741,12 +763,13 @@ public function testPHP8PseudoTypeNull() */ public function testPHP8PseudoTypeFalse() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'false', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 7, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 7, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -764,12 +787,13 @@ public function testPHP8PseudoTypeFalse() */ public function testPHP8PseudoTypeFalseAndBool() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'bool|false', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 9, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 9, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -787,12 +811,13 @@ public function testPHP8PseudoTypeFalseAndBool() */ public function testPHP8ObjectAndClass() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'object|ClassName', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 9, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 9, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -810,12 +835,13 @@ public function testPHP8ObjectAndClass() */ public function testPHP8PseudoTypeIterableAndArray() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => true, 'return_type' => 'iterable|array|Traversable', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 11, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 11, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -833,12 +859,13 @@ public function testPHP8PseudoTypeIterableAndArray() */ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'int|string|INT', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 17, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 17, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -856,12 +883,13 @@ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment() */ public function testPHP81NeverType() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'never', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 7, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 7, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -879,12 +907,13 @@ public function testPHP81NeverType() */ public function testPHP81NullableNeverType() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => '?never', - 'return_type_token' => 8, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. + 'return_type_token' => 8, + 'return_type_end_token' => 8, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -902,12 +931,13 @@ public function testPHP81NullableNeverType() */ public function testPHP8IntersectionTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'Foo&Bar', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 9, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 9, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -927,12 +957,13 @@ public function testPHP81MoreIntersectionTypes() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'MyClassA&\Package\MyClassB&\Package\MyClassC', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => ($php8Names === true) ? 11 : 17, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => ($php8Names === true) ? 11 : 17, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -952,12 +983,13 @@ public function testPHP81IntersectionArrowFunction() { $php8Names = parent::usesPhp8NameTokens(); + // Offsets are relative to the T_FN token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'MyClassA&\Package\MyClassB', - 'return_type_token' => 6, // Offset from the T_FN token. - 'return_type_end_token' => ($php8Names === true) ? 8 : 11, // Offset from the T_FN token. + 'return_type_token' => 6, + 'return_type_end_token' => ($php8Names === true) ? 8 : 11, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -975,12 +1007,13 @@ public function testPHP81IntersectionArrowFunction() */ public function testPHP81IllegalIntersectionTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'string&int', - 'return_type_token' => 6, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. + 'return_type_token' => 6, + 'return_type_end_token' => 8, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -998,12 +1031,13 @@ public function testPHP81IllegalIntersectionTypes() */ public function testPHP81NullableIntersectionTypes() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => '?Foo&Bar', - 'return_type_token' => 7, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 9, // Offset from the T_FUNCTION token. + 'return_type_token' => 7, + 'return_type_end_token' => 9, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -1015,18 +1049,19 @@ public function testPHP81NullableIntersectionTypes() } /** - * Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability. + * Verify recognition of PHP 8.2 stand-alone `true` type. * * @return void */ public function testPHP82PseudoTypeTrue() { + // Offsets are relative to the T_FUNCTION token. $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. + 'return_type_token' => 8, + 'return_type_end_token' => 8, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -1038,18 +1073,19 @@ public function testPHP82PseudoTypeTrue() } /** - * Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability. + * Verify recognition of PHP 8.2 type declaration with (illegal) type false combined with type true. * * @return void */ public function testPHP82PseudoTypeFalseAndTrue() { + // Offsets are relative to the T_FUNCTION token. $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. + 'return_type_token' => 7, + 'return_type_end_token' => 9, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -1069,12 +1105,13 @@ public function testPHP82PseudoTypeFalseAndTrue() */ public function testPhpcsIssue1264() { + // Offsets are relative to the T_FUNCTION token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'array', - 'return_type_token' => 8, // Offset from the T_FUNCTION token. - 'return_type_end_token' => 8, // Offset from the T_FUNCTION token. + 'return_type_token' => 8, + 'return_type_end_token' => 8, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -1095,12 +1132,13 @@ public function testPhpcsIssue1264() */ public function testArrowFunctionArrayReturnValue() { + // Offsets are relative to the T_FN token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => 'array', - 'return_type_token' => 5, // Offset from the T_FN token. - 'return_type_end_token' => 5, // Offset from the T_FN token. + 'return_type_token' => 5, + 'return_type_end_token' => 5, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -1118,12 +1156,13 @@ public function testArrowFunctionArrayReturnValue() */ public function testArrowFunctionReturnByRef() { + // Offsets are relative to the T_FN token. $expected = [ 'scope' => 'public', 'scope_specified' => false, 'return_type' => '?string', - 'return_type_token' => 12, // Offset from the T_FN token. - 'return_type_end_token' => 12, // Offset from the T_FN token. + 'return_type_token' => 12, + 'return_type_end_token' => 12, 'nullable_return_type' => true, 'is_abstract' => false, 'is_final' => false, @@ -1142,12 +1181,13 @@ public function testArrowFunctionReturnByRef() */ public function testFunctionDeclarationNestedInTernaryPHPCS2975() { + // Offsets are relative to the T_FN token. $expected = [ 'scope' => 'public', 'scope_specified' => true, 'return_type' => 'c', - 'return_type_token' => 7, // Offset from the T_FN token. - 'return_type_end_token' => 7, // Offset from the T_FN token. + 'return_type_token' => 7, + 'return_type_end_token' => 7, 'nullable_return_type' => false, 'is_abstract' => false, 'is_final' => false, @@ -1161,10 +1201,10 @@ public function testFunctionDeclarationNestedInTernaryPHPCS2975() /** * Test helper. * - * @param string $commentString The comment which preceeds the test. - * @param array $expected The expected function output. - * @param array $targetType Optional. The token type to search for after $commentString. - * Defaults to the function/closure tokens. + * @param string $commentString The comment which preceeds the test. + * @param array $expected The expected function output. + * @param int|string|array $targetType Optional. The token type to search for after $commentString. + * Defaults to the function/closure tokens. * * @return void */ @@ -1176,10 +1216,11 @@ protected function getMethodPropertiesTestHelper( $function = $this->getTargetToken($commentString, $targetType); $found = BCFile::getMethodProperties(self::$phpcsFile, $function); - if ($expected['return_type_token'] !== false) { + // Convert offsets to absolute positions in the token stream. + if (\is_int($expected['return_type_token']) === true) { $expected['return_type_token'] += $function; } - if ($expected['return_type_end_token'] !== false) { + if (\is_int($expected['return_type_end_token']) === true) { $expected['return_type_end_token'] += $function; } diff --git a/Tests/BackCompat/BCFile/GetTokensAsStringTest.php b/Tests/BackCompat/BCFile/GetTokensAsStringTest.php index c1856ca9..d0196fb5 100644 --- a/Tests/BackCompat/BCFile/GetTokensAsStringTest.php +++ b/Tests/BackCompat/BCFile/GetTokensAsStringTest.php @@ -93,12 +93,12 @@ public function testLengthBeyondEndOfFile() /** * Test getting a token set as a string. * - * @dataProvider dataGetTokensAsString() + * @dataProvider dataGetTokensAsString * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $startTokenType The type of token(s) to look for for the start of the string. - * @param int $length Token length to get. - * @param string $expected The expected function return value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $startTokenType The type of token(s) to look for for the start of the string. + * @param int $length Token length to get. + * @param string $expected The expected function return value. * * @return void */ @@ -114,7 +114,7 @@ public function testGetTokensAsString($testMarker, $startTokenType, $length, $ex * * @see testGetTokensAsString() For the array format. * - * @return array + * @return array> */ public static function dataGetTokensAsString() { @@ -122,143 +122,143 @@ public static function dataGetTokensAsString() return [ 'length-0' => [ - '/* testCalculation */', - \T_LNUMBER, - 0, - '', + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 0, + 'expected' => '', ], 'length-1' => [ - '/* testCalculation */', - \T_LNUMBER, - 1, - '1', + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 1, + 'expected' => '1', ], 'length-2' => [ - '/* testCalculation */', - \T_LNUMBER, - 2, - '1 ', + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 2, + 'expected' => '1 ', ], 'length-3' => [ - '/* testCalculation */', - \T_LNUMBER, - 3, - '1 +', + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 3, + 'expected' => '1 +', ], 'length-4' => [ - '/* testCalculation */', - \T_LNUMBER, - 4, - '1 + ', + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 4, + 'expected' => '1 + ', ], 'length-5' => [ - '/* testCalculation */', - \T_LNUMBER, - 5, - '1 + 2', + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 5, + 'expected' => '1 + 2', ], 'length-6' => [ - '/* testCalculation */', - \T_LNUMBER, - 6, - '1 + 2 ', + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 6, + 'expected' => '1 + 2 ', ], 'length-7' => [ - '/* testCalculation */', - \T_LNUMBER, - 7, - '1 + 2 +', + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 7, + 'expected' => '1 + 2 +', ], 'length-8' => [ - '/* testCalculation */', - \T_LNUMBER, - 8, - '1 + 2 + + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 8, + 'expected' => '1 + 2 + ', ], 'length-9' => [ - '/* testCalculation */', - \T_LNUMBER, - 9, - '1 + 2 + + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 9, + 'expected' => '1 + 2 + ', ], 'length-10' => [ - '/* testCalculation */', - \T_LNUMBER, - 10, - '1 + 2 + + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 10, + 'expected' => '1 + 2 + // Comment. ', ], 'length-11' => [ - '/* testCalculation */', - \T_LNUMBER, - 11, - '1 + 2 + + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 11, + 'expected' => '1 + 2 + // Comment. ', ], 'length-12' => [ - '/* testCalculation */', - \T_LNUMBER, - 12, - '1 + 2 + + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 12, + 'expected' => '1 + 2 + // Comment. 3', ], 'length-13' => [ - '/* testCalculation */', - \T_LNUMBER, - 13, - '1 + 2 + + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 13, + 'expected' => '1 + 2 + // Comment. 3 ', ], 'length-14' => [ - '/* testCalculation */', - \T_LNUMBER, - 14, - '1 + 2 + + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 14, + 'expected' => '1 + 2 + // Comment. 3 +', ], 'length-34' => [ - '/* testCalculation */', - \T_LNUMBER, - 34, - '1 + 2 + + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'length' => 34, + 'expected' => '1 + 2 + // Comment. 3 + 4 + 5 + 6 + 7 > 20;', ], 'namespace' => [ - '/* testNamespace */', - \T_NAMESPACE, - ($php8Names === true) ? 4 : 8, - 'namespace Foo\Bar\Baz;', + 'testMarker' => '/* testNamespace */', + 'startTokenType' => \T_NAMESPACE, + 'length' => ($php8Names === true) ? 4 : 8, + 'expected' => 'namespace Foo\Bar\Baz;', ], 'use-with-comments' => [ - '/* testUseWithComments */', - \T_USE, - 17, - 'use Foo /*comment*/ \ Bar + 'testMarker' => '/* testUseWithComments */', + 'startTokenType' => \T_USE, + 'length' => 17, + 'expected' => 'use Foo /*comment*/ \ Bar // phpcs:ignore Stnd.Cat.Sniff -- For reasons. \ Bah;', ], 'echo-with-tabs' => [ - '/* testEchoWithTabs */', - \T_ECHO, - 13, - 'echo \'foo\', + 'testMarker' => '/* testEchoWithTabs */', + 'startTokenType' => \T_ECHO, + 'length' => 13, + 'expected' => 'echo \'foo\', \'bar\' , \'baz\';', ], 'end-of-file' => [ - '/* testEndOfFile */', - \T_ECHO, - 4, - 'echo $foo;', + 'testMarker' => '/* testEndOfFile */', + 'startTokenType' => \T_ECHO, + 'length' => 4, + 'expected' => 'echo $foo;', ], ]; } @@ -266,12 +266,12 @@ public static function dataGetTokensAsString() /** * Test getting a token set as a string with the original, non tab-replaced content. * - * @dataProvider dataGetOrigContent() + * @dataProvider dataGetOrigContent * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $startTokenType The type of token(s) to look for for the start of the string. - * @param int $length Token length to get. - * @param string $expected The expected function return value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $startTokenType The type of token(s) to look for for the start of the string. + * @param int $length Token length to get. + * @param string $expected The expected function return value. * * @return void */ @@ -287,32 +287,32 @@ public function testGetOrigContent($testMarker, $startTokenType, $length, $expec * * @see testGetOrigContent() For the array format. * - * @return array + * @return array> */ public static function dataGetOrigContent() { return [ 'use-with-comments' => [ - '/* testUseWithComments */', - \T_USE, - 17, - 'use Foo /*comment*/ \ Bar + 'testMarker' => '/* testUseWithComments */', + 'startTokenType' => \T_USE, + 'length' => 17, + 'expected' => 'use Foo /*comment*/ \ Bar // phpcs:ignore Stnd.Cat.Sniff -- For reasons. \ Bah;', ], 'echo-with-tabs' => [ - '/* testEchoWithTabs */', - \T_ECHO, - 13, - 'echo \'foo\', + 'testMarker' => '/* testEchoWithTabs */', + 'startTokenType' => \T_ECHO, + 'length' => 13, + 'expected' => 'echo \'foo\', \'bar\' , \'baz\';', ], 'end-of-file' => [ - '/* testEndOfFile */', - \T_ECHO, - 4, - 'echo $foo;', + 'testMarker' => '/* testEndOfFile */', + 'startTokenType' => \T_ECHO, + 'length' => 4, + 'expected' => 'echo $foo;', ], ]; } diff --git a/Tests/BackCompat/BCFile/IsReferenceTest.php b/Tests/BackCompat/BCFile/IsReferenceTest.php index 9f5dcedd..2054a1e4 100644 --- a/Tests/BackCompat/BCFile/IsReferenceTest.php +++ b/Tests/BackCompat/BCFile/IsReferenceTest.php @@ -60,20 +60,20 @@ public function testNotBitwiseAndToken() } /** - * Test correctly identifying that whether a "bitwise and" token is a reference or not. + * Test correctly identifying whether a "bitwise and" token is a reference or not. * * @dataProvider dataIsReference * - * @param string $identifier Comment which precedes the test case. + * @param string $testMarker Comment which precedes the test case. * @param bool $expected Expected function output. * * @return void */ - public function testIsReference($identifier, $expected) + public function testIsReference($testMarker, $expected) { $testClass = static::TEST_CLASS; - $bitwiseAnd = $this->getTargetToken($identifier, T_BITWISE_AND); + $bitwiseAnd = $this->getTargetToken($testMarker, T_BITWISE_AND); $result = $testClass::isReference(self::$phpcsFile, $bitwiseAnd); $this->assertSame($expected, $result); } @@ -83,7 +83,7 @@ public function testIsReference($identifier, $expected) * * @see testIsReference() * - * @return array + * @return array> */ public static function dataIsReference() { @@ -97,272 +97,272 @@ public static function dataIsReference() 'expected' => true, ], 'bitwise and: param in function call' => [ - '/* testBitwiseAndA */', - false, + 'testMarker' => '/* testBitwiseAndA */', + 'expected' => false, ], 'bitwise and: in unkeyed short array, first value' => [ - '/* testBitwiseAndB */', - false, + 'testMarker' => '/* testBitwiseAndB */', + 'expected' => false, ], 'bitwise and: in unkeyed short array, last value' => [ - '/* testBitwiseAndC */', - false, + 'testMarker' => '/* testBitwiseAndC */', + 'expected' => false, ], 'bitwise and: in unkeyed long array, last value' => [ - '/* testBitwiseAndD */', - false, + 'testMarker' => '/* testBitwiseAndD */', + 'expected' => false, ], 'bitwise and: in keyed short array, last value' => [ - '/* testBitwiseAndE */', - false, + 'testMarker' => '/* testBitwiseAndE */', + 'expected' => false, ], 'bitwise and: in keyed long array, last value' => [ - '/* testBitwiseAndF */', - false, + 'testMarker' => '/* testBitwiseAndF */', + 'expected' => false, ], 'bitwise and: in assignment' => [ - '/* testBitwiseAndG */', - false, + 'testMarker' => '/* testBitwiseAndG */', + 'expected' => false, ], 'bitwise and: in param default value in function declaration' => [ - '/* testBitwiseAndH */', - false, + 'testMarker' => '/* testBitwiseAndH */', + 'expected' => false, ], 'bitwise and: in param default value in closure declaration' => [ - '/* testBitwiseAndI */', - false, + 'testMarker' => '/* testBitwiseAndI */', + 'expected' => false, ], 'reference: function declared to return by reference' => [ - '/* testFunctionReturnByReference */', - true, + 'testMarker' => '/* testFunctionReturnByReference */', + 'expected' => true, ], 'reference: only param in function declaration, pass by reference' => [ - '/* testFunctionPassByReferenceA */', - true, + 'testMarker' => '/* testFunctionPassByReferenceA */', + 'expected' => true, ], 'reference: last param in function declaration, pass by reference' => [ - '/* testFunctionPassByReferenceB */', - true, + 'testMarker' => '/* testFunctionPassByReferenceB */', + 'expected' => true, ], 'reference: only param in closure declaration, pass by reference' => [ - '/* testFunctionPassByReferenceC */', - true, + 'testMarker' => '/* testFunctionPassByReferenceC */', + 'expected' => true, ], 'reference: last param in closure declaration, pass by reference' => [ - '/* testFunctionPassByReferenceD */', - true, + 'testMarker' => '/* testFunctionPassByReferenceD */', + 'expected' => true, ], 'reference: typed param in function declaration, pass by reference' => [ - '/* testFunctionPassByReferenceE */', - true, + 'testMarker' => '/* testFunctionPassByReferenceE */', + 'expected' => true, ], 'reference: typed param in closure declaration, pass by reference' => [ - '/* testFunctionPassByReferenceF */', - true, + 'testMarker' => '/* testFunctionPassByReferenceF */', + 'expected' => true, ], 'reference: variadic param in function declaration, pass by reference' => [ - '/* testFunctionPassByReferenceG */', - true, + 'testMarker' => '/* testFunctionPassByReferenceG */', + 'expected' => true, ], 'reference: foreach value' => [ - '/* testForeachValueByReference */', - true, + 'testMarker' => '/* testForeachValueByReference */', + 'expected' => true, ], 'reference: foreach key' => [ - '/* testForeachKeyByReference */', - true, + 'testMarker' => '/* testForeachKeyByReference */', + 'expected' => true, ], 'reference: keyed short array, first value, value by reference' => [ - '/* testArrayValueByReferenceA */', - true, + 'testMarker' => '/* testArrayValueByReferenceA */', + 'expected' => true, ], 'reference: keyed short array, last value, value by reference' => [ - '/* testArrayValueByReferenceB */', - true, + 'testMarker' => '/* testArrayValueByReferenceB */', + 'expected' => true, ], 'reference: unkeyed short array, only value, value by reference' => [ - '/* testArrayValueByReferenceC */', - true, + 'testMarker' => '/* testArrayValueByReferenceC */', + 'expected' => true, ], 'reference: unkeyed short array, last value, value by reference' => [ - '/* testArrayValueByReferenceD */', - true, + 'testMarker' => '/* testArrayValueByReferenceD */', + 'expected' => true, ], 'reference: keyed long array, first value, value by reference' => [ - '/* testArrayValueByReferenceE */', - true, + 'testMarker' => '/* testArrayValueByReferenceE */', + 'expected' => true, ], 'reference: keyed long array, last value, value by reference' => [ - '/* testArrayValueByReferenceF */', - true, + 'testMarker' => '/* testArrayValueByReferenceF */', + 'expected' => true, ], 'reference: unkeyed long array, only value, value by reference' => [ - '/* testArrayValueByReferenceG */', - true, + 'testMarker' => '/* testArrayValueByReferenceG */', + 'expected' => true, ], 'reference: unkeyed long array, last value, value by reference' => [ - '/* testArrayValueByReferenceH */', - true, + 'testMarker' => '/* testArrayValueByReferenceH */', + 'expected' => true, ], 'reference: variable, assign by reference' => [ - '/* testAssignByReferenceA */', - true, + 'testMarker' => '/* testAssignByReferenceA */', + 'expected' => true, ], 'reference: variable, assign by reference, spacing variation' => [ - '/* testAssignByReferenceB */', - true, + 'testMarker' => '/* testAssignByReferenceB */', + 'expected' => true, ], 'reference: variable, assign by reference, concat assign' => [ - '/* testAssignByReferenceC */', - true, + 'testMarker' => '/* testAssignByReferenceC */', + 'expected' => true, ], 'reference: property, assign by reference' => [ - '/* testAssignByReferenceD */', - true, + 'testMarker' => '/* testAssignByReferenceD */', + 'expected' => true, ], 'reference: function return value, assign by reference' => [ - '/* testAssignByReferenceE */', - true, + 'testMarker' => '/* testAssignByReferenceE */', + 'expected' => true, ], 'reference: function return value, assign by reference, null coalesce assign' => [ - '/* testAssignByReferenceF */', - true, + 'testMarker' => '/* testAssignByReferenceF */', + 'expected' => true, ], 'reference: unkeyed short list, first var, assign by reference' => [ - '/* testShortListAssignByReferenceNoKeyA */', - true, + 'testMarker' => '/* testShortListAssignByReferenceNoKeyA */', + 'expected' => true, ], 'reference: unkeyed short list, second var, assign by reference' => [ - '/* testShortListAssignByReferenceNoKeyB */', - true, + 'testMarker' => '/* testShortListAssignByReferenceNoKeyB */', + 'expected' => true, ], 'reference: unkeyed short list, nested var, assign by reference' => [ - '/* testNestedShortListAssignByReferenceNoKey */', - true, + 'testMarker' => '/* testNestedShortListAssignByReferenceNoKey */', + 'expected' => true, ], 'reference: unkeyed long list, second var, assign by reference' => [ - '/* testLongListAssignByReferenceNoKeyA */', - true, + 'testMarker' => '/* testLongListAssignByReferenceNoKeyA */', + 'expected' => true, ], 'reference: unkeyed long list, first nested var, assign by reference' => [ - '/* testLongListAssignByReferenceNoKeyB */', - true, + 'testMarker' => '/* testLongListAssignByReferenceNoKeyB */', + 'expected' => true, ], 'reference: unkeyed long list, last nested var, assign by reference' => [ - '/* testLongListAssignByReferenceNoKeyC */', - true, + 'testMarker' => '/* testLongListAssignByReferenceNoKeyC */', + 'expected' => true, ], 'reference: keyed short list, first nested var, assign by reference' => [ - '/* testNestedShortListAssignByReferenceWithKeyA */', - true, + 'testMarker' => '/* testNestedShortListAssignByReferenceWithKeyA */', + 'expected' => true, ], 'reference: keyed short list, last nested var, assign by reference' => [ - '/* testNestedShortListAssignByReferenceWithKeyB */', - true, + 'testMarker' => '/* testNestedShortListAssignByReferenceWithKeyB */', + 'expected' => true, ], 'reference: keyed long list, only var, assign by reference' => [ - '/* testLongListAssignByReferenceWithKeyA */', - true, + 'testMarker' => '/* testLongListAssignByReferenceWithKeyA */', + 'expected' => true, ], 'reference: first param in function call, pass by reference' => [ - '/* testPassByReferenceA */', - true, + 'testMarker' => '/* testPassByReferenceA */', + 'expected' => true, ], 'reference: last param in function call, pass by reference' => [ - '/* testPassByReferenceB */', - true, + 'testMarker' => '/* testPassByReferenceB */', + 'expected' => true, ], 'reference: property in function call, pass by reference' => [ - '/* testPassByReferenceC */', - true, + 'testMarker' => '/* testPassByReferenceC */', + 'expected' => true, ], 'reference: hierarchical self property in function call, pass by reference' => [ - '/* testPassByReferenceD */', - true, + 'testMarker' => '/* testPassByReferenceD */', + 'expected' => true, ], 'reference: hierarchical parent property in function call, pass by reference' => [ - '/* testPassByReferenceE */', - true, + 'testMarker' => '/* testPassByReferenceE */', + 'expected' => true, ], 'reference: hierarchical static property in function call, pass by reference' => [ - '/* testPassByReferenceF */', - true, + 'testMarker' => '/* testPassByReferenceF */', + 'expected' => true, ], 'reference: static property in function call, pass by reference' => [ - '/* testPassByReferenceG */', - true, + 'testMarker' => '/* testPassByReferenceG */', + 'expected' => true, ], 'reference: static property in function call, first with FQN, pass by reference' => [ - '/* testPassByReferenceH */', - true, + 'testMarker' => '/* testPassByReferenceH */', + 'expected' => true, ], 'reference: static property in function call, last with FQN, pass by reference' => [ - '/* testPassByReferenceI */', - true, + 'testMarker' => '/* testPassByReferenceI */', + 'expected' => true, ], 'reference: static property in function call, last with namespace relative name, pass by reference' => [ - '/* testPassByReferenceJ */', - true, + 'testMarker' => '/* testPassByReferenceJ */', + 'expected' => true, ], 'reference: static property in function call, last with PQN, pass by reference' => [ - '/* testPassByReferencePartiallyQualifiedName */', - true, + 'testMarker' => '/* testPassByReferencePartiallyQualifiedName */', + 'expected' => true, ], 'reference: new by reference' => [ - '/* testNewByReferenceA */', - true, + 'testMarker' => '/* testNewByReferenceA */', + 'expected' => true, ], 'reference: new by reference as function call param' => [ - '/* testNewByReferenceB */', - true, + 'testMarker' => '/* testNewByReferenceB */', + 'expected' => true, ], 'reference: closure use by reference' => [ - '/* testUseByReference */', - true, + 'testMarker' => '/* testUseByReference */', + 'expected' => true, ], 'reference: closure use by reference, first param, with comment' => [ - '/* testUseByReferenceWithCommentFirstParam */', - true, + 'testMarker' => '/* testUseByReferenceWithCommentFirstParam */', + 'expected' => true, ], 'reference: closure use by reference, last param, with comment' => [ - '/* testUseByReferenceWithCommentSecondParam */', - true, + 'testMarker' => '/* testUseByReferenceWithCommentSecondParam */', + 'expected' => true, ], 'reference: arrow fn declared to return by reference' => [ - '/* testArrowFunctionReturnByReference */', - true, + 'testMarker' => '/* testArrowFunctionReturnByReference */', + 'expected' => true, ], 'bitwise and: first param default value in closure declaration' => [ - '/* testBitwiseAndExactParameterA */', - false, + 'testMarker' => '/* testBitwiseAndExactParameterA */', + 'expected' => false, ], 'reference: param in closure declaration, pass by reference' => [ - '/* testPassByReferenceExactParameterB */', - true, + 'testMarker' => '/* testPassByReferenceExactParameterB */', + 'expected' => true, ], 'reference: variadic param in closure declaration, pass by reference' => [ - '/* testPassByReferenceExactParameterC */', - true, + 'testMarker' => '/* testPassByReferenceExactParameterC */', + 'expected' => true, ], 'bitwise and: last param default value in closure declaration' => [ - '/* testBitwiseAndExactParameterD */', - false, + 'testMarker' => '/* testBitwiseAndExactParameterD */', + 'expected' => false, ], 'reference: typed param in arrow fn declaration, pass by reference' => [ - '/* testArrowFunctionPassByReferenceA */', - true, + 'testMarker' => '/* testArrowFunctionPassByReferenceA */', + 'expected' => true, ], 'reference: variadic param in arrow fn declaration, pass by reference' => [ - '/* testArrowFunctionPassByReferenceB */', - true, + 'testMarker' => '/* testArrowFunctionPassByReferenceB */', + 'expected' => true, ], 'reference: closure declared to return by reference' => [ - '/* testClosureReturnByReference */', - true, + 'testMarker' => '/* testClosureReturnByReference */', + 'expected' => true, ], 'bitwise and: param default value in arrow fn declaration' => [ - '/* testBitwiseAndArrowFunctionInDefault */', - false, + 'testMarker' => '/* testBitwiseAndArrowFunctionInDefault */', + 'expected' => false, ], 'issue-1284-short-list-directly-after-close-curly-control-structure' => [ 'testMarker' => '/* testTokenizerIssue1284PHPCSlt280A */', diff --git a/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php b/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php index ba949545..992c126f 100644 --- a/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php +++ b/Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php @@ -452,8 +452,8 @@ final class UnchangedTokenArraysTest extends TestCase * * @dataProvider dataUnchangedTokenArrays * - * @param string $name The token array name. - * @param array $expected The token array content. + * @param string $name The token array name. + * @param array $expected The token array content. * * @return void */ @@ -467,7 +467,7 @@ public function testUnchangedTokenArrays($name, $expected) * * @see testUnchangedTokenArrays() For the array format. * - * @return array + * @return array> */ public static function dataUnchangedTokenArrays() { diff --git a/Tests/BackCompat/Helper/ConfigDataTest.php b/Tests/BackCompat/Helper/ConfigDataTest.php index 316e3ff4..022aa105 100644 --- a/Tests/BackCompat/Helper/ConfigDataTest.php +++ b/Tests/BackCompat/Helper/ConfigDataTest.php @@ -20,8 +20,6 @@ * @covers \PHPCSUtils\BackCompat\Helper::setConfigData * @covers \PHPCSUtils\BackCompat\Helper::getConfigData * - * @group helper - * * @since 1.0.0 */ final class ConfigDataTest extends TestCase diff --git a/Tests/BackCompat/Helper/GetCommandLineDataTest.php b/Tests/BackCompat/Helper/GetCommandLineDataTest.php index 35b2c6ac..c8f06e6f 100644 --- a/Tests/BackCompat/Helper/GetCommandLineDataTest.php +++ b/Tests/BackCompat/Helper/GetCommandLineDataTest.php @@ -12,14 +12,13 @@ use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\TestUtils\UtilityMethodTestCase; +use stdClass; /** * Test class. * * @coversDefaultClass \PHPCSUtils\BackCompat\Helper * - * @group helper - * * @since 1.0.0 */ final class GetCommandLineDataTest extends UtilityMethodTestCase @@ -202,4 +201,28 @@ public function testIgnoreAnnotationsSetViaProperty() $this->assertTrue($result); } + + /** + * Test the ignoreAnnotations() method. + * + * @covers ::ignoreAnnotations + * + * @return void + */ + public function testIgnoreAnnotationsUsesGetConfigDataWhenInvalidFileParamPassed() + { + $config = null; + if (isset(self::$phpcsFile->config) === true) { + $config = self::$phpcsFile->config; + } + + Helper::setConfigData('annotations', false, true, $config); + + $result = Helper::ignoreAnnotations(new stdClass()); + + // Restore defaults before moving to the next test. + Helper::setConfigData('annotations', true, true, $config); + + $this->assertTrue($result); + } } diff --git a/Tests/BackCompat/Helper/GetVersionTest.php b/Tests/BackCompat/Helper/GetVersionTest.php index 16b0d4a9..f27c5d1c 100644 --- a/Tests/BackCompat/Helper/GetVersionTest.php +++ b/Tests/BackCompat/Helper/GetVersionTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\BackCompat\Helper::getVersion * - * @group helper - * * @since 1.0.0 */ final class GetVersionTest extends TestCase @@ -32,7 +30,7 @@ final class GetVersionTest extends TestCase * * @var string */ - const DEVMASTER = '3.8.0'; + const DEVMASTER = '3.9.0'; /** * Test the method. @@ -49,7 +47,7 @@ public function testGetVersion() } if ($expected === 'lowest') { - $expected = '3.8.0'; + $expected = '3.9.0'; } $result = Helper::getVersion(); diff --git a/Tests/ExpectWithConsecutiveArgs.php b/Tests/ExpectWithConsecutiveArgs.php index 12073926..b2844d93 100644 --- a/Tests/ExpectWithConsecutiveArgs.php +++ b/Tests/ExpectWithConsecutiveArgs.php @@ -25,10 +25,11 @@ trait ExpectWithConsecutiveArgs /** * PHPUnit cross-version helper method to test the arguments passed to a method in a mocked object. * - * @param object $mockObject The object mock. - * @param object $countMatcher Matcher for number of time the method is expected to be called. - * @param string $methodName The name of the method on which to set the expectations. - * @param array $expectedArgs Multi-dimentional array of arguments expected to be passed in consecutive calls. + * @param object $mockObject The object mock. + * @param object $countMatcher Matcher for number of time the method is expected to be called. + * @param string $methodName The name of the method on which to set the expectations. + * @param array> $expectedArgs Multi-dimentional array of arguments expected to be passed in + * consecutive calls. * * @return object Expectation object. */ diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.php index 303a9d9f..2475457d 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Fixers\SpacesFixer::checkAndFix * - * @group fixers - * * @since 1.0.8 */ final class SpacesFixerAtEOFTest extends UtilityMethodTestCase @@ -58,7 +56,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 string[] + * @var array */ protected static $selectedSniff = ['PHPCSUtils.SpacesFixer.Test']; diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerExceptionsTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerExceptionsTest.php index 3ff2ef0e..a244369f 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerExceptionsTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerExceptionsTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Fixers\SpacesFixer::checkAndFix * - * @group fixers - * * @since 1.0.0 */ final class SpacesFixerExceptionsTest extends UtilityMethodTestCase diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php index a8e42c3a..60455f90 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerNewlineTest.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\Fixers\SpacesFixer::checkAndFix * - * @group fixers - * * @since 1.0.0 */ final class SpacesFixerNewlineTest extends SpacesFixerTestCase @@ -48,7 +46,7 @@ final class SpacesFixerNewlineTest extends SpacesFixerTestCase /** * The names of the test case(s) in compliance. * - * @var string[] + * @var array */ protected static $compliantCases = [ 'newline-and-trailing-spaces', diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php index caca0072..da40d2d4 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerNoSpaceTest.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\Fixers\SpacesFixer::checkAndFix * - * @group fixers - * * @since 1.0.0 */ final class SpacesFixerNoSpaceTest extends SpacesFixerTestCase @@ -48,7 +46,7 @@ final class SpacesFixerNoSpaceTest extends SpacesFixerTestCase /** * The names of the test case(s) in compliance. * - * @var string[] + * @var array */ protected static $compliantCases = ['no-space']; diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php b/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php index a8cdeef8..10578cc5 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerOneSpaceTest.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\Fixers\SpacesFixer::checkAndFix * - * @group fixers - * * @since 1.0.0 */ final class SpacesFixerOneSpaceTest extends SpacesFixerTestCase @@ -48,7 +46,7 @@ final class SpacesFixerOneSpaceTest extends SpacesFixerTestCase /** * The names of the test case(s) in compliance. * - * @var string[] + * @var array */ protected static $compliantCases = [ 'one-space', diff --git a/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php b/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php index ae861daa..efc39a4f 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerTestCase.php @@ -69,7 +69,7 @@ abstract class SpacesFixerTestCase extends UtilityMethodTestCase * * Important: this MUST be set in the concrete test class! * - * @var string[] + * @var array */ 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 string[] + * @var array */ protected static $selectedSniff = ['PHPCSUtils.SpacesFixer.Test']; @@ -109,8 +109,8 @@ public static function setUpTestFile() * * @dataProvider dataCheckAndFixNoError * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected Expected error details (for the metric input). + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected Expected error details (for the metric input). * * @return void */ @@ -154,7 +154,7 @@ public function testCheckAndFixNoError($testMarker, $expected) * * @see testCheckAndFixNoError() For the array format. * - * @return array + * @return array>> */ public static function dataCheckAndFixNoError() { @@ -164,6 +164,7 @@ public static function dataCheckAndFixNoError() foreach (static::$compliantCases as $caseName) { if (isset($baseData[$caseName])) { $data[$caseName] = $baseData[$caseName]; + unset($data[$caseName]['type']); } } @@ -177,9 +178,9 @@ public static function dataCheckAndFixNoError() * * @dataProvider dataCheckAndFix * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected Expected error details. - * @param string $type The message type to test: 'error' or 'warning'. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected Expected error details. + * @param string $type The message type to test: 'error' or 'warning'. * * @return void */ @@ -242,7 +243,7 @@ public function testCheckAndFix($testMarker, $expected, $type) * * @see testCheckAndFix() For the array format. * - * @return array + * @return array>> */ public static function dataCheckAndFix() { @@ -301,7 +302,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 55d443e8..6a9aa604 100644 --- a/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php +++ b/Tests/Fixers/SpacesFixer/SpacesFixerTwoSpaceTest.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\Fixers\SpacesFixer::checkAndFix * - * @group fixers - * * @since 1.0.0 */ final class SpacesFixerTwoSpaceTest extends SpacesFixerTestCase @@ -50,7 +48,7 @@ final class SpacesFixerTwoSpaceTest extends SpacesFixerTestCase /** * The names of the test case(s) in compliance. * - * @var string[] + * @var array */ protected static $compliantCases = ['two-spaces']; diff --git a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php index 557fe808..576350c3 100644 --- a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php +++ b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingNewlineTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Fixers\SpacesFixer::checkAndFix * - * @group fixers - * * @since 1.0.0 */ final class TrailingCommentHandlingNewlineTest extends UtilityMethodTestCase @@ -65,7 +63,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 string[] + * @var array */ protected static $selectedSniff = ['PHPCSUtils.SpacesFixer.Test']; @@ -154,7 +152,7 @@ public function testNoFixesMade() * * @see testCheckAndFixNoError() For the array format. * - * @return array + * @return array> */ public static function dataCheckAndFixNoError() { diff --git a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php index 5c480866..74dab315 100644 --- a/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php +++ b/Tests/Fixers/SpacesFixer/TrailingCommentHandlingTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Fixers\SpacesFixer::checkAndFix * - * @group fixers - * * @since 1.0.0 */ final class TrailingCommentHandlingTest extends UtilityMethodTestCase @@ -65,7 +63,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 string[] + * @var array */ protected static $selectedSniff = ['PHPCSUtils.SpacesFixer.Test']; @@ -74,9 +72,9 @@ final class TrailingCommentHandlingTest extends UtilityMethodTestCase * * @dataProvider dataCheckAndFix * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected Expected error details. - * @param string $type The message type to test: 'error' or 'warning'. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected Expected error details. + * @param string $type The message type to test: 'error' or 'warning'. * * @return void */ @@ -180,7 +178,7 @@ public function testFixesMade() * * @see testCheckAndFix() For the array format. * - * @return array + * @return array>> */ public static function dataCheckAndFix() { diff --git a/Tests/Internal/Cache/GetClearTest.php b/Tests/Internal/Cache/GetClearTest.php index b0c8d352..652aa62b 100644 --- a/Tests/Internal/Cache/GetClearTest.php +++ b/Tests/Internal/Cache/GetClearTest.php @@ -280,7 +280,7 @@ public function testGetWillRetrievedPreviouslySetValue($id, $expected) /** * Data provider. * - * @return array + * @return array> */ public static function dataEveryTypeOfInput() { @@ -401,7 +401,7 @@ public function testGetForFileWillNotConfuseDataFromDifferentLoops() /** * Test that previously cached data is no longer available when the cache has been cleared. * - * @dataProvider dataEveryTypeOfInput + * @dataProvider dataClearCache * * @covers ::clear * @@ -416,4 +416,22 @@ public function testClearCache($id) $this->assertFalse(Cache::isCached(self::$phpcsFile, 'Utility1', $id)); $this->assertFalse(Cache::isCached(self::$phpcsFile, 'Utility2', $id)); } + + /** + * Data provider. + * + * @see testClearCache() For the array format. + * + * @return array + */ + public static function dataClearCache() + { + $data = self::dataEveryTypeOfInput(); + + foreach ($data as $name => $dataset) { + unset($data[$name]['expected']); + } + + return $data; + } } diff --git a/Tests/Internal/Cache/SetTest.php b/Tests/Internal/Cache/SetTest.php index 28df3ed7..77bb3362 100644 --- a/Tests/Internal/Cache/SetTest.php +++ b/Tests/Internal/Cache/SetTest.php @@ -113,7 +113,7 @@ public function testSetAcceptsEveryTypeOfInput($input) /** * Data provider. * - * @return array + * @return array> */ public static function dataEveryTypeOfInput() { @@ -155,7 +155,7 @@ public function testSetAcceptsIntAndStringIdKeys($id) /** * Data provider. * - * @return array + * @return array> */ public static function dataSetAcceptsIntAndStringIdKeys() { diff --git a/Tests/Internal/IsShortArrayOrList/ConstructorTest.php b/Tests/Internal/IsShortArrayOrList/ConstructorTest.php index 306ee6da..ad97db03 100644 --- a/Tests/Internal/IsShortArrayOrList/ConstructorTest.php +++ b/Tests/Internal/IsShortArrayOrList/ConstructorTest.php @@ -42,8 +42,8 @@ public function testNonExistentToken() * * @dataProvider dataNotOpenBracket * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetType The token type(s) to look for. * * @return void */ @@ -62,7 +62,7 @@ public function testNotOpenBracket($testMarker, $targetType) * * @see testNotBracket() For the array format. * - * @return array + * @return array> */ public static function dataNotOpenBracket() { @@ -95,8 +95,8 @@ public static function dataNotOpenBracket() * * @dataProvider dataSupportedBrackets * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetType The token type(s) to look for. * * @return void */ @@ -113,7 +113,7 @@ public function testSupportedBrackets($testMarker, $targetType) * * @see testSupportedBrackets() For the array format. * - * @return array + * @return array> */ public static function dataSupportedBrackets() { diff --git a/Tests/Internal/IsShortArrayOrList/IsInForeachTest.php b/Tests/Internal/IsShortArrayOrList/IsInForeachTest.php index 905603f5..fb5078d7 100644 --- a/Tests/Internal/IsShortArrayOrList/IsInForeachTest.php +++ b/Tests/Internal/IsShortArrayOrList/IsInForeachTest.php @@ -67,7 +67,7 @@ public function testIsInForeach($testMarker, $expected) * * @see testIsInForeach() For the array format. * - * @return array + * @return array> */ public static function dataIsInForeachResolved() { @@ -112,7 +112,7 @@ public static function dataIsInForeachResolved() * * @see testIsInForeach() For the array format. * - * @return array + * @return array> */ public static function dataIsInForeachNestedResolvedViaOuter() { @@ -157,7 +157,7 @@ public static function dataIsInForeachNestedResolvedViaOuter() * * @see testIsInForeach() For the array format. * - * @return array + * @return array> */ public static function dataIsInForeachUndetermined() { diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC1Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC1Test.php index e2801e2b..302b7e37 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC1Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC1Test.php @@ -50,7 +50,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @see testIsShortArrayBracket() For the array format. * - * @return array + * @return array> */ public static function dataIsShortArrayBracket() { diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC2Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC2Test.php index 1d5753da..7580784f 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC2Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC2Test.php @@ -50,7 +50,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @see testIsShortArrayBracket() For the array format. * - * @return array + * @return array> */ public static function dataIsShortArrayBracket() { diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC3Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC3Test.php index 6ca30c68..026d5ca1 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC3Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC3Test.php @@ -50,7 +50,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @see testIsShortArrayBracket() For the array format. * - * @return array + * @return array> */ public static function dataIsShortArrayBracket() { diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC4Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC4Test.php index 7f2a45a5..0b4eaabf 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC4Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC4Test.php @@ -50,7 +50,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @see testIsShortArrayBracket() For the array format. * - * @return array + * @return array> */ public static function dataIsShortArrayBracket() { diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC5Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC5Test.php index f26f8507..79edb170 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC5Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC5Test.php @@ -50,7 +50,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @see testIsShortArrayBracket() For the array format. * - * @return array + * @return array> */ public static function dataIsShortArrayBracket() { diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC6Test.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC6Test.php index dc267a62..e23f987e 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC6Test.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayBracketBC6Test.php @@ -50,7 +50,7 @@ public function testIsShortArrayBracket($testMarker, $expected) * * @see testIsShortArrayBracket() For the array format. * - * @return array + * @return array> */ public static function dataIsShortArrayBracket() { diff --git a/Tests/Internal/IsShortArrayOrList/IsShortArrayOrListTest.php b/Tests/Internal/IsShortArrayOrList/IsShortArrayOrListTest.php index aa221281..c3379825 100644 --- a/Tests/Internal/IsShortArrayOrList/IsShortArrayOrListTest.php +++ b/Tests/Internal/IsShortArrayOrList/IsShortArrayOrListTest.php @@ -52,7 +52,7 @@ public function testIsShortArrayOrList($testMarker, $expected) * * @see testIsShortArrayOrList() For the array format. * - * @return array + * @return array> */ public static function dataIsShortArrayOrList() { diff --git a/Tests/Internal/IsShortArrayOrList/IsSquareBracketTest.php b/Tests/Internal/IsShortArrayOrList/IsSquareBracketTest.php index 6c36029a..6ad49d42 100644 --- a/Tests/Internal/IsShortArrayOrList/IsSquareBracketTest.php +++ b/Tests/Internal/IsShortArrayOrList/IsSquareBracketTest.php @@ -61,7 +61,7 @@ public function testSquareBrackets($testMarker) * * @see testSquareBrackets() For the array format. * - * @return array + * @return array> */ public static function dataSquareBrackets() { diff --git a/Tests/Internal/IsShortArrayOrList/SolveTest.php b/Tests/Internal/IsShortArrayOrList/SolveTest.php index 45788bde..8328a6c0 100644 --- a/Tests/Internal/IsShortArrayOrList/SolveTest.php +++ b/Tests/Internal/IsShortArrayOrList/SolveTest.php @@ -48,7 +48,7 @@ public function testSolve($testMarker, $expected) * * @see testSolve() For the array format. * - * @return array + * @return array> */ public static function dataSolve() { diff --git a/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php b/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php index 4e7a64d5..3dda6e8d 100644 --- a/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php +++ b/Tests/Internal/IsShortArrayOrList/WalkInsideTest.php @@ -47,7 +47,7 @@ public function testWalkInsideUndetermined($testMarker, $expected) * * @see testWalkInsideUndetermined() For the array format. * - * @return array + * @return array> */ public static function dataWalkInsideUndetermined() { @@ -132,7 +132,7 @@ public function testWalkInsideResolved($testMarker, $expected) * * @see testWalkInsideResolved() For the array format. * - * @return array + * @return array> */ public static function dataWalkInsideResolved() { @@ -274,7 +274,7 @@ public function testRecursionLimit($testMarker, $expected) * * @see testRecursionLimit() For the array format. * - * @return array + * @return array> */ public static function dataRecursionLimit() { diff --git a/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php b/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php index 012be957..e7e41b1a 100644 --- a/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php +++ b/Tests/Internal/IsShortArrayOrList/WalkOutsideTest.php @@ -50,7 +50,7 @@ public function testWalkOutside($testMarker, $expected) * * @see testWalkOutside() For the array format. * - * @return array + * @return array> */ public static function dataWalkOutside() { @@ -186,7 +186,7 @@ public function testReuseCacheFromAdjacent($testMarker, $adjacent1, $adjacent2, * * @see testReuseCacheFromAdjacent() For the array format. * - * @return array + * @return array> */ public static function dataReuseCacheFromAdjacent() { diff --git a/Tests/Internal/IsShortArrayOrListWithCache/CachingTest.php b/Tests/Internal/IsShortArrayOrListWithCache/CachingTest.php index 672aa43c..63918ee9 100644 --- a/Tests/Internal/IsShortArrayOrListWithCache/CachingTest.php +++ b/Tests/Internal/IsShortArrayOrListWithCache/CachingTest.php @@ -67,7 +67,7 @@ public function testResultIsCached($testMarker, $expected) /** * Data provider. * - * @return array + * @return array> */ public static function dataResultIsCached() { diff --git a/Tests/Internal/IsShortArrayOrListWithCache/EntryPointsTest.php b/Tests/Internal/IsShortArrayOrListWithCache/EntryPointsTest.php index a50ce9b0..057f6b29 100644 --- a/Tests/Internal/IsShortArrayOrListWithCache/EntryPointsTest.php +++ b/Tests/Internal/IsShortArrayOrListWithCache/EntryPointsTest.php @@ -29,7 +29,7 @@ final class EntryPointsTest extends IsShortArrayOrListWithCacheTestCase /** * Return values in use for the IsShortArrayOrListWithCache::solve() method. * - * @var string[] + * @var array */ private $validValues = [ IsShortArrayOrList::SHORT_ARRAY, @@ -45,8 +45,8 @@ final class EntryPointsTest extends IsShortArrayOrListWithCacheTestCase * * @covers \PHPCSUtils\Utils\Arrays::isShortArray * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the file. + * @param int|string|array $targetType The token type(s) to look for. * * @return void */ @@ -63,8 +63,8 @@ public function testIsShortArrayApi($testMarker, $targetType) * * @covers \PHPCSUtils\Utils\Lists::isShortList * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the file. + * @param int|string|array $targetType The token type(s) to look for. * * @return void */ @@ -82,8 +82,8 @@ public function testIsShortListApi($testMarker, $targetType) * * @covers \PHPCSUtils\Internal\IsShortArrayOrListWithCache::isShortArray * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the file. + * @param int|string|array $targetType The token type(s) to look for. * * @return void */ @@ -101,8 +101,8 @@ public function testIsShortArrayInternal($testMarker, $targetType) * * @covers \PHPCSUtils\Internal\IsShortArrayOrListWithCache::isShortList * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the file. + * @param int|string|array $targetType The token type(s) to look for. * * @return void */ @@ -120,8 +120,8 @@ public function testIsShortListInternal($testMarker, $targetType) * * @covers \PHPCSUtils\Internal\IsShortArrayOrListWithCache::getType * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the file. + * @param int|string|array $targetType The token type(s) to look for. * * @return void */ @@ -134,7 +134,7 @@ public function testGetTypeInternal($testMarker, $targetType) /** * Data provider. * - * @return array + * @return array>> */ public static function dataEntryPoints() { diff --git a/Tests/Internal/IsShortArrayOrListWithCache/IsValidStackPtrTest.php b/Tests/Internal/IsShortArrayOrListWithCache/IsValidStackPtrTest.php index d91560b0..62d620c1 100644 --- a/Tests/Internal/IsShortArrayOrListWithCache/IsValidStackPtrTest.php +++ b/Tests/Internal/IsShortArrayOrListWithCache/IsValidStackPtrTest.php @@ -27,7 +27,7 @@ final class IsValidStackPtrTest extends IsShortArrayOrListWithCacheTestCase /** * Return values in use for square brackets. * - * @var string[] + * @var array */ private $validValues = [ IsShortArrayOrList::SHORT_ARRAY, @@ -50,8 +50,8 @@ public function testNonExistentToken() * * @dataProvider dataNotBracket * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetType The token type(s) to look for. * * @return void */ @@ -66,7 +66,7 @@ public function testNotBracket($testMarker, $targetType) * * @see testNotBracket() For the array format. * - * @return array + * @return array> */ public static function dataNotBracket() { @@ -89,8 +89,8 @@ public static function dataNotBracket() * * @dataProvider dataValidBracket * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetType The token type(s) to look for. * * @return void */ @@ -107,7 +107,7 @@ public function testValidBracket($testMarker, $targetType) * * @see testNotBracket() For the array format. * - * @return array + * @return array> */ public static function dataValidBracket() { diff --git a/Tests/Internal/IsShortArrayOrListWithCache/ProcessTest.php b/Tests/Internal/IsShortArrayOrListWithCache/ProcessTest.php index 39519c67..83472c68 100644 --- a/Tests/Internal/IsShortArrayOrListWithCache/ProcessTest.php +++ b/Tests/Internal/IsShortArrayOrListWithCache/ProcessTest.php @@ -42,9 +42,9 @@ public function testInvalidStackPtr() * * @dataProvider dataSupportedBrackets * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. - * @param string|false $expected The expected function return value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetType The token type(s) to look for. + * @param string $expected The expected function return value. * * @return void */ @@ -59,7 +59,7 @@ public function testSupportedBrackets($testMarker, $targetType, $expected) * * @see testSupportedBrackets() For the array format. * - * @return array + * @return array> */ public static function dataSupportedBrackets() { diff --git a/Tests/Internal/NoFileCache/GetClearTest.php b/Tests/Internal/NoFileCache/GetClearTest.php index d7eebb03..ff5ef8d4 100644 --- a/Tests/Internal/NoFileCache/GetClearTest.php +++ b/Tests/Internal/NoFileCache/GetClearTest.php @@ -232,7 +232,7 @@ public function testGetWillRetrievedPreviouslySetValue($id, $expected) /** * Data provider. * - * @return array + * @return array> */ public static function dataEveryTypeOfInput() { @@ -265,7 +265,7 @@ public function testGetForKey() /** * Test that previously cached data is no longer available when the cache has been cleared. * - * @dataProvider dataEveryTypeOfInput + * @dataProvider dataClearCache * * @covers ::clear * @@ -280,4 +280,22 @@ public function testClearCache($id) $this->assertFalse(NoFileCache::isCached('Utility1', $id)); $this->assertFalse(NoFileCache::isCached('Utility2', $id)); } + + /** + * Data provider. + * + * @see testClearCache() For the array format. + * + * @return array + */ + public static function dataClearCache() + { + $data = self::dataEveryTypeOfInput(); + + foreach ($data as $name => $dataset) { + unset($data[$name]['expected']); + } + + return $data; + } } diff --git a/Tests/Internal/NoFileCache/SetTest.php b/Tests/Internal/NoFileCache/SetTest.php index fc327001..b672f047 100644 --- a/Tests/Internal/NoFileCache/SetTest.php +++ b/Tests/Internal/NoFileCache/SetTest.php @@ -107,7 +107,7 @@ public function testSetAcceptsEveryTypeOfInput($input) /** * Data provider. * - * @return array + * @return array> */ public static function dataEveryTypeOfInput() { @@ -149,7 +149,7 @@ public function testSetAcceptsIntAndStringIdKeys($id) /** * Data provider. * - * @return array + * @return array> */ public static function dataSetAcceptsIntAndStringIdKeys() { diff --git a/Tests/TestUtils/UtilityMethodTestCase/ExpectPhpcsExceptionTest.php b/Tests/TestUtils/UtilityMethodTestCase/ExpectPhpcsExceptionTest.php index 5b31884a..542911b2 100644 --- a/Tests/TestUtils/UtilityMethodTestCase/ExpectPhpcsExceptionTest.php +++ b/Tests/TestUtils/UtilityMethodTestCase/ExpectPhpcsExceptionTest.php @@ -19,8 +19,6 @@ * * @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::expectPhpcsException * - * @group testutils - * * @since 1.0.0 */ final class ExpectPhpcsExceptionTest extends UtilityMethodTestCase diff --git a/Tests/TestUtils/UtilityMethodTestCase/FailedToTokenizeTest.php b/Tests/TestUtils/UtilityMethodTestCase/FailedToTokenizeTest.php index 988d89b3..f6356f73 100644 --- a/Tests/TestUtils/UtilityMethodTestCase/FailedToTokenizeTest.php +++ b/Tests/TestUtils/UtilityMethodTestCase/FailedToTokenizeTest.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::setUpTestFile * - * @group testutils - * * @since 1.0.0 */ final class FailedToTokenizeTest extends PolyfilledTestCase diff --git a/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenFileNotFoundTest.php b/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenFileNotFoundTest.php index 1990b7b6..01e112c7 100644 --- a/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenFileNotFoundTest.php +++ b/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenFileNotFoundTest.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::getTargetToken * - * @group testutils - * * @since 1.0.0 */ final class GetTargetTokenFileNotFoundTest extends PolyfilledTestCase diff --git a/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenTest.php b/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenTest.php index d07f6387..c4dcb7f7 100644 --- a/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenTest.php +++ b/Tests/TestUtils/UtilityMethodTestCase/GetTargetTokenTest.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::getTargetToken * - * @group testutils - * * @since 1.0.0 */ final class GetTargetTokenTest extends PolyfilledTestCase @@ -42,10 +40,10 @@ public static function setUpTestFile() * * @dataProvider dataGetTargetToken * - * @param int|false $expected Expected function output. - * @param string $commentString The delimiter comment to look for. - * @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 int $expected Expected function output. + * @param string $commentString The delimiter comment to look for. + * @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 void */ @@ -65,7 +63,7 @@ public function testGetTargetToken($expected, $commentString, $tokenType, $token * * @see testGetTargetToken() For the array format. * - * @return array + * @return array>> */ public static function dataGetTargetToken() { diff --git a/Tests/TestUtils/UtilityMethodTestCase/MissingCaseFileTest.php b/Tests/TestUtils/UtilityMethodTestCase/MissingCaseFileTest.php index ead82dfa..58b8cea1 100644 --- a/Tests/TestUtils/UtilityMethodTestCase/MissingCaseFileTest.php +++ b/Tests/TestUtils/UtilityMethodTestCase/MissingCaseFileTest.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::setUpTestFile * - * @group testutils - * * @since 1.0.0 */ final class MissingCaseFileTest extends PolyfilledTestCase diff --git a/Tests/TestUtils/UtilityMethodTestCase/SkipJSCSSTestsOnPHPCS4Test.php b/Tests/TestUtils/UtilityMethodTestCase/SkipJSCSSTestsOnPHPCS4Test.php index 76064d2c..0b1096fd 100644 --- a/Tests/TestUtils/UtilityMethodTestCase/SkipJSCSSTestsOnPHPCS4Test.php +++ b/Tests/TestUtils/UtilityMethodTestCase/SkipJSCSSTestsOnPHPCS4Test.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::skipJSCSSTestsOnPHPCS4 * - * @group testutils - * * @since 1.0.0 */ final class SkipJSCSSTestsOnPHPCS4Test extends PolyfilledTestCase diff --git a/Tests/TestUtils/UtilityMethodTestCase/UtilityMethodTestCaseTest.php b/Tests/TestUtils/UtilityMethodTestCase/UtilityMethodTestCaseTest.php index 6247c17f..137f440b 100644 --- a/Tests/TestUtils/UtilityMethodTestCase/UtilityMethodTestCaseTest.php +++ b/Tests/TestUtils/UtilityMethodTestCase/UtilityMethodTestCaseTest.php @@ -17,8 +17,6 @@ * * @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase * - * @group testutils - * * @since 1.0.0 */ final class UtilityMethodTestCaseTest extends PolyfilledTestCase diff --git a/Tests/Tokens/Collections/ArrayOpenTokensBCTest.php b/Tests/Tokens/Collections/ArrayOpenTokensBCTest.php index 2f581b75..60f90060 100644 --- a/Tests/Tokens/Collections/ArrayOpenTokensBCTest.php +++ b/Tests/Tokens/Collections/ArrayOpenTokensBCTest.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tests\Tokens\Collections; -use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Tokens\Collections; use PHPUnit\Framework\TestCase; @@ -19,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::arrayOpenTokensBC * - * @group collections - * * @since 1.0.2 */ final class ArrayOpenTokensBCTest extends TestCase diff --git a/Tests/Tokens/Collections/ArrayTokensBCTest.php b/Tests/Tokens/Collections/ArrayTokensBCTest.php index 7a5be5ba..c3f2a9c8 100644 --- a/Tests/Tokens/Collections/ArrayTokensBCTest.php +++ b/Tests/Tokens/Collections/ArrayTokensBCTest.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tests\Tokens\Collections; -use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Tokens\Collections; use PHPUnit\Framework\TestCase; @@ -19,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::arrayTokensBC * - * @group collections - * * @since 1.0.2 */ final class ArrayTokensBCTest extends TestCase diff --git a/Tests/Tokens/Collections/FunctionCallTokensTest.php b/Tests/Tokens/Collections/FunctionCallTokensTest.php index 2c7b0fb3..ce3a6ad4 100644 --- a/Tests/Tokens/Collections/FunctionCallTokensTest.php +++ b/Tests/Tokens/Collections/FunctionCallTokensTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::functionCallTokens * - * @group collections - * * @since 1.0.0 */ final class FunctionCallTokensTest extends TestCase diff --git a/Tests/Tokens/Collections/ListOpenTokensBCTest.php b/Tests/Tokens/Collections/ListOpenTokensBCTest.php index ddbcc615..571eef2d 100644 --- a/Tests/Tokens/Collections/ListOpenTokensBCTest.php +++ b/Tests/Tokens/Collections/ListOpenTokensBCTest.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tests\Tokens\Collections; -use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Tokens\Collections; use PHPUnit\Framework\TestCase; @@ -19,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::listOpenTokensBC * - * @group collections - * * @since 1.0.2 */ final class ListOpenTokensBCTest extends TestCase diff --git a/Tests/Tokens/Collections/ListTokensBCTest.php b/Tests/Tokens/Collections/ListTokensBCTest.php index d7a2eff8..8936c863 100644 --- a/Tests/Tokens/Collections/ListTokensBCTest.php +++ b/Tests/Tokens/Collections/ListTokensBCTest.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tests\Tokens\Collections; -use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Tokens\Collections; use PHPUnit\Framework\TestCase; @@ -19,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::listTokensBC * - * @group collections - * * @since 1.0.2 */ final class ListTokensBCTest extends TestCase diff --git a/Tests/Tokens/Collections/NamespacedNameTokensTest.php b/Tests/Tokens/Collections/NamespacedNameTokensTest.php index 9fb3d4c1..9c081b8e 100644 --- a/Tests/Tokens/Collections/NamespacedNameTokensTest.php +++ b/Tests/Tokens/Collections/NamespacedNameTokensTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::namespacedNameTokens * - * @group collections - * * @since 1.0.0 */ final class NamespacedNameTokensTest extends TestCase diff --git a/Tests/Tokens/Collections/ParameterPassingTokensTest.php b/Tests/Tokens/Collections/ParameterPassingTokensTest.php index e457f90d..e26255cb 100644 --- a/Tests/Tokens/Collections/ParameterPassingTokensTest.php +++ b/Tests/Tokens/Collections/ParameterPassingTokensTest.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tests\Tokens\Collections; -use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Tokens\Collections; use PHPUnit\Framework\TestCase; @@ -19,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::parameterPassingTokens * - * @group collections - * * @since 1.0.0 */ final class ParameterPassingTokensTest extends TestCase diff --git a/Tests/Tokens/Collections/ParameterTypeTokensTest.php b/Tests/Tokens/Collections/ParameterTypeTokensTest.php index 417741cb..3f4bd3a3 100644 --- a/Tests/Tokens/Collections/ParameterTypeTokensTest.php +++ b/Tests/Tokens/Collections/ParameterTypeTokensTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::parameterTypeTokens * - * @group collections - * * @since 1.0.0 */ final class ParameterTypeTokensTest extends TestCase diff --git a/Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php b/Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php index d1d83bc5..e9b40f68 100644 --- a/Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php +++ b/Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php @@ -19,8 +19,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::__callStatic * - * @group collections - * * @since 1.0.0 */ final class PropertyBasedTokenArraysTest extends TestCase @@ -50,7 +48,7 @@ public function testPropertyBasedTokenArrays($name) * * @see testPropertyBasedTokenArrays() For the array format. * - * @return array + * @return array> */ public static function dataPropertyBasedTokenArrays() { diff --git a/Tests/Tokens/Collections/PropertyTypeTokensTest.php b/Tests/Tokens/Collections/PropertyTypeTokensTest.php index d2c3aeae..65278cba 100644 --- a/Tests/Tokens/Collections/PropertyTypeTokensTest.php +++ b/Tests/Tokens/Collections/PropertyTypeTokensTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::propertyTypeTokens * - * @group collections - * * @since 1.0.0 */ final class PropertyTypeTokensTest extends TestCase diff --git a/Tests/Tokens/Collections/ReturnTypeTokensTest.php b/Tests/Tokens/Collections/ReturnTypeTokensTest.php index 085061c7..f53d9252 100644 --- a/Tests/Tokens/Collections/ReturnTypeTokensTest.php +++ b/Tests/Tokens/Collections/ReturnTypeTokensTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::returnTypeTokens * - * @group collections - * * @since 1.0.0 */ final class ReturnTypeTokensTest extends TestCase diff --git a/Tests/Tokens/Collections/ShortArrayListOpenTokensBCTest.php b/Tests/Tokens/Collections/ShortArrayListOpenTokensBCTest.php index d85bf8c1..55bff891 100644 --- a/Tests/Tokens/Collections/ShortArrayListOpenTokensBCTest.php +++ b/Tests/Tokens/Collections/ShortArrayListOpenTokensBCTest.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tests\Tokens\Collections; -use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Tokens\Collections; use PHPUnit\Framework\TestCase; @@ -19,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::shortArrayListOpenTokensBC * - * @group collections - * * @since 1.0.2 */ final class ShortArrayListOpenTokensBCTest extends TestCase diff --git a/Tests/Tokens/Collections/ShortArrayTokensBCTest.php b/Tests/Tokens/Collections/ShortArrayTokensBCTest.php index 0d8d75bd..07f36c3a 100644 --- a/Tests/Tokens/Collections/ShortArrayTokensBCTest.php +++ b/Tests/Tokens/Collections/ShortArrayTokensBCTest.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tests\Tokens\Collections; -use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Tokens\Collections; use PHPUnit\Framework\TestCase; @@ -19,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::shortArrayTokensBC * - * @group collections - * * @since 1.0.2 */ final class ShortArrayTokensBCTest extends TestCase diff --git a/Tests/Tokens/Collections/ShortListTokensBCTest.php b/Tests/Tokens/Collections/ShortListTokensBCTest.php index 5b403d4a..10a36c61 100644 --- a/Tests/Tokens/Collections/ShortListTokensBCTest.php +++ b/Tests/Tokens/Collections/ShortListTokensBCTest.php @@ -10,7 +10,6 @@ namespace PHPCSUtils\Tests\Tokens\Collections; -use PHPCSUtils\BackCompat\Helper; use PHPCSUtils\Tokens\Collections; use PHPUnit\Framework\TestCase; @@ -19,8 +18,6 @@ * * @covers \PHPCSUtils\Tokens\Collections::shortListTokensBC * - * @group collections - * * @since 1.0.2 */ final class ShortListTokensBCTest extends TestCase diff --git a/Tests/Tokens/TokenHelper/TokenExistsTest.php b/Tests/Tokens/TokenHelper/TokenExistsTest.php index 0dc01ee3..718737ef 100644 --- a/Tests/Tokens/TokenHelper/TokenExistsTest.php +++ b/Tests/Tokens/TokenHelper/TokenExistsTest.php @@ -60,7 +60,7 @@ public function testTokenExists($name, $expected) * These tests are not relevant at this time with the current minimum * PHPCS version, but this may change again in the future.} * - * @return array + * @return array> */ public static function dataTokenExists() { diff --git a/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php b/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php index 1ef4f0f2..cb072944 100644 --- a/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php +++ b/Tests/Utils/Arrays/GetDoubleArrowPtrTest.php @@ -20,8 +20,6 @@ * * @covers \PHPCSUtils\Utils\Arrays::getDoubleArrowPtr * - * @group arrays - * * @since 1.0.0 */ final class GetDoubleArrowPtrTest extends UtilityMethodTestCase @@ -136,7 +134,7 @@ public function testGetDoubleArrowPtr($testMarker, $expected) * * @see testGetDoubleArrowPtr() * - * @return array + * @return array> */ public static function dataGetDoubleArrowPtr() { diff --git a/Tests/Utils/Arrays/GetOpenCloseTest.php b/Tests/Utils/Arrays/GetOpenCloseTest.php index c6cfe5c1..bdcccb63 100644 --- a/Tests/Utils/Arrays/GetOpenCloseTest.php +++ b/Tests/Utils/Arrays/GetOpenCloseTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Arrays::getOpenClose * - * @group arrays - * * @since 1.0.0 */ final class GetOpenCloseTest extends UtilityMethodTestCase @@ -40,8 +38,8 @@ public function testNonExistentToken() * * @dataProvider dataNotArrayOpenToken * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetToken The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetToken The token type(s) to look for. * * @return void */ @@ -56,7 +54,7 @@ public function testNotArrayOpenToken($testMarker, $targetToken) * * @see testNotArrayOpenToken() For the array format. * - * @return array + * @return array> */ public static function dataNotArrayOpenToken() { @@ -89,9 +87,9 @@ public static function dataNotArrayOpenToken() * * @dataProvider dataGetOpenClose * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetToken The token type(s) to look for. - * @param array|false $expected The expected function return value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetToken The token type(s) to look for. + * @param array|false $expected The expected function return value. * * @return void */ @@ -116,7 +114,7 @@ public function testGetOpenClose($testMarker, $targetToken, $expected) * * @see testGetOpenClose() For the array format. * - * @return array + * @return array|false>> */ public static function dataGetOpenClose() { diff --git a/Tests/Utils/Conditions/GetConditionTest.php b/Tests/Utils/Conditions/GetConditionTest.php index c8b84d9c..52d40116 100644 --- a/Tests/Utils/Conditions/GetConditionTest.php +++ b/Tests/Utils/Conditions/GetConditionTest.php @@ -148,7 +148,7 @@ public function testGetFirstCondition($testMarker) * * @see testGetFirstCondition() For the array format. * - * @return array + * @return array> */ public static function dataGetFirstCondition() { @@ -165,9 +165,9 @@ public static function dataGetFirstCondition() * * @dataProvider dataGetLastCondition * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The marker for the pointers to the expected condition - * results for the pre-set tests. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The marker for the pointers to the expected condition + * results for the pre-set tests. * * @return void */ @@ -193,7 +193,7 @@ public function testGetLastCondition($testMarker, $expected) * * @see testGetLastCondition() For the array format. * - * @return array + * @return array>> */ public static function dataGetLastCondition() { diff --git a/Tests/Utils/Context/InAttributeTest.php b/Tests/Utils/Context/InAttributeTest.php index d09faa41..3cb9b8cb 100644 --- a/Tests/Utils/Context/InAttributeTest.php +++ b/Tests/Utils/Context/InAttributeTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Context::inAttribute * - * @group context - * * @since 1.0.0 */ final class InAttributeTest extends UtilityMethodTestCase @@ -40,8 +38,8 @@ public function testNonExistentToken() * * @dataProvider dataNotInAttribute * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetType The token type(s) to look for. * * @return void */ @@ -56,7 +54,7 @@ public function testNotInAttribute($testMarker, $targetType) * * @see testInAttribute() * - * @return array + * @return array> */ public static function dataNotInAttribute() { @@ -104,8 +102,8 @@ public static function dataNotInAttribute() * * @dataProvider dataInAttribute * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetType The token type(s) to look for. * * @return void */ @@ -120,7 +118,7 @@ public function testInAttribute($testMarker, $targetType) * * @see testInAttribute() * - * @return array + * @return array> */ public static function dataInAttribute() { diff --git a/Tests/Utils/Context/InEmptyTest.php b/Tests/Utils/Context/InEmptyTest.php index 62750d1c..f9b40f6c 100644 --- a/Tests/Utils/Context/InEmptyTest.php +++ b/Tests/Utils/Context/InEmptyTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Context::inEmpty * - * @group context - * * @since 1.0.0 */ final class InEmptyTest extends UtilityMethodTestCase @@ -56,7 +54,7 @@ public function testInEmpty($testMarker, $expected) * * @see testInEmpty() * - * @return array + * @return array> */ public static function dataInEmpty() { diff --git a/Tests/Utils/Context/InForConditionTest.php b/Tests/Utils/Context/InForConditionTest.php index 89d3ee99..b1897aee 100644 --- a/Tests/Utils/Context/InForConditionTest.php +++ b/Tests/Utils/Context/InForConditionTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Context::inForCondition * - * @group context - * * @since 1.0.0 */ final class InForConditionTest extends UtilityMethodTestCase @@ -55,7 +53,7 @@ public function testNotInFor($testMarker) * * @see testNotInFor() * - * @return array + * @return array> */ public static function dataNotInFor() { @@ -76,12 +74,12 @@ public static function dataNotInFor() * * @dataProvider dataInForCondition * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param string $expected The expected function return value. - * @param int|string|array $targetType Optional. The token type of the target token. - * Defaults to T_VARIABLE. - * @param string $targetContent Optional. The token content of the target token. - * Defaults to `$target` for `T_VARIABLE`. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expected The expected function return value. + * @param int|string $targetType Optional. The token type of the target token. + * Defaults to T_VARIABLE. + * @param string $targetContent Optional. The token content of the target token. + * Defaults to `$target` for `T_VARIABLE`. * * @return void */ @@ -101,7 +99,7 @@ public function testInForCondition($testMarker, $expected, $targetType = \T_VARI * * @see testInForCondition() * - * @return array + * @return array> */ public static function dataInForCondition() { diff --git a/Tests/Utils/Context/InForeachConditionTest.php b/Tests/Utils/Context/InForeachConditionTest.php index f14e73ce..0c66287f 100644 --- a/Tests/Utils/Context/InForeachConditionTest.php +++ b/Tests/Utils/Context/InForeachConditionTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Context::inForeachCondition * - * @group context - * * @since 1.0.0 */ final class InForeachConditionTest extends UtilityMethodTestCase @@ -55,7 +53,7 @@ public function testNotInForeach($testMarker) * * @see testNotInForeach() * - * @return array + * @return array> */ public static function dataNotInForeach() { @@ -75,12 +73,12 @@ public static function dataNotInForeach() * * @dataProvider dataInForeachCondition * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param string $expected The expected function return value. - * @param int|string|array $targetType Optional. The token type of the target token. - * Defaults to T_VARIABLE. - * @param string $targetContent Optional. The token content of the target token. - * Defaults to `$target` for `T_VARIABLE`. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expected The expected function return value. + * @param int|string $targetType Optional. The token type of the target token. + * Defaults to T_VARIABLE. + * @param string $targetContent Optional. The token content of the target token. + * Defaults to `$target` for `T_VARIABLE`. * * @return void */ @@ -100,7 +98,7 @@ public function testInForeachCondition($testMarker, $expected, $targetType = \T_ * * @see testInForeachCondition() * - * @return array + * @return array> */ public static function dataInForeachCondition() { diff --git a/Tests/Utils/Context/InIssetTest.php b/Tests/Utils/Context/InIssetTest.php index c48a7433..6952e95b 100644 --- a/Tests/Utils/Context/InIssetTest.php +++ b/Tests/Utils/Context/InIssetTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Context::inIsset * - * @group context - * * @since 1.0.0 */ final class InIssetTest extends UtilityMethodTestCase @@ -56,7 +54,7 @@ public function testInIsset($testMarker, $expected) * * @see testInIsset() * - * @return array + * @return array> */ public static function dataInIsset() { diff --git a/Tests/Utils/Context/InUnsetTest.php b/Tests/Utils/Context/InUnsetTest.php index 350f38aa..4209ff65 100644 --- a/Tests/Utils/Context/InUnsetTest.php +++ b/Tests/Utils/Context/InUnsetTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Context::inUnset * - * @group context - * * @since 1.0.0 */ final class InUnsetTest extends UtilityMethodTestCase @@ -56,7 +54,7 @@ public function testInUnset($testMarker, $expected) * * @see testInUnset() * - * @return array + * @return array> */ public static function dataInUnset() { diff --git a/Tests/Utils/ControlStructures/GetCaughtExceptionsTest.php b/Tests/Utils/ControlStructures/GetCaughtExceptionsTest.php index fdafc00f..c2aefe3a 100644 --- a/Tests/Utils/ControlStructures/GetCaughtExceptionsTest.php +++ b/Tests/Utils/ControlStructures/GetCaughtExceptionsTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\ControlStructures::getCaughtExceptions * - * @group controlstructures - * * @since 1.0.0 */ final class GetCaughtExceptionsTest extends UtilityMethodTestCase @@ -67,8 +65,8 @@ public function testParseError() * * @dataProvider dataGetCaughtExceptions * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array> $expected The expected return value. * * @return void */ @@ -91,7 +89,7 @@ public function testGetCaughtExceptions($testMarker, $expected) * * @see testGetCaughtExceptions() For the array format. * - * @return array + * @return array>>> */ public static function dataGetCaughtExceptions() { diff --git a/Tests/Utils/ControlStructures/HasBodyParseError1Test.php b/Tests/Utils/ControlStructures/HasBodyParseError1Test.php index 3869f40a..1997a0e1 100644 --- a/Tests/Utils/ControlStructures/HasBodyParseError1Test.php +++ b/Tests/Utils/ControlStructures/HasBodyParseError1Test.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\ControlStructures::hasBody * - * @group controlstructures - * * @since 1.0.0 */ final class HasBodyParseError1Test extends UtilityMethodTestCase diff --git a/Tests/Utils/ControlStructures/HasBodyParseError2Test.php b/Tests/Utils/ControlStructures/HasBodyParseError2Test.php index 83072b75..781e3ab3 100644 --- a/Tests/Utils/ControlStructures/HasBodyParseError2Test.php +++ b/Tests/Utils/ControlStructures/HasBodyParseError2Test.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\ControlStructures::hasBody * - * @group controlstructures - * * @since 1.0.0 */ final class HasBodyParseError2Test extends UtilityMethodTestCase diff --git a/Tests/Utils/ControlStructures/HasBodyTest.php b/Tests/Utils/ControlStructures/HasBodyTest.php index 9ffc7ca3..6045b290 100644 --- a/Tests/Utils/ControlStructures/HasBodyTest.php +++ b/Tests/Utils/ControlStructures/HasBodyTest.php @@ -19,8 +19,6 @@ * * @covers \PHPCSUtils\Utils\ControlStructures::hasBody * - * @group controlstructures - * * @since 1.0.0 */ final class HasBodyTest extends UtilityMethodTestCase @@ -76,7 +74,7 @@ public function testHasBody($testMarker, $hasBody, $hasNonEmptyBody) * * @see testHasBody() For the array format. * - * @return array + * @return array> */ public static function dataHasBody() { diff --git a/Tests/Utils/ControlStructures/IsElseIfTest.php b/Tests/Utils/ControlStructures/IsElseIfTest.php index 2f292465..9e1869ed 100644 --- a/Tests/Utils/ControlStructures/IsElseIfTest.php +++ b/Tests/Utils/ControlStructures/IsElseIfTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\ControlStructures::isElseIf * - * @group controlstructures - * * @since 1.0.0 */ final class IsElseIfTest extends UtilityMethodTestCase @@ -68,7 +66,7 @@ public function testIsElseIf($testMarker, $expected) * * @see testIsElseIf() For the array format. * - * @return array + * @return array> */ public static function dataIsElseIf() { diff --git a/Tests/Utils/FunctionDeclarations/GetParametersTest.php b/Tests/Utils/FunctionDeclarations/GetParametersTest.php index d0ad91c7..d5bfe22d 100644 --- a/Tests/Utils/FunctionDeclarations/GetParametersTest.php +++ b/Tests/Utils/FunctionDeclarations/GetParametersTest.php @@ -54,8 +54,8 @@ public static function setUpTestFile() * * @dataProvider dataUnexpectedTokenException * - * @param string $commentString The comment which preceeds the test. - * @param array $targetTokenType The token type to search for after $commentString. + * @param string $commentString The comment which preceeds the test. + * @param int|string|array $targetTokenType The token type to search for after $commentString. * * @return void */ @@ -89,9 +89,9 @@ public function testInvalidUse($identifier) * * @dataProvider dataNoParams * - * @param string $commentString The comment which preceeds the test. - * @param array $targetTokenType Optional. The token type to search for after $commentString. - * Defaults to the function/closure/arrow tokens. + * @param string $commentString The comment which preceeds the test. + * @param int|string|array $targetTokenType Optional. The token type to search for after $commentString. + * Defaults to the function/closure/arrow tokens. * * @return void */ @@ -106,10 +106,10 @@ public function testNoParams($commentString, $targetTokenType = [\T_FUNCTION, \T /** * Test helper. * - * @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. + * @param string $marker The comment which preceeds the test. + * @param array> $expected The expected function output. + * @param int|string|array $targetType Optional. The token type to search for after $marker. + * Defaults to the function/closure/arrow tokens. * * @return void */ @@ -125,30 +125,30 @@ protected function getMethodParametersTestHelper($marker, $expected, $targetType /** * 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. + * @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) { foreach ($expected as $key => $param) { $expected[$key]['token'] += $targetPtr; - if ($param['reference_token'] !== false) { + if (\is_int($param['reference_token']) === true) { $expected[$key]['reference_token'] += $targetPtr; } - if ($param['variadic_token'] !== false) { + if (\is_int($param['variadic_token']) === true) { $expected[$key]['variadic_token'] += $targetPtr; } - if ($param['type_hint_token'] !== false) { + if (\is_int($param['type_hint_token']) === true) { $expected[$key]['type_hint_token'] += $targetPtr; } - if ($param['type_hint_end_token'] !== false) { + if (\is_int($param['type_hint_end_token']) === true) { $expected[$key]['type_hint_end_token'] += $targetPtr; } - if ($param['comma_token'] !== false) { + if (\is_int($param['comma_token']) === true) { $expected[$key]['comma_token'] += $targetPtr; } if (isset($param['default_token'])) { @@ -157,7 +157,7 @@ private function updateExpectedTokenPositions($targetPtr, $expected) if (isset($param['default_equal_token'])) { $expected[$key]['default_equal_token'] += $targetPtr; } - if (isset($param['visibility_token']) && $param['visibility_token'] !== false) { + if (isset($param['visibility_token']) && \is_int($param['visibility_token']) === true) { $expected[$key]['visibility_token'] += $targetPtr; } if (isset($param['readonly_token'])) { @@ -178,22 +178,24 @@ 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 = [ + + // Offsets are relative to the T_FUNCTION token. + $expected = [ 0 => [ - 'token' => 7, // Offset from the T_FUNCTION token. + 'token' => 7, '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. + 'default_token' => 11, + 'default_equal_token' => 9, '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. + 'type_hint_token' => 5, + 'type_hint_end_token' => 5, 'nullable_type' => true, 'comma_token' => false, ], diff --git a/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.php b/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.php index f02460f8..4745703f 100644 --- a/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.php +++ b/Tests/Utils/FunctionDeclarations/GetPropertiesDiffTest.php @@ -91,10 +91,10 @@ public function testMessyPhpcsAnnotationsStaticClosure() /** * Test helper. * - * @param string $commentString The comment which preceeds the test. - * @param array $expected The expected function output. - * @param array $targetType Optional. The token type to search for after $commentString. - * Defaults to the function/closure tokens. + * @param string $commentString The comment which preceeds the test. + * @param array $expected The expected function output. + * @param int|string|array $targetType Optional. The token type to search for after $commentString. + * Defaults to the function/closure tokens. * * @return void */ @@ -106,10 +106,11 @@ protected function getPropertiesTestHelper( $function = $this->getTargetToken($commentString, $targetType); $found = FunctionDeclarations::getProperties(self::$phpcsFile, $function); - if ($expected['return_type_token'] !== false) { + // Convert offsets to absolute positions in the token stream. + if (\is_int($expected['return_type_token']) === true) { $expected['return_type_token'] += $function; } - if ($expected['return_type_end_token'] !== false) { + if (\is_int($expected['return_type_end_token']) === true) { $expected['return_type_end_token'] += $function; } diff --git a/Tests/Utils/FunctionDeclarations/GetPropertiesTest.php b/Tests/Utils/FunctionDeclarations/GetPropertiesTest.php index aa0f172e..3f98fd75 100644 --- a/Tests/Utils/FunctionDeclarations/GetPropertiesTest.php +++ b/Tests/Utils/FunctionDeclarations/GetPropertiesTest.php @@ -52,8 +52,8 @@ public static function setUpTestFile() * * @dataProvider dataNotAFunctionException * - * @param string $commentString The comment which preceeds the test. - * @param array $targetTokenType The token type to search for after $commentString. + * @param string $commentString The comment which preceeds the test. + * @param int|string|array $targetTokenType The token type to search for after $commentString. * * @return void */ @@ -68,10 +68,10 @@ public function testNotAFunctionException($commentString, $targetTokenType) /** * Test helper. * - * @param string $commentString The comment which preceeds the test. - * @param array $expected The expected function output. - * @param array $targetType Optional. The token type to search for after $commentString. - * Defaults to the function/closure tokens. + * @param string $commentString The comment which preceeds the test. + * @param array $expected The expected function output. + * @param int|string|array $targetType Optional. The token type to search for after $commentString. + * Defaults to the function/closure tokens. * * @return void */ @@ -83,10 +83,11 @@ protected function getMethodPropertiesTestHelper( $function = $this->getTargetToken($commentString, $targetType); $found = FunctionDeclarations::getProperties(self::$phpcsFile, $function); - if ($expected['return_type_token'] !== false) { + // Convert offsets to absolute positions in the token stream. + if (\is_int($expected['return_type_token']) === true) { $expected['return_type_token'] += $function; } - if ($expected['return_type_end_token'] !== false) { + if (\is_int($expected['return_type_end_token']) === true) { $expected['return_type_end_token'] += $function; } diff --git a/Tests/Utils/FunctionDeclarations/IsMagicFunctionNameTest.php b/Tests/Utils/FunctionDeclarations/IsMagicFunctionNameTest.php index 991c2ff8..779336ce 100644 --- a/Tests/Utils/FunctionDeclarations/IsMagicFunctionNameTest.php +++ b/Tests/Utils/FunctionDeclarations/IsMagicFunctionNameTest.php @@ -44,7 +44,7 @@ public function testIsMagicFunctionName($name) * * @see testIsMagicFunctionName() For the array format. * - * @return array + * @return array> */ public static function dataIsMagicFunctionName() { @@ -74,7 +74,7 @@ public function testIsNotMagicFunctionName($name) * * @see testIsNotMagicFunctionName() For the array format. * - * @return array + * @return array> */ public static function dataIsNotMagicFunctionName() { diff --git a/Tests/Utils/FunctionDeclarations/IsMagicMethodNameTest.php b/Tests/Utils/FunctionDeclarations/IsMagicMethodNameTest.php index 5fa84844..f1887159 100644 --- a/Tests/Utils/FunctionDeclarations/IsMagicMethodNameTest.php +++ b/Tests/Utils/FunctionDeclarations/IsMagicMethodNameTest.php @@ -61,7 +61,7 @@ public function testIsSpecialMethodName($name) * @see testIsMagicMethodName() For the array format. * @see testIsSpecialMethodName() For the array format. * - * @return array + * @return array> */ public static function dataIsMagicMethodName() { @@ -142,7 +142,7 @@ public function testIsNotSpecialMethodName($name) * @see testIsNotMagicMethodName() For the array format. * @see testIsNotSpecialMethodName() For the array format. * - * @return array + * @return array> */ public static function dataIsNotMagicMethodName() { diff --git a/Tests/Utils/FunctionDeclarations/IsPHPDoubleUnderscoreMethodNameTest.php b/Tests/Utils/FunctionDeclarations/IsPHPDoubleUnderscoreMethodNameTest.php index 79e74ad9..4b6fc948 100644 --- a/Tests/Utils/FunctionDeclarations/IsPHPDoubleUnderscoreMethodNameTest.php +++ b/Tests/Utils/FunctionDeclarations/IsPHPDoubleUnderscoreMethodNameTest.php @@ -62,7 +62,7 @@ public function testIsSpecialMethodName($name) * @see testIsPHPDoubleUnderscoreMethodName() For the array format. * @see testIsSpecialMethodName() For the array format. * - * @return array + * @return array> */ public static function dataIsPHPDoubleUnderscoreMethodName() { @@ -133,7 +133,7 @@ public function testIsNotSpecialMethodName($name) * @see testIsNotPHPDoubleUnderscoreMethodName() For the array format. * @see testIsNotSpecialMethodName() For the array format. * - * @return array + * @return array> */ public static function dataIsNotPHPDoubleUnderscoreMethodName() { diff --git a/Tests/Utils/FunctionDeclarations/SpecialFunctionsTest.php b/Tests/Utils/FunctionDeclarations/SpecialFunctionsTest.php index 52f1ee19..1f8cb6dd 100644 --- a/Tests/Utils/FunctionDeclarations/SpecialFunctionsTest.php +++ b/Tests/Utils/FunctionDeclarations/SpecialFunctionsTest.php @@ -86,8 +86,8 @@ public function testNotAFunctionToken() * @dataProvider dataItsAKindOfMagic * @covers ::isMagicFunction * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return values for the various functions. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected return values for the various functions. * * @return void */ @@ -104,8 +104,8 @@ public function testIsMagicFunction($testMarker, $expected) * @dataProvider dataItsAKindOfMagic * @covers ::isMagicMethod * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return values for the various functions. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected return values for the various functions. * * @return void */ @@ -122,8 +122,8 @@ public function testIsMagicMethod($testMarker, $expected) * @dataProvider dataItsAKindOfMagic * @covers ::isPHPDoubleUnderscoreMethod * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return values for the various functions. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected return values for the various functions. * * @return void */ @@ -140,8 +140,8 @@ public function testIsPHPDoubleUnderscoreMethod($testMarker, $expected) * @dataProvider dataItsAKindOfMagic * @covers ::isSpecialMethod * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return values for the various functions. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected return values for the various functions. * * @return void */ @@ -160,7 +160,7 @@ public function testIsSpecialMethod($testMarker, $expected) * @see testIsPHPDoubleUnderscoreMethod() For the array format. * @see testIsSpecialMethod() For the array format. * - * @return array + * @return array>> */ public static function dataItsAKindOfMagic() { diff --git a/Tests/Utils/GetTokensAsString/GetTokensAsStringTest.php b/Tests/Utils/GetTokensAsString/GetTokensAsStringTest.php index 0202545a..ff1dd8f8 100644 --- a/Tests/Utils/GetTokensAsString/GetTokensAsStringTest.php +++ b/Tests/Utils/GetTokensAsString/GetTokensAsStringTest.php @@ -112,11 +112,11 @@ public function testLengthBeyondEndOfFile() /** * Test getting a token set as a string. * - * @dataProvider dataGetTokensAsString() + * @dataProvider dataGetTokensAsString * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $startTokenType The type of token(s) to look for for the start of the string. - * @param array $expected The expected function's return values. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $startTokenType The type of token(s) to look for for the start of the string. + * @param array $expected The expected function's return values. * * @return void */ @@ -132,11 +132,11 @@ public function testNormal($testMarker, $startTokenType, $expected) /** * Test getting a token set as a string with the original content. * - * @dataProvider dataGetTokensAsString() + * @dataProvider dataGetTokensAsString * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $startTokenType The type of token(s) to look for for the start of the string. - * @param array $expected The expected function's return values. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $startTokenType The type of token(s) to look for for the start of the string. + * @param array $expected The expected function's return values. * * @return void */ @@ -152,11 +152,11 @@ public function testOrigContent($testMarker, $startTokenType, $expected) /** * Test getting a token set as a string without comments. * - * @dataProvider dataGetTokensAsString() + * @dataProvider dataGetTokensAsString * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $startTokenType The type of token(s) to look for for the start of the string. - * @param array $expected The expected function's return values. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $startTokenType The type of token(s) to look for for the start of the string. + * @param array $expected The expected function's return values. * * @return void */ @@ -172,11 +172,11 @@ public function testNoComments($testMarker, $startTokenType, $expected) /** * Test getting a token set as a string without comments or whitespace. * - * @dataProvider dataGetTokensAsString() + * @dataProvider dataGetTokensAsString * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $startTokenType The type of token(s) to look for for the start of the string. - * @param array $expected The expected function's return values. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $startTokenType The type of token(s) to look for for the start of the string. + * @param array $expected The expected function's return values. * * @return void */ @@ -192,11 +192,11 @@ public function testNoEmpties($testMarker, $startTokenType, $expected) /** * Test getting a token set as a string with compacted whitespace. * - * @dataProvider dataGetTokensAsString() + * @dataProvider dataGetTokensAsString * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $startTokenType The type of token(s) to look for for the start of the string. - * @param array $expected The expected function's return values. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $startTokenType The type of token(s) to look for for the start of the string. + * @param array $expected The expected function's return values. * * @return void */ @@ -212,11 +212,11 @@ public function testCompact($testMarker, $startTokenType, $expected) /** * Test getting a token set as a string without comments and with compacted whitespace. * - * @dataProvider dataGetTokensAsString() + * @dataProvider dataGetTokensAsString * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $startTokenType The type of token(s) to look for for the start of the string. - * @param array $expected The expected function's return values. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $startTokenType The type of token(s) to look for for the start of the string. + * @param array $expected The expected function's return values. * * @return void */ @@ -239,15 +239,15 @@ public function testCompactNoComments($testMarker, $startTokenType, $expected) * @see testCompact() For the array format. * @see testCompactNoComments() For the array format. * - * @return array + * @return array>> */ public static function dataGetTokensAsString() { return [ 'namespace' => [ - 'marker' => '/* testNamespace */', - 'type' => \T_NAMESPACE, - 'expected' => [ + 'testMarker' => '/* testNamespace */', + 'startTokenType' => \T_NAMESPACE, + 'expected' => [ 'tab_replaced' => 'namespace Foo\Bar\Baz;', 'orig' => 'namespace Foo\Bar\Baz;', 'no_comments' => 'namespace Foo\Bar\Baz;', @@ -257,9 +257,9 @@ public static function dataGetTokensAsString() ], ], 'use-with-comments' => [ - 'marker' => '/* testUseWithComments */', - 'type' => \T_STRING, - 'expected' => [ + 'testMarker' => '/* testUseWithComments */', + 'startTokenType' => \T_STRING, + 'expected' => [ 'tab_replaced' => 'Foo /*comment*/ \ Bar // phpcs:ignore Stnd.Cat.Sniff -- For reasons. \ Bah;', @@ -275,9 +275,9 @@ public static function dataGetTokensAsString() ], ], 'calculation' => [ - 'marker' => '/* testCalculation */', - 'type' => \T_LNUMBER, - 'expected' => [ + 'testMarker' => '/* testCalculation */', + 'startTokenType' => \T_LNUMBER, + 'expected' => [ 'tab_replaced' => '1 + 2 + // Comment. 3 + 4 @@ -296,9 +296,9 @@ public static function dataGetTokensAsString() ], ], 'echo-with-tabs' => [ - 'marker' => '/* testEchoWithTabs */', - 'type' => \T_ECHO, - 'expected' => [ + 'testMarker' => '/* testEchoWithTabs */', + 'startTokenType' => \T_ECHO, + 'expected' => [ 'tab_replaced' => 'echo \'foo\', \'bar\' , \'baz\';', @@ -314,9 +314,9 @@ public static function dataGetTokensAsString() ], ], 'end-of-file' => [ - 'marker' => '/* testEndOfFile */', - 'type' => \T_ECHO, - 'expected' => [ + 'testMarker' => '/* testEndOfFile */', + 'startTokenType' => \T_ECHO, + 'expected' => [ 'tab_replaced' => 'echo $foo;', 'orig' => 'echo $foo;', 'no_comments' => 'echo $foo;', diff --git a/Tests/Utils/Lists/GetAssignmentsTest.php b/Tests/Utils/Lists/GetAssignmentsTest.php index ee799080..33b8882d 100644 --- a/Tests/Utils/Lists/GetAssignmentsTest.php +++ b/Tests/Utils/Lists/GetAssignmentsTest.php @@ -20,8 +20,6 @@ * * @covers \PHPCSUtils\Utils\Lists::getAssignments * - * @group lists - * * @since 1.0.0 */ final class GetAssignmentsTest extends UtilityMethodTestCase diff --git a/Tests/Utils/Lists/GetOpenCloseTest.php b/Tests/Utils/Lists/GetOpenCloseTest.php index d169af39..cfe5a440 100644 --- a/Tests/Utils/Lists/GetOpenCloseTest.php +++ b/Tests/Utils/Lists/GetOpenCloseTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Lists::getOpenClose * - * @group lists - * * @since 1.0.0 */ final class GetOpenCloseTest extends UtilityMethodTestCase @@ -40,8 +38,8 @@ public function testNonExistentToken() * * @dataProvider dataNotListOpenToken * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetToken The token type(s) to look for. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetToken The token type(s) to look for. * * @return void */ @@ -56,7 +54,7 @@ public function testNotListOpenToken($testMarker, $targetToken) * * @see testNotListOpenToken() For the array format. * - * @return array + * @return array> */ public static function dataNotListOpenToken() { @@ -89,9 +87,9 @@ public static function dataNotListOpenToken() * * @dataProvider dataGetOpenClose * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetToken The token type(s) to look for. - * @param array|false $expected The expected function return value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string $targetToken The token type(s) to look for. + * @param array|false $expected The expected function return value. * * @return void */ @@ -116,7 +114,7 @@ public function testGetOpenClose($testMarker, $targetToken, $expected) * * @see testGetOpenClose() For the array format. * - * @return array + * @return array|false>> */ public static function dataGetOpenClose() { diff --git a/Tests/Utils/MessageHelper/AddMessageTest.php b/Tests/Utils/MessageHelper/AddMessageTest.php index 5dd7a969..d9a4d402 100644 --- a/Tests/Utils/MessageHelper/AddMessageTest.php +++ b/Tests/Utils/MessageHelper/AddMessageTest.php @@ -22,8 +22,6 @@ * * @coversDefaultClass \PHPCSUtils\Utils\MessageHelper * - * @group messagehelper - * * @since 1.0.0 */ final class AddMessageTest extends UtilityMethodTestCase @@ -41,7 +39,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 string[] + * @var array */ protected static $selectedSniff = ['PHPCSUtils.MessageHelper.AddMessageTest']; @@ -232,9 +230,6 @@ protected function verifyRecordedMessages($stackPtr, $isError, $expected) $violation = $messages[0]; - // PHPCS 2.x places `unknownSniff.` before the actual error code for utility tests with a dummy error code. - $violation['source'] = \str_replace('unknownSniff.', '', $violation['source']); - /* * Test the violation details. */ diff --git a/Tests/Utils/MessageHelper/ShowEscapeCharsTest.php b/Tests/Utils/MessageHelper/ShowEscapeCharsTest.php index 726e3ae7..e8cc8cb3 100644 --- a/Tests/Utils/MessageHelper/ShowEscapeCharsTest.php +++ b/Tests/Utils/MessageHelper/ShowEscapeCharsTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\MessageHelper::showEscapeChars * - * @group messagehelper - * * @since 1.0.0 */ final class ShowEscapeCharsTest extends TestCase @@ -45,7 +43,7 @@ public function testShowEscapeChars($input, $expected) * * @see testShowEscapeChars() For the array format. * - * @return array + * @return array> */ public static function dataShowEscapeChars() { diff --git a/Tests/Utils/MessageHelper/StringToErrorcodeTest.php b/Tests/Utils/MessageHelper/StringToErrorcodeTest.php index d42750b6..1dddabba 100644 --- a/Tests/Utils/MessageHelper/StringToErrorcodeTest.php +++ b/Tests/Utils/MessageHelper/StringToErrorcodeTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\MessageHelper::stringToErrorcode * - * @group messagehelper - * * @since 1.0.0 */ final class StringToErrorcodeTest extends TestCase @@ -45,7 +43,7 @@ public function testStringToErrorCode($input, $expected) * * @see testStringToErrorCode() For the array format. * - * @return array + * @return array> */ public static function dataStringToErrorCode() { @@ -97,7 +95,7 @@ public function testStringToErrorCodeWithCaseChange($input, $expected) * * @see testStringToErrorCode() For the array format. * - * @return array + * @return array> */ public static function dataStringToErrorCodeWithCaseChange() { diff --git a/Tests/Utils/Namespaces/DetermineNamespaceTest.php b/Tests/Utils/Namespaces/DetermineNamespaceTest.php index c00ee201..1028039e 100644 --- a/Tests/Utils/Namespaces/DetermineNamespaceTest.php +++ b/Tests/Utils/Namespaces/DetermineNamespaceTest.php @@ -21,8 +21,6 @@ * @covers \PHPCSUtils\Utils\Namespaces::findNamespacePtr * @covers \PHPCSUtils\Utils\Namespaces::determineNamespace * - * @group namespaces - * * @since 1.0.0 */ final class DetermineNamespaceTest extends UtilityMethodTestCase @@ -43,8 +41,8 @@ public function testInvalidTokenPassed() * * @dataProvider dataDetermineNamespace * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected output for the functions. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected output for the functions. * * @return void */ @@ -66,8 +64,8 @@ public function testFindNamespacePtr($testMarker, $expected) * * @dataProvider dataDetermineNamespace * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected output for the functions. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected output for the functions. * * @return void */ @@ -84,7 +82,7 @@ public function testDetermineNamespace($testMarker, $expected) * * @see testDetermineNamespace() For the array format. * - * @return array + * @return array>> */ public static function dataDetermineNamespace() { diff --git a/Tests/Utils/Namespaces/GetDeclaredNameTest.php b/Tests/Utils/Namespaces/GetDeclaredNameTest.php index ae61faad..eafa1dfd 100644 --- a/Tests/Utils/Namespaces/GetDeclaredNameTest.php +++ b/Tests/Utils/Namespaces/GetDeclaredNameTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Namespaces::getDeclaredName * - * @group namespaces - * * @since 1.0.0 */ final class GetDeclaredNameTest extends UtilityMethodTestCase @@ -44,11 +42,11 @@ public function testInvalidTokenPassed() * * @dataProvider dataGetDeclaredName * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected output for the function. - * @param bool $skipOnPHP8 Optional. Whether the test should be skipped when the PHP 8 identifier - * name tokenization is used (as the target token won't exist). - * Defaults to `false`. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected output for the function. + * @param bool $skipOnPHP8 Optional. Whether the test should be skipped when the + * PHP 8 identifier name tokenization is used (as the target token + * won't exist). Defaults to `false`. * * @return void */ @@ -69,11 +67,11 @@ public function testGetDeclaredNameClean($testMarker, $expected, $skipOnPHP8 = f * * @dataProvider dataGetDeclaredName * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected output for the function. - * @param bool $skipOnPHP8 Optional. Whether the test should be skipped when the PHP 8 identifier - * name tokenization is used (as the target token won't exist). - * Defaults to `false`. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected output for the function. + * @param bool $skipOnPHP8 Optional. Whether the test should be skipped when the + * PHP 8 identifier name tokenization is used (as the target token + * won't exist). Defaults to `false`. * * @return void */ @@ -94,7 +92,7 @@ public function testGetDeclaredNameDirty($testMarker, $expected, $skipOnPHP8 = f * * @see testGetDeclaredName() For the array format. * - * @return array + * @return array|bool>> */ public static function dataGetDeclaredName() { diff --git a/Tests/Utils/Namespaces/NamespaceTypeTest.php b/Tests/Utils/Namespaces/NamespaceTypeTest.php index c79dad58..4ebbfb46 100644 --- a/Tests/Utils/Namespaces/NamespaceTypeTest.php +++ b/Tests/Utils/Namespaces/NamespaceTypeTest.php @@ -22,8 +22,6 @@ * @covers \PHPCSUtils\Utils\Namespaces::isOperator * @covers \PHPCSUtils\Utils\Namespaces::getType * - * @group namespaces - * * @since 1.0.0 */ final class NamespaceTypeTest extends UtilityMethodTestCase @@ -58,11 +56,11 @@ public function testNonNamespaceToken() * * @dataProvider dataNamespaceType * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected output for the functions. - * @param bool $skipOnPHP8 Optional. Whether the test should be skipped when the PHP 8 identifier - * name tokenization is used (as the target token won't exist). - * Defaults to `false`. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected output for the functions. + * @param bool $skipOnPHP8 Optional. Whether the test should be skipped when the PHP 8 identifier + * name tokenization is used (as the target token won't exist). + * Defaults to `false`. * * @return void */ @@ -83,11 +81,11 @@ public function testIsDeclaration($testMarker, $expected, $skipOnPHP8 = false) * * @dataProvider dataNamespaceType * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected output for the functions. - * @param bool $skipOnPHP8 Optional. Whether the test should be skipped when the PHP 8 identifier - * name tokenization is used (as the target token won't exist). - * Defaults to `false`. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected output for the functions. + * @param bool $skipOnPHP8 Optional. Whether the test should be skipped when the PHP 8 identifier + * name tokenization is used (as the target token won't exist). + * Defaults to `false`. * * @return void */ @@ -109,7 +107,7 @@ public function testIsOperator($testMarker, $expected, $skipOnPHP8 = false) * @see testIsDeclaration() For the array format. * @see testIsOperator() For the array format. * - * @return array + * @return array|true>> */ public static function dataNamespaceType() { diff --git a/Tests/Utils/NamingConventions/IsEqualTest.php b/Tests/Utils/NamingConventions/IsEqualTest.php index d5f7e767..81d9c9b6 100644 --- a/Tests/Utils/NamingConventions/IsEqualTest.php +++ b/Tests/Utils/NamingConventions/IsEqualTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\NamingConventions::isEqual * - * @group namingconventions - * * @since 1.0.0 */ final class IsEqualTest extends TestCase @@ -32,7 +30,7 @@ final class IsEqualTest extends TestCase * * @param string $inputA The first name. * @param string $inputB The second name. - * @param array $expected The expected function output. + * @param bool $expected The expected function output. * * @return void */ @@ -46,7 +44,7 @@ public function testIsEqual($inputA, $inputB, $expected) * * @see testIsEqual() For the array format. * - * @return array + * @return array> */ public static function dataIsEqual() { diff --git a/Tests/Utils/NamingConventions/IsValidIdentifierNameTest.php b/Tests/Utils/NamingConventions/IsValidIdentifierNameTest.php index 9db7fca2..fa5d924e 100644 --- a/Tests/Utils/NamingConventions/IsValidIdentifierNameTest.php +++ b/Tests/Utils/NamingConventions/IsValidIdentifierNameTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\NamingConventions::isValidIdentifierName * - * @group namingconventions - * * @since 1.0.0 */ final class IsValidIdentifierNameTest extends TestCase @@ -31,7 +29,7 @@ final class IsValidIdentifierNameTest extends TestCase * @dataProvider dataIsValidIdentifierName * * @param string $input The input string. - * @param array $expected The expected function output. + * @param bool $expected The expected function output. * * @return void */ @@ -45,7 +43,7 @@ public function testIsValidIdentifierName($input, $expected) * * @see testIsValidIdentifierName() For the array format. * - * @return array + * @return array> */ public static function dataIsValidIdentifierName() { diff --git a/Tests/Utils/Numbers/GetCompleteNumberTest.php b/Tests/Utils/Numbers/GetCompleteNumberTest.php index 55173dad..e1e95a19 100644 --- a/Tests/Utils/Numbers/GetCompleteNumberTest.php +++ b/Tests/Utils/Numbers/GetCompleteNumberTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Numbers::getCompleteNumber * - * @group numbers - * * @since 1.0.0 */ final class GetCompleteNumberTest extends UtilityMethodTestCase @@ -43,8 +41,8 @@ public function testNotANumberException() * * @dataProvider dataGetCompleteNumber * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected Expected function return value. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected Expected function return value. * * @return void */ @@ -68,7 +66,7 @@ public function testGetCompleteNumber($testMarker, $expected) * * @see testGetCompleteNumber() For the array format. * - * @return array + * @return array>> */ public static function dataGetCompleteNumber() { diff --git a/Tests/Utils/Numbers/GetDecimalValueTest.php b/Tests/Utils/Numbers/GetDecimalValueTest.php index 11f82e88..ff601f76 100644 --- a/Tests/Utils/Numbers/GetDecimalValueTest.php +++ b/Tests/Utils/Numbers/GetDecimalValueTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Numbers::getDecimalValue * - * @group numbers - * * @since 1.0.0 */ final class GetDecimalValueTest extends TestCase @@ -45,7 +43,7 @@ public function testGetDecimalValue($input, $expected) * * @see testGetDecimalValue() For the array format. * - * @return array + * @return array> */ public static function dataGetDecimalValue() { @@ -94,7 +92,7 @@ public static function dataGetDecimalValue() * * @dataProvider dataGetDecimalValueInvalid * - * @param string $input The input string. + * @param mixed $input The input value. * * @return void */ @@ -108,7 +106,7 @@ public function testGetDecimalValueInvalid($input) * * @see testGetDecimalValueInvalid() For the array format. * - * @return array + * @return array> */ public static function dataGetDecimalValueInvalid() { diff --git a/Tests/Utils/Numbers/NumberTypesTest.php b/Tests/Utils/Numbers/NumberTypesTest.php index 960dbbe1..becf2f91 100644 --- a/Tests/Utils/Numbers/NumberTypesTest.php +++ b/Tests/Utils/Numbers/NumberTypesTest.php @@ -22,8 +22,6 @@ * * @coversDefaultClass \PHPCSUtils\Utils\Numbers * - * @group numbers - * * @since 1.0.0 */ final class NumberTypesTest extends TestCase diff --git a/Tests/Utils/ObjectDeclarations/FindExtendedClassNameDiffTest.php b/Tests/Utils/ObjectDeclarations/FindExtendedClassNameDiffTest.php index ddaa3a18..c6b0d603 100644 --- a/Tests/Utils/ObjectDeclarations/FindExtendedClassNameDiffTest.php +++ b/Tests/Utils/ObjectDeclarations/FindExtendedClassNameDiffTest.php @@ -34,8 +34,8 @@ final class FindExtendedClassNameDiffTest extends UtilityMethodTestCase * * @dataProvider dataFindExtendedClassName * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param bool $expected Expected function output. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string|false $expected Expected function output. * * @return void */ @@ -51,7 +51,7 @@ public function testFindExtendedClassName($testMarker, $expected) * * @see testFindExtendedClassName() For the array format. * - * @return array + * @return array> */ public static function dataFindExtendedClassName() { diff --git a/Tests/Utils/ObjectDeclarations/FindExtendedInterfaceNamesTest.php b/Tests/Utils/ObjectDeclarations/FindExtendedInterfaceNamesTest.php index 4d927f5d..7a942dc7 100644 --- a/Tests/Utils/ObjectDeclarations/FindExtendedInterfaceNamesTest.php +++ b/Tests/Utils/ObjectDeclarations/FindExtendedInterfaceNamesTest.php @@ -54,8 +54,8 @@ public function testNotAnInterface() * * @dataProvider dataFindExtendedInterfaceNames * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array|false $expected Expected function output. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array|false $expected Expected function output. * * @return void */ @@ -71,7 +71,7 @@ public function testFindExtendedInterfaceNames($testMarker, $expected) * * @see testFindExtendedInterfaceNames() For the array format. * - * @return array + * @return array|false>> */ public static function dataFindExtendedInterfaceNames() { diff --git a/Tests/Utils/ObjectDeclarations/FindImplementedInterfaceNamesDiffTest.php b/Tests/Utils/ObjectDeclarations/FindImplementedInterfaceNamesDiffTest.php index 68bba35c..201f018d 100644 --- a/Tests/Utils/ObjectDeclarations/FindImplementedInterfaceNamesDiffTest.php +++ b/Tests/Utils/ObjectDeclarations/FindImplementedInterfaceNamesDiffTest.php @@ -34,8 +34,8 @@ final class FindImplementedInterfaceNamesDiffTest extends UtilityMethodTestCase * * @dataProvider dataFindImplementedInterfaceNames * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param bool $expected Expected function output. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array|false $expected Expected function output. * * @return void */ @@ -51,7 +51,7 @@ public function testFindImplementedInterfaceNames($testMarker, $expected) * * @see testFindImplementedInterfaceNames() For the array format. * - * @return array + * @return array|false>> */ public static function dataFindImplementedInterfaceNames() { diff --git a/Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.php b/Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.php index 85ce83ba..0cdf2569 100644 --- a/Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.php +++ b/Tests/Utils/ObjectDeclarations/GetClassPropertiesDiffTest.php @@ -45,8 +45,8 @@ public function testNonExistentToken() * * @dataProvider dataGetClassProperties * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected Expected function output. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected Expected function output. * * @return void */ @@ -55,13 +55,13 @@ public function testGetClassProperties($testMarker, $expected) $class = $this->getTargetToken($testMarker, \T_CLASS); // Translate offsets to absolute token positions. - if ($expected['abstract_token'] !== false) { + if (\is_int($expected['abstract_token']) === true) { $expected['abstract_token'] += $class; } - if ($expected['final_token'] !== false) { + if (\is_int($expected['final_token']) === true) { $expected['final_token'] += $class; } - if ($expected['readonly_token'] !== false) { + if (\is_int($expected['readonly_token']) === true) { $expected['readonly_token'] += $class; } @@ -74,7 +74,7 @@ public function testGetClassProperties($testMarker, $expected) * * @see testGetClassProperties() For the array format. * - * @return array + * @return array>> */ public static function dataGetClassProperties() { diff --git a/Tests/Utils/ObjectDeclarations/GetClassPropertiesTest.php b/Tests/Utils/ObjectDeclarations/GetClassPropertiesTest.php index 4d502378..978a909f 100644 --- a/Tests/Utils/ObjectDeclarations/GetClassPropertiesTest.php +++ b/Tests/Utils/ObjectDeclarations/GetClassPropertiesTest.php @@ -62,8 +62,8 @@ public static function setUpTestFile() * * @dataProvider dataGetClassProperties * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected Expected function output. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected Expected function output. * * @return void */ @@ -72,13 +72,13 @@ public function testGetClassProperties($testMarker, $expected) $class = $this->getTargetToken($testMarker, \T_CLASS); // Translate offsets to absolute token positions. - if ($expected['abstract_token'] !== false) { + if (\is_int($expected['abstract_token']) === true) { $expected['abstract_token'] += $class; } - if ($expected['final_token'] !== false) { + if (\is_int($expected['final_token']) === true) { $expected['final_token'] += $class; } - if ($expected['readonly_token'] !== false) { + if (\is_int($expected['readonly_token']) === true) { $expected['readonly_token'] += $class; } diff --git a/Tests/Utils/ObjectDeclarations/GetNameDiffTest.php b/Tests/Utils/ObjectDeclarations/GetNameDiffTest.php index f30d9549..de4f67ee 100644 --- a/Tests/Utils/ObjectDeclarations/GetNameDiffTest.php +++ b/Tests/Utils/ObjectDeclarations/GetNameDiffTest.php @@ -61,7 +61,7 @@ public function testGetNameNull($testMarker, $targetType) * * @see testGetNameNull() For the array format. * - * @return array + * @return array> */ public static function dataGetNameNull() { @@ -78,9 +78,9 @@ public static function dataGetNameNull() * * @dataProvider dataGetName * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param string $expected Expected function output. - * @param int|string $targetType Token type of the token to get as stackPtr. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expected Expected function output. + * @param int|string|null $targetType Token type of the token to get as stackPtr. * * @return void */ @@ -100,7 +100,7 @@ public function testGetName($testMarker, $expected, $targetType = null) * * @see testGetName() For the array format. * - * @return array + * @return array> */ public static function dataGetName() { diff --git a/Tests/Utils/ObjectDeclarations/GetNameJSTest.php b/Tests/Utils/ObjectDeclarations/GetNameJSTest.php index 875761bd..155f9189 100644 --- a/Tests/Utils/ObjectDeclarations/GetNameJSTest.php +++ b/Tests/Utils/ObjectDeclarations/GetNameJSTest.php @@ -86,9 +86,9 @@ public function testGetDeclarationNameNull($testMarker, $targetType) * * @dataProvider dataGetDeclarationName * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param string $expected Expected function output. - * @param int|string $targetType Token type of the token to get as stackPtr. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expected Expected function output. + * @param array|null $targetType Token type of the token to get as stackPtr. * * @return void */ diff --git a/Tests/Utils/ObjectDeclarations/GetNameTest.php b/Tests/Utils/ObjectDeclarations/GetNameTest.php index eb1e1509..074cdf7c 100644 --- a/Tests/Utils/ObjectDeclarations/GetNameTest.php +++ b/Tests/Utils/ObjectDeclarations/GetNameTest.php @@ -86,9 +86,9 @@ public function testGetDeclarationNameNull($testMarker, $targetType) * * @dataProvider dataGetDeclarationName * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param string $expected Expected function output. - * @param int|string $targetType Token type of the token to get as stackPtr. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expected Expected function output. + * @param int|string|null $targetType Token type of the token to get as stackPtr. * * @return void */ diff --git a/Tests/Utils/Operators/IsShortTernaryTest.php b/Tests/Utils/Operators/IsShortTernaryTest.php index 7dfee745..22674560 100644 --- a/Tests/Utils/Operators/IsShortTernaryTest.php +++ b/Tests/Utils/Operators/IsShortTernaryTest.php @@ -72,7 +72,7 @@ public function testIsShortTernary($testMarker, $expected) * * @see testIsShortTernary() For the array format. * - * @return array + * @return array> */ public static function dataIsShortTernary() { diff --git a/Tests/Utils/Operators/IsUnaryPlusMinusJSTest.php b/Tests/Utils/Operators/IsUnaryPlusMinusJSTest.php index 8b52d441..5df83917 100644 --- a/Tests/Utils/Operators/IsUnaryPlusMinusJSTest.php +++ b/Tests/Utils/Operators/IsUnaryPlusMinusJSTest.php @@ -36,7 +36,7 @@ final class IsUnaryPlusMinusJSTest extends IsUnaryPlusMinusTestCase * * @see IsUnaryPlusMinusTest::testIsUnaryPlusMinus() For the array format. * - * @return array + * @return array> */ public static function dataIsUnaryPlusMinus() { diff --git a/Tests/Utils/Operators/IsUnaryPlusMinusTest.php b/Tests/Utils/Operators/IsUnaryPlusMinusTest.php index 45d4c842..3c8d7ef0 100644 --- a/Tests/Utils/Operators/IsUnaryPlusMinusTest.php +++ b/Tests/Utils/Operators/IsUnaryPlusMinusTest.php @@ -29,7 +29,7 @@ final class IsUnaryPlusMinusTest extends IsUnaryPlusMinusTestCase * * @see testIsUnaryPlusMinus() For the array format. * - * @return array + * @return array> */ public static function dataIsUnaryPlusMinus() { diff --git a/Tests/Utils/Operators/IsUnaryPlusMinusTestCase.php b/Tests/Utils/Operators/IsUnaryPlusMinusTestCase.php index 705caafb..00bacf61 100644 --- a/Tests/Utils/Operators/IsUnaryPlusMinusTestCase.php +++ b/Tests/Utils/Operators/IsUnaryPlusMinusTestCase.php @@ -71,7 +71,7 @@ public function testIsUnaryPlusMinus($testMarker, $expected) * * @see testIsUnaryPlusMinus() For the array format. * - * @return array + * @return array> */ abstract public static function dataIsUnaryPlusMinus(); } diff --git a/Tests/Utils/Orthography/FirstCharTest.php b/Tests/Utils/Orthography/FirstCharTest.php index b8d17497..06405e24 100644 --- a/Tests/Utils/Orthography/FirstCharTest.php +++ b/Tests/Utils/Orthography/FirstCharTest.php @@ -20,8 +20,6 @@ * @covers \PHPCSUtils\Utils\Orthography::isFirstCharCapitalized * @covers \PHPCSUtils\Utils\Orthography::isFirstCharLowercase * - * @group orthography - * * @since 1.0.0 */ final class FirstCharTest extends TestCase @@ -32,8 +30,8 @@ final class FirstCharTest extends TestCase * * @dataProvider dataFirstChar * - * @param string $input The input string. - * @param array $expected The expected function output for the respective functions. + * @param string $input The input string. + * @param array $expected The expected function output for the respective functions. * * @return void */ @@ -47,8 +45,8 @@ public function testIsFirstCharCapitalized($input, $expected) * * @dataProvider dataFirstChar * - * @param string $input The input string. - * @param array $expected The expected function output for the respective functions. + * @param string $input The input string. + * @param array $expected The expected function output for the respective functions. * * @return void */ @@ -63,7 +61,7 @@ public function testIsFirstCharLowercase($input, $expected) * @see testIsFirstCharCapitalized() For the array format. * @see testIsFirstCharLowercase() For the array format. * - * @return array + * @return array>> */ public static function dataFirstChar() { diff --git a/Tests/Utils/Orthography/IsLastCharPunctuationTest.php b/Tests/Utils/Orthography/IsLastCharPunctuationTest.php index ab5ce131..b148fde1 100644 --- a/Tests/Utils/Orthography/IsLastCharPunctuationTest.php +++ b/Tests/Utils/Orthography/IsLastCharPunctuationTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\Orthography::isLastCharPunctuation * - * @group orthography - * * @since 1.0.0 */ final class IsLastCharPunctuationTest extends TestCase @@ -52,7 +50,7 @@ public function testIsLastCharPunctuation($input, $expected, $allowedChars = nul * * @see testIsLastCharPunctuation() For the array format. * - * @return array + * @return array> */ public static function dataIsLastCharPunctuation() { diff --git a/Tests/Utils/Parentheses/ParenthesesTest.php b/Tests/Utils/Parentheses/ParenthesesTest.php index 5028607c..46efa8fa 100644 --- a/Tests/Utils/Parentheses/ParenthesesTest.php +++ b/Tests/Utils/Parentheses/ParenthesesTest.php @@ -19,8 +19,6 @@ * * @covers \PHPCSUtils\Utils\Parentheses * - * @group parentheses - * * @since 1.0.0 */ final class ParenthesesTest extends UtilityMethodTestCase diff --git a/Tests/Utils/PassedParameters/GetParameterCountTest.php b/Tests/Utils/PassedParameters/GetParameterCountTest.php index 9edf8fe4..8800c34e 100644 --- a/Tests/Utils/PassedParameters/GetParameterCountTest.php +++ b/Tests/Utils/PassedParameters/GetParameterCountTest.php @@ -21,8 +21,6 @@ * @covers \PHPCSUtils\Utils\PassedParameters::getParameters * @covers \PHPCSUtils\Utils\PassedParameters::hasParameters * - * @group passedparameters - * * @since 1.0.0 */ final class GetParameterCountTest extends UtilityMethodTestCase @@ -33,10 +31,10 @@ final class GetParameterCountTest extends UtilityMethodTestCase * * @dataProvider dataGetParameterCount * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int $expected The expected parameter count. - * @param string $targetContent Optional. The content of the target token to find. - * Defaults to null (ignore content). + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int $expected The expected parameter count. + * @param string|null $targetContent Optional. The content of the target token to find. + * Defaults to null (ignore content). * * @return void */ @@ -58,7 +56,7 @@ public function testGetParameterCount($testMarker, $expected, $targetContent = n * * @see testGetParameterCount() For the array format. * - * @return array + * @return array> */ public static function dataGetParameterCount() { diff --git a/Tests/Utils/PassedParameters/GetParameterFromStackTest.php b/Tests/Utils/PassedParameters/GetParameterFromStackTest.php index 878772fa..b146603c 100644 --- a/Tests/Utils/PassedParameters/GetParameterFromStackTest.php +++ b/Tests/Utils/PassedParameters/GetParameterFromStackTest.php @@ -21,8 +21,6 @@ * @covers \PHPCSUtils\Utils\PassedParameters::getParameter * @covers \PHPCSUtils\Utils\PassedParameters::getParameterFromStack * - * @group passedparameters - * * @since 1.0.0 */ final class GetParameterFromStackTest extends UtilityMethodTestCase @@ -71,7 +69,7 @@ public function testGetParameterNonFunctionCallNoParamName($testMarker, $targetT * * @see testGetParameterNonFunctionCallNoParamName() For the array format. * - * @return array + * @return array> */ public static function dataGetParameterNonFunctionCallNoParamName() { @@ -148,8 +146,8 @@ public function testGetParameterFunctionCallPositionalMissingParamNameNonExisten * * @dataProvider dataGetParameterFunctionCallWithParamName * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected function output. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected function output. * * @return void */ @@ -173,7 +171,7 @@ public function testGetParameterFunctionCallWithParamName($testMarker, $expected * * @see testGetParameterFunctionCallWithParamName() For the array format. * - * @return array + * @return array>> */ public static function dataGetParameterFunctionCallWithParamName() { diff --git a/Tests/Utils/PassedParameters/GetParametersNamedTest.php b/Tests/Utils/PassedParameters/GetParametersNamedTest.php index 31fdce68..2ea5be1c 100644 --- a/Tests/Utils/PassedParameters/GetParametersNamedTest.php +++ b/Tests/Utils/PassedParameters/GetParametersNamedTest.php @@ -23,8 +23,6 @@ * @covers \PHPCSUtils\Utils\PassedParameters::getParameterFromStack * @covers \PHPCSUtils\Utils\PassedParameters::hasParameters * - * @group passedparameters - * * @since 1.0.0 */ final class GetParametersNamedTest extends UtilityMethodTestCase diff --git a/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php b/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php index 786bf7b3..b3ae65ac 100644 --- a/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php +++ b/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php @@ -22,8 +22,6 @@ * @covers \PHPCSUtils\Utils\PassedParameters::hasParameters * @covers \PHPCSUtils\Utils\PassedParameters::getParameters * - * @group passedparameters - * * @since 1.0.0 */ final class GetParametersSkipShortArrayCheckTest extends PolyfilledTestCase @@ -35,7 +33,7 @@ final class GetParametersSkipShortArrayCheckTest extends PolyfilledTestCase * * Also verify that for valid constructs, the method still behaves like normal. * - * @dataProvider dataTestCases + * @dataProvider dataHasParametersDontSkipShortArrayCheck * * @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. @@ -58,20 +56,37 @@ public function testHasParametersDontSkipShortArrayCheck($testMarker, $targetTyp $this->assertIsBool($hasParams); } + /** + * Data provider. + * + * @see testHasParametersDontSkipShortArrayCheck() For the array format. + * + * @return array + */ + public static function dataHasParametersDontSkipShortArrayCheck() + { + $data = self::dataTestCases(); + + foreach ($data as $name => $dataset) { + unset($data[$name]['expected']); + } + + return $data; + } + /** * Test retrieving the parameter details for valid and invalid constructs when the * `$isShortArray` parameter is set to TRUE. * - * @dataProvider dataTestCases + * @dataProvider dataGetParametersSkipShortArrayCheck * * @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 bool $ignore Not used in this test. * @param array $expected The expected return value. * * @return void */ - public function testGetParametersSkipShortArrayCheck($testMarker, $targetType, $ignore, $expected) + public function testGetParametersSkipShortArrayCheck($testMarker, $targetType, $expected) { /* * Expect an exception on PHPCS versions when square brackets will never be a short array. @@ -105,6 +120,24 @@ public function testGetParametersSkipShortArrayCheck($testMarker, $targetType, $ $this->assertSame($expected, $result); } + /** + * Data provider. + * + * @see testGetParametersSkipShortArrayCheck() For the array format. + * + * @return array + */ + public static function dataGetParametersSkipShortArrayCheck() + { + $data = self::dataTestCases(); + + foreach ($data as $name => $dataset) { + unset($data[$name]['expectException']); + } + + return $data; + } + /** * Data provider. * @@ -117,16 +150,16 @@ public static function dataTestCases() { return [ 'no-params' => [ - 'testMarker' => '/* testNoParams */', - 'targetType' => \T_OPEN_SHORT_ARRAY, - 'ignore' => false, - 'expected' => [], + 'testMarker' => '/* testNoParams */', + 'targetType' => \T_OPEN_SHORT_ARRAY, + 'expectException' => false, + 'expected' => [], ], 'long-array' => [ - 'testMarker' => '/* testLongArray */', - 'targetType' => \T_ARRAY, - 'ignore' => false, - 'expected' => [ + 'testMarker' => '/* testLongArray */', + 'targetType' => \T_ARRAY, + 'expectException' => false, + 'expected' => [ 1 => [ 'start' => 2, 'end' => 3, @@ -140,10 +173,10 @@ public static function dataTestCases() ], ], 'short-array' => [ - 'testMarker' => '/* testShortArray */', - 'targetType' => \T_OPEN_SHORT_ARRAY, - 'ignore' => false, - 'expected' => [ + 'testMarker' => '/* testShortArray */', + 'targetType' => \T_OPEN_SHORT_ARRAY, + 'expectException' => false, + 'expected' => [ 1 => [ 'start' => 1, 'end' => 6, @@ -157,10 +190,10 @@ public static function dataTestCases() ], ], 'short-list' => [ - 'testMarker' => '/* testShortList */', - 'targetType' => \T_OPEN_SHORT_ARRAY, - 'ignore' => true, - 'expected' => [ + 'testMarker' => '/* testShortList */', + 'targetType' => \T_OPEN_SHORT_ARRAY, + 'expectException' => true, + 'expected' => [ 1 => [ 'start' => 1, 'end' => 6, @@ -180,10 +213,10 @@ public static function dataTestCases() * class for those PHPCS versions. */ 'array-assign' => [ - 'testMarker' => '/* testArrayAssign */', - 'targetType' => \T_OPEN_SQUARE_BRACKET, - 'ignore' => true, - 'expected' => [], + 'testMarker' => '/* testArrayAssign */', + 'targetType' => \T_OPEN_SQUARE_BRACKET, + 'expectException' => true, + 'expected' => [], ], /* * This test will result in an (expected) Exception when run on PHPCS versions which @@ -192,10 +225,10 @@ public static function dataTestCases() * class for those PHPCS versions. */ 'array-access' => [ - 'testMarker' => '/* testArrayAccess */', - 'targetType' => \T_OPEN_SQUARE_BRACKET, - 'ignore' => true, - 'expected' => [ + 'testMarker' => '/* testArrayAccess */', + 'targetType' => \T_OPEN_SQUARE_BRACKET, + 'expectException' => true, + 'expected' => [ 1 => [ 'start' => 1, 'end' => 4, @@ -204,10 +237,10 @@ public static function dataTestCases() ], ], 'short-list-with-empties-before' => [ - 'testMarker' => '/* testShortListWithEmptyItemsBefore */', - 'targetType' => \T_OPEN_SHORT_ARRAY, - 'ignore' => true, - 'expected' => [ + 'testMarker' => '/* testShortListWithEmptyItemsBefore */', + 'targetType' => \T_OPEN_SHORT_ARRAY, + 'expectException' => true, + 'expected' => [ 1 => [ 'start' => 1, 'end' => 0, @@ -226,10 +259,10 @@ public static function dataTestCases() ], ], 'short-list-with-empties-after' => [ - 'testMarker' => '/* testShortListWithEmptyItemsAfter */', - 'targetType' => \T_OPEN_SHORT_ARRAY, - 'ignore' => true, - 'expected' => [ + 'testMarker' => '/* testShortListWithEmptyItemsAfter */', + 'targetType' => \T_OPEN_SHORT_ARRAY, + 'expectException' => true, + 'expected' => [ 1 => [ 'start' => 1, 'end' => 1, @@ -243,10 +276,10 @@ public static function dataTestCases() ], ], 'short-list-with-all-empties' => [ - 'testMarker' => '/* testShortListWithAllEmptyItems */', - 'targetType' => \T_OPEN_SHORT_ARRAY, - 'ignore' => true, - 'expected' => [ + 'testMarker' => '/* testShortListWithAllEmptyItems */', + 'targetType' => \T_OPEN_SHORT_ARRAY, + 'expectException' => true, + 'expected' => [ 1 => [ 'start' => 1, 'end' => 0, diff --git a/Tests/Utils/PassedParameters/GetParametersTest.php b/Tests/Utils/PassedParameters/GetParametersTest.php index ead9f87d..245be61c 100644 --- a/Tests/Utils/PassedParameters/GetParametersTest.php +++ b/Tests/Utils/PassedParameters/GetParametersTest.php @@ -23,8 +23,6 @@ * @covers \PHPCSUtils\Utils\PassedParameters::getParameterFromStack * @covers \PHPCSUtils\Utils\PassedParameters::hasParameters * - * @group passedparameters - * * @since 1.0.0 */ final class GetParametersTest extends UtilityMethodTestCase diff --git a/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php b/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php index fe097363..e16c242d 100644 --- a/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php +++ b/Tests/Utils/PassedParameters/GetParametersWithLimitTest.php @@ -20,8 +20,6 @@ * * @covers \PHPCSUtils\Utils\PassedParameters::getParameters * - * @group passedparameters - * * @since 1.0.0 */ final class GetParametersWithLimitTest extends UtilityMethodTestCase diff --git a/Tests/Utils/PassedParameters/HasParametersTest.php b/Tests/Utils/PassedParameters/HasParametersTest.php index e7084028..51cf443b 100644 --- a/Tests/Utils/PassedParameters/HasParametersTest.php +++ b/Tests/Utils/PassedParameters/HasParametersTest.php @@ -19,8 +19,6 @@ * * @covers \PHPCSUtils\Utils\PassedParameters::hasParameters * - * @group passedparameters - * * @since 1.0.0 */ final class HasParametersTest extends UtilityMethodTestCase @@ -81,7 +79,7 @@ public function testNotACallToConstructor($testMarker, $targetType) * * @see testNotACallToConstructor() For the array format. * - * @return array + * @return array> */ public static function dataNotACallToConstructor() { @@ -124,11 +122,11 @@ public function testNotAShortArray() * * @dataProvider dataHasParameters * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param int|string|array $targetType The type(s) of token to look for. - * @param bool $expected Whether or not the function/array has parameters/values. - * @param string $targetContent Optional. The content of the target token to find. - * Defaults to null (ignore content). + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int|string|array $targetType The type(s) of token to look for. + * @param bool $expected Whether or not the function/array has parameters/values. + * @param string|null $targetContent Optional. The content of the target token to find. + * Defaults to null (ignore content). * * @return void */ @@ -144,7 +142,7 @@ public function testHasParameters($testMarker, $targetType, $expected, $targetCo * * @see testHasParameters() For the array format. * - * @return array + * @return array|null>> */ public static function dataHasParameters() { diff --git a/Tests/Utils/Scopes/IsOOConstantTest.php b/Tests/Utils/Scopes/IsOOConstantTest.php index 38a43f22..80c66c05 100644 --- a/Tests/Utils/Scopes/IsOOConstantTest.php +++ b/Tests/Utils/Scopes/IsOOConstantTest.php @@ -18,8 +18,6 @@ * * @coversDefaultClass \PHPCSUtils\Utils\Scopes * - * @group scopes - * * @since 1.0.0 */ final class IsOOConstantTest extends UtilityMethodTestCase @@ -76,7 +74,7 @@ public function testIsOOConstant($testMarker, $expected) * * @see testIsOOConstant() For the array format. * - * @return array + * @return array> */ public static function dataIsOOConstant() { diff --git a/Tests/Utils/Scopes/IsOOMethodTest.php b/Tests/Utils/Scopes/IsOOMethodTest.php index 30b62889..9ca5983f 100644 --- a/Tests/Utils/Scopes/IsOOMethodTest.php +++ b/Tests/Utils/Scopes/IsOOMethodTest.php @@ -18,8 +18,6 @@ * * @coversDefaultClass \PHPCSUtils\Utils\Scopes * - * @group scopes - * * @since 1.0.0 */ final class IsOOMethodTest extends UtilityMethodTestCase @@ -76,7 +74,7 @@ public function testIsOOMethod($testMarker, $expected) * * @see testIsOOMethod() For the array format. * - * @return array + * @return array> */ public static function dataIsOOMethod() { diff --git a/Tests/Utils/Scopes/IsOOPropertyTest.php b/Tests/Utils/Scopes/IsOOPropertyTest.php index 9e444ca8..0bdbe6d3 100644 --- a/Tests/Utils/Scopes/IsOOPropertyTest.php +++ b/Tests/Utils/Scopes/IsOOPropertyTest.php @@ -18,8 +18,6 @@ * * @coversDefaultClass \PHPCSUtils\Utils\Scopes * - * @group scopes - * * @since 1.0.0 */ final class IsOOPropertyTest extends UtilityMethodTestCase @@ -76,7 +74,7 @@ public function testIsOOProperty($testMarker, $expected) * * @see testIsOOProperty() For the array format. * - * @return array + * @return array> */ public static function dataIsOOProperty() { diff --git a/Tests/Utils/TextStrings/GetCompleteTextStringTest.php b/Tests/Utils/TextStrings/GetCompleteTextStringTest.php index 8a575231..1caa1d5f 100644 --- a/Tests/Utils/TextStrings/GetCompleteTextStringTest.php +++ b/Tests/Utils/TextStrings/GetCompleteTextStringTest.php @@ -21,8 +21,6 @@ * @covers \PHPCSUtils\Utils\TextStrings::getCompleteTextString * @covers \PHPCSUtils\Utils\TextStrings::getEndOfCompleteTextString * - * @group textstrings - * * @since 1.0.0 */ final class GetCompleteTextStringTest extends UtilityMethodTestCase @@ -105,7 +103,7 @@ public function testNotFirstTextStringException($method) /** * Data provider. * - * @return array + * @return array> */ public static function dataExceptions() { @@ -142,7 +140,7 @@ public function testGetCompleteTextString($testMarker, $expected, $expectedWithQ * * @see testGetCompleteTextString() For the array format. * - * @return array + * @return array> */ public static function dataGetCompleteTextString() { diff --git a/Tests/Utils/TextStrings/GetEndOfCompleteTextStringTest.php b/Tests/Utils/TextStrings/GetEndOfCompleteTextStringTest.php index 569c9f52..0821427d 100644 --- a/Tests/Utils/TextStrings/GetEndOfCompleteTextStringTest.php +++ b/Tests/Utils/TextStrings/GetEndOfCompleteTextStringTest.php @@ -22,8 +22,6 @@ * * @covers \PHPCSUtils\Utils\TextStrings::getEndOfCompleteTextString * - * @group textstrings - * * @since 1.0.0 */ final class GetEndOfCompleteTextStringTest extends UtilityMethodTestCase @@ -53,7 +51,7 @@ public function testGetEndOfDoubleQuotedString($testMarker, $expectedContent) * * @see testGetEndOfDoubleQuotedString() For the array format. * - * @return array + * @return array> */ public static function dataGetEndOfDoubleQuotedString() { diff --git a/Tests/Utils/TextStrings/InterpolatedVariablesTest.php b/Tests/Utils/TextStrings/InterpolatedVariablesTest.php index abc3d131..051c645a 100644 --- a/Tests/Utils/TextStrings/InterpolatedVariablesTest.php +++ b/Tests/Utils/TextStrings/InterpolatedVariablesTest.php @@ -21,8 +21,6 @@ * @covers \PHPCSUtils\Utils\TextStrings::stripEmbeds * @covers \PHPCSUtils\Utils\TextStrings::getStripEmbeds * - * @group textstrings - * * @since 1.0.0 */ final class InterpolatedVariablesTest extends TestCase @@ -31,7 +29,7 @@ final class InterpolatedVariablesTest extends TestCase /** * Collection of various variables and other embeds which are valid in double quoted strings. * - * @var string[] + * @var array */ private static $embeds = [ // Simple. diff --git a/Tests/Utils/TextStrings/StripQuotesTest.php b/Tests/Utils/TextStrings/StripQuotesTest.php index dd05088b..5616874a 100644 --- a/Tests/Utils/TextStrings/StripQuotesTest.php +++ b/Tests/Utils/TextStrings/StripQuotesTest.php @@ -18,8 +18,6 @@ * * @covers \PHPCSUtils\Utils\TextStrings::stripQuotes * - * @group textstrings - * * @since 1.0.0 */ final class StripQuotesTest extends TestCase @@ -45,7 +43,7 @@ public function testStripQuotes($input, $expected) * * @see testStripQuotes() For the array format. * - * @return array + * @return array> */ public static function dataStripQuotes() { diff --git a/Tests/Utils/UseStatements/SplitAndMergeImportUseStatementTest.php b/Tests/Utils/UseStatements/SplitAndMergeImportUseStatementTest.php index fc81ab18..caa3d36f 100644 --- a/Tests/Utils/UseStatements/SplitAndMergeImportUseStatementTest.php +++ b/Tests/Utils/UseStatements/SplitAndMergeImportUseStatementTest.php @@ -20,8 +20,6 @@ * @covers \PHPCSUtils\Utils\UseStatements::splitAndMergeImportUseStatement * @covers \PHPCSUtils\Utils\UseStatements::mergeImportUseStatements * - * @group usestatements - * * @since 1.0.0 */ final class SplitAndMergeImportUseStatementTest extends UtilityMethodTestCase @@ -32,9 +30,9 @@ final class SplitAndMergeImportUseStatementTest extends UtilityMethodTestCase * * @dataProvider dataSplitAndMergeImportUseStatement * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return value of the function. - * @param array $previousUse Previous use statement parameter to pass to the method. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array> $expected The expected return value of the function. + * @param array> $previousUse Previous use statement parameter to pass to the method. * * @return void */ @@ -50,7 +48,7 @@ public function testSplitAndMergeImportUseStatement($testMarker, $expected, $pre * * @see testSplitAndMergeImportUseStatement() For the array format. * - * @return array + * @return array>>> */ public static function dataSplitAndMergeImportUseStatement() { diff --git a/Tests/Utils/UseStatements/SplitImportUseStatementTest.php b/Tests/Utils/UseStatements/SplitImportUseStatementTest.php index c75eccda..a38e1309 100644 --- a/Tests/Utils/UseStatements/SplitImportUseStatementTest.php +++ b/Tests/Utils/UseStatements/SplitImportUseStatementTest.php @@ -19,8 +19,6 @@ * * @covers \PHPCSUtils\Utils\UseStatements::splitImportUseStatement * - * @group usestatements - * * @since 1.0.0 */ final class SplitImportUseStatementTest extends UtilityMethodTestCase @@ -73,7 +71,7 @@ public function testNonImportUseTokenPassed($testMarker) * * @see testSplitImportUseStatement() For the array format. * - * @return array + * @return array> */ public static function dataNonImportUseTokenPassed() { @@ -88,8 +86,8 @@ public static function dataNonImportUseTokenPassed() * * @dataProvider dataSplitImportUseStatement * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return value of the function. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array> $expected The expected return value of the function. * * @return void */ @@ -105,7 +103,7 @@ public function testSplitImportUseStatement($testMarker, $expected) * * @see testSplitImportUseStatement() For the array format. * - * @return array + * @return array>>> */ public static function dataSplitImportUseStatement() { diff --git a/Tests/Utils/UseStatements/UseTypeTest.php b/Tests/Utils/UseStatements/UseTypeTest.php index d2f23a05..49ded75b 100644 --- a/Tests/Utils/UseStatements/UseTypeTest.php +++ b/Tests/Utils/UseStatements/UseTypeTest.php @@ -24,8 +24,6 @@ * @covers \PHPCSUtils\Utils\UseStatements::isClosureUse * @covers \PHPCSUtils\Utils\UseStatements::getType * - * @group usestatements - * * @since 1.0.0 */ final class UseTypeTest extends UtilityMethodTestCase @@ -60,8 +58,8 @@ public function testNonUseToken() * * @dataProvider dataUseType * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return values for the various functions. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected return values for the various functions. * * @return void */ @@ -78,8 +76,8 @@ public function testIsClosureUse($testMarker, $expected) * * @dataProvider dataUseType * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return values for the various functions. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected return values for the various functions. * * @return void */ @@ -96,8 +94,8 @@ public function testIsImportUse($testMarker, $expected) * * @dataProvider dataUseType * - * @param string $testMarker The comment which prefaces the target token in the test file. - * @param array $expected The expected return values for the various functions. + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param array $expected The expected return values for the various functions. * * @return void */ @@ -116,7 +114,7 @@ public function testIsTraitUse($testMarker, $expected) * @see testIsImportUse() For the array format. * @see testIsTraitUse() For the array format. * - * @return array + * @return array>> */ public static function dataUseType() { diff --git a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php index 1fdd4d82..5b6b6ebc 100644 --- a/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php +++ b/Tests/Utils/Variables/GetMemberPropertiesDiffTest.php @@ -62,7 +62,7 @@ public function testNotClassPropertyException($testMarker) * * @see testNotClassPropertyException() * - * @return array + * @return array> */ public static function dataNotClassPropertyException() { diff --git a/Tests/Utils/Variables/GetMemberPropertiesTest.php b/Tests/Utils/Variables/GetMemberPropertiesTest.php index ed3ccd80..07e08235 100644 --- a/Tests/Utils/Variables/GetMemberPropertiesTest.php +++ b/Tests/Utils/Variables/GetMemberPropertiesTest.php @@ -63,21 +63,17 @@ public static function setUpTestFile() * * @see testGetMemberProperties() * - * @return array + * @return array>> */ public static function dataGetMemberProperties() { $data = parent::dataGetMemberProperties(); /* - * Remove the data set related to the invalid interface/enum properties. + * Remove the data sets related to the invalid interface/enum properties. * These will now throw an exception instead. */ - foreach ($data as $key => $value) { - if ($value[0] === '/* testInterfaceProperty */' || $value[0] === '/* testEnumProperty */') { - unset($data[$key]); - } - } + unset($data['invalid-property-in-interface'], $data['invalid-property-in-enum']); return $data; } @@ -91,15 +87,15 @@ 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]; + $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) { + if (isset($expected['type_token']) && \is_int($expected['type_token']) === true) { $expected['type_token'] += $variable; } - if (isset($expected['type_end_token']) && $expected['type_end_token'] !== false) { + if (isset($expected['type_end_token']) && \is_int($expected['type_end_token']) === true) { $expected['type_end_token'] += $variable; } diff --git a/Tests/Utils/Variables/IsPHPReservedVarNameTest.php b/Tests/Utils/Variables/IsPHPReservedVarNameTest.php index dc466fc4..4808f8e6 100644 --- a/Tests/Utils/Variables/IsPHPReservedVarNameTest.php +++ b/Tests/Utils/Variables/IsPHPReservedVarNameTest.php @@ -44,7 +44,7 @@ public function testIsPHPReservedVarName($name) * * @see testIsPHPReservedVarName() For the array format. * - * @return array + * @return array> */ public static function dataIsPHPReservedVarName() { @@ -116,7 +116,7 @@ public function testIsPHPReservedVarNameFalse($name) * * @see testIsPHPReservedVarNameFalse() For the array format. * - * @return array + * @return array> */ public static function dataIsPHPReservedVarNameFalse() { diff --git a/Tests/Utils/Variables/IsSuperglobalTest.php b/Tests/Utils/Variables/IsSuperglobalTest.php index 8bec4bd3..d7205af2 100644 --- a/Tests/Utils/Variables/IsSuperglobalTest.php +++ b/Tests/Utils/Variables/IsSuperglobalTest.php @@ -62,7 +62,7 @@ public function testIsSuperglobal($testMarker, $expected, $targetType = \T_VARIA * * @see testIsSuperglobal() For the array format. * - * @return array + * @return array> */ public static function dataIsSuperglobal() { @@ -155,7 +155,7 @@ public function testIsSuperglobalName($name) * * @see testIsSuperglobalName() For the array format. * - * @return array + * @return array> */ public static function dataIsSuperglobalName() { @@ -191,7 +191,7 @@ public function testIsSuperglobalNameFalse($name) * * @see testIsSuperglobalNameFalse() For the array format. * - * @return array + * @return array> */ public static function dataIsSuperglobalNameFalse() { diff --git a/Tests/Xtra/Messages/HasNewLineSupportTest.php b/Tests/Xtra/Messages/HasNewLineSupportTest.php index 614c4c20..c1778654 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 string[] + * @var array */ protected static $selectedSniff = ['PHPCSUtils.Xtra.HasNewLineSupportTest']; diff --git a/Tests/Xtra/Tokens/TokenNameTest.php b/Tests/Xtra/Tokens/TokenNameTest.php index 3eb9f636..75bd2227 100644 --- a/Tests/Xtra/Tokens/TokenNameTest.php +++ b/Tests/Xtra/Tokens/TokenNameTest.php @@ -48,7 +48,7 @@ public function testTokenName($tokenCode, $expected) * * @see testTokenName() For the array format. * - * @return array + * @return array> */ public static function dataTokenName() { diff --git a/composer.json b/composer.json index bd5c4ae0..0fe11b88 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require" : { "php" : ">=5.4", - "squizlabs/php_codesniffer" : "^3.8.0 || 4.0.x-dev@dev", + "squizlabs/php_codesniffer" : "^3.9.0 || 4.0.x-dev@dev", "dealerdirect/phpcodesniffer-composer-installer" : "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0" }, "require-dev" : { diff --git a/docs/_config.yml b/docs/_config.yml index d39e168a..7650fa64 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -15,6 +15,7 @@ plugins: phpcsutils: packagist: phpcsstandards/phpcsutils + open_collective: php_codesniffer # Theme info. title: PHPCSUtils @@ -26,11 +27,13 @@ google_analytics: # SEO info. tagline: "PHPCSUtils: A suite of utility functions for use with PHP_CodeSniffer." twitter: - username: jrf_nl + username: PHP_CodeSniffer card: summary hashtags: PHPCSUtils +mastodon: + username: "@phpcs@phpc.social" author: - twitter: jrf_nl + twitter: PHP_CodeSniffer # Needed so the select HTML tags do not get removed *sigh* commonmark: diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html index b6bd3b8e..9169256d 100644 --- a/docs/_layouts/default.html +++ b/docs/_layouts/default.html @@ -45,8 +45,22 @@

{{ site.title | default: site.github.repo

Visit the Project on GitHub {{ site.github.repository_nwo }}

+

+ +

+

+
+ + +
@@ -76,5 +90,21 @@

{{ site.title | default: site.github.repo + + + diff --git a/docs/assets/js/mastodon.js b/docs/assets/js/mastodon.js new file mode 100644 index 00000000..421fdb2a --- /dev/null +++ b/docs/assets/js/mastodon.js @@ -0,0 +1,177 @@ +// Source: https://github.com/Aly-ve/Mastodon-share-button + +"use strict"; + +const COOKIE_NAME = 'instance-address' +const URL_REGEX = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([\/\w .-]*)*\/?$/ + +function msbShareButtonAction(name, target) { + let msbInstanceAddress = '' + + msbInstanceAddress = msbGetCookie('instance-address') + if (msbInstanceAddress.length > 0) { + window.open(`${msbInstanceAddress}/share?text=${name}%20${target}`, `__blank`) + } + else { + if (msbConfig && msbConfig.openModal && msbConfig.addressFieldSelector) { + + if (document.querySelector(msbConfig.buttonModalSelector)) { + let bms = document.querySelector(msbConfig.buttonModalSelector) + bms.data = { target, name } + bms.addEventListener('click', () => msbOnShare(), false) + + } + msbConfig.openModal(name, target) + } + } +} + +function msbOnShare(_name, _target) { + if (msbConfig && msbConfig.addressFieldSelector && msbConfig.buttonModalSelector) { + + let name = !!_name ? _name : document.querySelector(msbConfig.buttonModalSelector).data.name + let target = !!_target ? _target : document.querySelector(msbConfig.buttonModalSelector).data.target + let msbInstanceAddress = document.querySelector(`${msbConfig.addressFieldSelector}`).value + + if (!msbInstanceAddress.startsWith('http')) { + msbInstanceAddress = 'https://' + msbInstanceAddress; + } + if (msbInstanceAddress.match(URL_REGEX)) { + if (msbConfig.memorizeFieldId) { + let msbMemorizeIsChecked = document.querySelector(`#${msbConfig.memorizeFieldId}`).checked + if (msbConfig.memorizeFieldId && !msbGetCookie(COOKIE_NAME).length > 0 && msbMemorizeIsChecked) { + msbSetCookie(COOKIE_NAME, msbInstanceAddress, 7); + } + } + + window.open(`${msbInstanceAddress}/share?text=${name}%20${target}`, `__blank`) + if (msbConfig && msbConfig.openModal && msbConfig.closeModal) { + msbConfig.closeModal() + } + } + } +} + +function msbGetCookie(cname) { + var name = cname + "="; + var ca = document.cookie.split(';'); + for(var i = 0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) == ' ') { + c = c.substring(1); + } + if (c.indexOf(name) == 0) { + return c.substring(name.length, c.length); + } + } + return ""; +} + +function msbSetCookie(name, value, days) { + let d = new Date() + d.setTime(d.getTime() + days*86400000) + let expires = 'expires=' + d.toUTCString() + document.cookie = `${name}=${value}; ${expires}; path=/` +} + +(function() { + + let msbButtons = document.querySelectorAll('.mastodon-share-button') + + for(let i = 0; i < msbButtons.length; i++) { + (function(j) { + + let msbTarget = msbButtons[j].dataset.target + let msbName = msbButtons[j].dataset.name + let msbButtonStyle = msbButtons[j].dataset.buttonstyle + let msbText = msbButtons[j].dataset.text + + // Replace hashtab by html code + msbName = msbName.replace(/#/g, '%23') + + /** + * Create buttons + */ + let button = document.createElement('button') + let buttonText = null + + /** + * Add text button... or not + */ + if (msbConfig && (msbConfig.buttonDisplayText || msbConfig.buttonDisplayText === undefined)) { + buttonText = !!msbText ? document.createTextNode(msbText) : document.createTextNode(msbI18n()) + } + else { + buttonText = document.createTextNode('') + } + + + if (msbButtonStyle) { + button.setAttribute('class', msbButtonStyle) + } + + button.appendChild(buttonText) + msbButtons[j].appendChild(button) + + /** + * Add icon to the button if buttonIconHtml is setted + */ + if (msbConfig && msbConfig.buttonIconHtml) { + button.innerHTML = `${msbConfig.buttonIconHtml} ${button.innerHTML}` + } + + /** + * Set the listener in each button + */ + button.addEventListener('click', () => { msbShareButtonAction(msbName, msbTarget) }, true) + + })(i) + } + +})() + +function msbI18n() { + let language = navigator.language || navigator.userLanguage + let publish = { + 'ar': 'بوّق', + 'bg': 'Раздумай', + 'cs': 'Tootnout', + 'de': 'Tröt', + 'eo': 'Hué', + 'es': 'Tootear', + 'eu': 'Tut', + 'fa': 'بوق', + 'fi': 'Tuuttaa', + 'fr': 'Pouet', + 'gl': 'ללחוש', + 'he': 'ללחוש', + 'hu': 'Tülk', + 'hy': 'Թթել', + 'io': 'Siflar', + 'ja': 'トゥート', + 'ko': '툿', + 'no': 'Tut', + 'oc': 'Tut', + 'pl': 'Wyślij', + 'pt-BR': 'Publicar', + 'pt': 'Publicar', + 'ru': 'Трубить', + 'sr-Latn': 'Tutni', + 'sr': 'Тутни', + 'uk': 'Дмухнути', + 'zh-CN': '嘟嘟', + 'zh-HK': '發文', + 'zh-TW': '貼掉', + 'default': 'Toot' + } + + let text = null + try { + text = publish[language] + } + catch (error) { + text = publish.default + } + + return text +} diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c4d18fed..bdcaef3b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -74,6 +74,7 @@ parameters: - message: '`^Parameter #[0-9]+ \$\S+ of static method PHPCSUtils\\(?!Tests)[A-Za-z]+\\[A-Za-z]+::[A-Za-z]+\(\) expects [^,]+, \S+ given\.$`' paths: + - Tests/BackCompat/Helper/GetCommandLineDataTest.php - Tests/BackCompat/BCFile/GetTokensAsStringTest.php - Tests/Exceptions/TestTargetNotFound/TestTargetNotFoundTest.php - Tests/Fixers/SpacesFixer/SpacesFixerExceptionsTest.php