Skip to content

Commit

Permalink
Merge pull request #410 from PHPCSStandards/feature/remove-deprecated…
Browse files Browse the repository at this point in the history
…-functionality

Remove deprecated functionality
  • Loading branch information
jrfnl committed Dec 24, 2022
2 parents 08826c2 + b77eece commit 2bf0fe8
Show file tree
Hide file tree
Showing 39 changed files with 173 additions and 2,796 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/basics.yml
Expand Up @@ -71,9 +71,7 @@ jobs:

# Check the code-style consistency of the XML file.
- name: Check XML code style
run: |
diff -B ./PHPCSUtils/ruleset.xml <(xmllint --format "./PHPCSUtils/ruleset.xml")
diff -B ./PHPCS23Utils/ruleset.xml <(xmllint --format "./PHPCS23Utils/ruleset.xml")
run: diff -B ./PHPCSUtils/ruleset.xml <(xmllint --format "./PHPCSUtils/ruleset.xml")

# Check the code-style consistency of the PHP files.
- name: Check PHP code style
Expand Down
52 changes: 0 additions & 52 deletions PHPCS23Utils/Sniffs/Load/LoadUtilsSniff.php

This file was deleted.

4 changes: 0 additions & 4 deletions PHPCS23Utils/ruleset.xml

This file was deleted.

546 changes: 154 additions & 392 deletions PHPCSUtils/Tokens/Collections.php

Large diffs are not rendered by default.

60 changes: 0 additions & 60 deletions PHPCSUtils/Utils/ControlStructures.php
Expand Up @@ -193,66 +193,6 @@ public static function isElseIf(File $phpcsFile, $stackPtr)
return false;
}

/**
* Get the scope opener and closer for a DECLARE statement.
*
* A `declare` statement can be:
* - applied to the rest of the file, like `declare(ticks=1);`
* - applied to a limited scope using curly braces;
* - applied to a limited scope using the alternative control structure syntax.
*
* In the first case, the statement - correctly - won't have a scope opener/closer.
* In the second case, the statement will have the scope opener/closer indexes.
* In the last case, due to a bug in the PHPCS Tokenizer, it won't have the scope opener/closer indexes,
* while it really should. This bug was fixed in PHPCS 3.5.4.
*
* @link https://github.com/squizlabs/PHP_CodeSniffer/pull/2843 PHPCS PR #2843
*
* @since 1.0.0
* @deprecated 1.0.0-alpha4 Check the scope_opener/scope_closer instead.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the token we are checking.
*
* @return array|false An array with the token pointers; or `FALSE` if not a `DECLARE` token
* or if the opener/closer could not be determined.
* The format of the array return value is:
* ```php
* array(
* 'opener' => integer, // Stack pointer to the scope opener.
* 'closer' => integer, // Stack pointer to the scope closer.
* )
* ```
*/
public static function getDeclareScopeOpenClose(File $phpcsFile, $stackPtr)
{
\trigger_error(
\sprintf(
'The %s() function is deprecated since PHPCSUtils 1.0.0-alpha4.'
. ' Check for the "scope_opener"/"scope_closer" keys instead.',
__METHOD__
),
\E_USER_DEPRECATED
);

$tokens = $phpcsFile->getTokens();

if (isset($tokens[$stackPtr]) === false
|| $tokens[$stackPtr]['code'] !== \T_DECLARE
) {
return false;
}

if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === true) {
return [
'opener' => $tokens[$stackPtr]['scope_opener'],
'closer' => $tokens[$stackPtr]['scope_closer'],
];
}

return false;
}

/**
* Retrieve the exception(s) being caught in a CATCH condition.
*
Expand Down
102 changes: 0 additions & 102 deletions PHPCSUtils/Utils/FunctionDeclarations.php
Expand Up @@ -621,108 +621,6 @@ public static function getParameters(File $phpcsFile, $stackPtr)
return $vars;
}

/**
* Check if an arbitrary token is the "fn" keyword for a PHP 7.4 arrow function.
*
* Helper function for cross-version compatibility with both PHP as well as PHPCS.
* As of PHPCS 3.5.6, this function is no longer be needed.
*
* @see \PHPCSUtils\Utils\FunctionDeclarations::getArrowFunctionOpenClose() Related function.
*
* @since 1.0.0
* @deprecated 1.0.0-alpha4 Use the T_FN token constant instead.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
* @param int $stackPtr The token to check. Typically a T_FN or
* T_STRING token as those are the only two
* tokens which can be the arrow function keyword.
*
* @return bool `TRUE` if the token is the "fn" keyword for an arrow function. `FALSE` when it's not
* or in case of live coding/parse error.
*/
public static function isArrowFunction(File $phpcsFile, $stackPtr)
{
\trigger_error(
\sprintf(
'The %s() function is deprecated since PHPCSUtils 1.0.0-alpha4. Use the `T_FN` token instead.',
__METHOD__
),
\E_USER_DEPRECATED
);

$tokens = $phpcsFile->getTokens();
if (isset($tokens[$stackPtr]) === false) {
return false;
}

if ($tokens[$stackPtr]['code'] === \T_FN
&& isset($tokens[$stackPtr]['scope_closer']) === true
) {
return true;
}

return false;
}

/**
* Retrieve the parenthesis opener, parenthesis closer, the scope opener and the scope closer
* for an arrow function.
*
* Helper function for cross-version compatibility with both PHP as well as PHPCS.
* As of PHPCS 3.5.6, this function is no longer be needed.
*
* @see \PHPCSUtils\Utils\FunctionDeclarations::isArrowFunction() Related function.
*
* @since 1.0.0
* @deprecated 1.0.0-alpha4 Use the T_FN token constant instead.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
* @param int $stackPtr The token to retrieve the openers/closers for.
* Typically a `T_FN` or `T_STRING` token as those are the
* only two tokens which can be the arrow function keyword.
*
* @return array|false An array with the token pointers or `FALSE` if this is not an arrow function.
* The format of the return value is:
* ```php
* array(
* 'parenthesis_opener' => integer, // Stack pointer to the parenthesis opener.
* 'parenthesis_closer' => integer, // Stack pointer to the parenthesis closer.
* 'scope_opener' => integer, // Stack pointer to the scope opener (arrow).
* 'scope_closer' => integer, // Stack pointer to the scope closer.
* )
* ```
*/
public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr)
{
\trigger_error(
\sprintf(
'The %s() function is deprecated since PHPCSUtils 1.0.0-alpha4. Use the `T_FN` token instead.',
__METHOD__
),
\E_USER_DEPRECATED
);

$tokens = $phpcsFile->getTokens();

if (isset($tokens[$stackPtr]) === false
|| $tokens[$stackPtr]['code'] !== \T_FN
) {
return false;
}

if (isset($tokens[$stackPtr]['scope_closer']) === true) {
// The keys will either all be set or none will be set, so no additional checks needed.
return [
'parenthesis_opener' => $tokens[$stackPtr]['parenthesis_opener'],
'parenthesis_closer' => $tokens[$stackPtr]['parenthesis_closer'],
'scope_opener' => $tokens[$stackPtr]['scope_opener'],
'scope_closer' => $tokens[$stackPtr]['scope_closer'],
];
}

return [];
}

/**
* Checks if a given function is a PHP magic function.
*
Expand Down

This file was deleted.

This file was deleted.

48 changes: 0 additions & 48 deletions Tests/Tokens/Collections/ArrowFunctionTokensBCTest.php

This file was deleted.

0 comments on commit 2bf0fe8

Please sign in to comment.