Skip to content

Commit

Permalink
minor #5499 DX: add TODOs for PHP requirements cleanup (keradus)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.18 branch.

Discussion
----------

DX: add TODOs for PHP requirements cleanup

Commits
-------

7d588f4 DX: add TODOs for PHP requirements cleanup
  • Loading branch information
keradus committed Feb 18, 2021
2 parents e2c6a1a + 7d588f4 commit dd2e3d6
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ public function __construct()
{
parent::__construct();

// To be moved back to compile time property declaration when PHP support of PHP CS Fixer will be 7.0+
// @TODO: To be moved back to compile time property declaration when PHP support of PHP CS Fixer will be 7.0+
if (\defined('T_COALESCE')) {
self::$loops['clone']['forbiddenContents'][] = [T_COALESCE, '??'];
}

// @TODO: To be moved back to compile time property declaration when PHP support of PHP CS Fixer will be 7.0+
if (\defined('T_YIELD_FROM')) {
self::$loops['yield_from'] = ['lookupTokens' => T_YIELD_FROM, 'neededSuccessors' => [';', ')']];
}
Expand Down
2 changes: 2 additions & 0 deletions src/Fixer/ControlStructure/YodaStyleFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,12 @@ private function isOfLowerPrecedence(Token $token)
T_XOR_EQUAL, // ^=
];

// @TODO: drop condition when PHP 7.0+ is required
if (\defined('T_COALESCE')) {
$tokens[] = T_COALESCE; // ??
}

// @TODO: drop condition when PHP 7.4+ is required
if (\defined('T_COALESCE_EQUAL')) {
$tokens[] = T_COALESCE_EQUAL; // ??=
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ public function configure(array $configuration = null)
{
parent::configure($configuration);

// @TODO: drop condition when PHP 7.0+ is required
if (\defined('T_YIELD_FROM')) {
self::$tokenMap['yield_from'] = T_YIELD_FROM;
}

// @TODO: drop condition when PHP 8.0+ is required
if (\defined('T_MATCH')) {
self::$tokenMap['match'] = T_MATCH;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Fixer/Operator/BinaryOperatorSpacesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,17 @@ private function resolveOperatorsFromConfig()
}
}

// @TODO: drop condition when PHP 7.0+ is required
if (!\defined('T_SPACESHIP')) {
unset($operators['<=>']);
}

// @TODO: drop condition when PHP 7.0+ is required
if (!\defined('T_COALESCE')) {
unset($operators['??']);
}

// @TODO: drop condition when PHP 7.4+ is required
if (!\defined('T_COALESCE_EQUAL')) {
unset($operators['??=']);
}
Expand Down
1 change: 1 addition & 0 deletions src/Fixer/Operator/NewWithBracesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
[CT::T_BRACE_CLASS_INSTANTIATION_CLOSE],
];

// @TODO: drop condition when PHP 7.0+ is required
if (\defined('T_SPACESHIP')) {
$nextTokenKinds[] = [T_SPACESHIP];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct()
{
parent::__construct();

// To be moved back to compile time property declaration when PHP support of PHP CS Fixer will be 7.0+
// @TODO: To be moved back to compile time property declaration when PHP support of PHP CS Fixer will be 7.0+
if (\defined('T_YIELD_FROM')) {
self::$tokenMap['yield_from'] = T_YIELD_FROM;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Linter/TokenizerLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ final class TokenizerLinter implements LinterInterface
{
public function __construct()
{
if (false === \defined('TOKEN_PARSE') || false === class_exists(\CompileError::class)) {
if (
// @TODO: drop condition when PHP 7.0+ is required
false === \defined('TOKEN_PARSE')
// @TODO: drop condition when PHP 7.3+ is required
|| false === class_exists(\CompileError::class)
) {
throw new UnavailableLinterException('Cannot use tokenizer as linter.');
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Tokenizer/Analyzer/CommentsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function isBeforeStructuralElement(Tokens $tokens, $index)
do {
$nextIndex = $tokens->getNextMeaningfulToken($nextIndex);

// @TODO: drop condition when PHP 8.0+ is required
if (\defined('T_ATTRIBUTE')) {
while (null !== $nextIndex && $tokens[$nextIndex]->isGivenKind(T_ATTRIBUTE)) {
$nextIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ATTRIBUTE, $nextIndex);
Expand Down
3 changes: 2 additions & 1 deletion src/Tokenizer/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public static function getBlockEdgeDefinitions()
],
];

// @TODO: drop condition when PHP 8.0+ is required
if (\defined('T_ATTRIBUTE')) {
$definitions[self::BLOCK_TYPE_ATTRIBUTE] = [
'start' => [T_ATTRIBUTE, '#['],
Expand Down Expand Up @@ -1092,7 +1093,7 @@ public function setCode($code)
// clear memory
$this->setSize(0);

$tokens = \defined('TOKEN_PARSE')
$tokens = \defined('TOKEN_PARSE') // @TODO: drop condition when PHP 7.0+ is required
? token_get_all($code, TOKEN_PARSE)
: token_get_all($code);

Expand Down
3 changes: 3 additions & 0 deletions src/Tokenizer/TokensAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,17 @@ public function isBinaryOperator($index)
CT::T_TYPE_ALTERNATION => true, // |
];

// @TODO: drop condition when PHP 7.0+ is required
if (\defined('T_SPACESHIP')) {
$arrayOperators[T_SPACESHIP] = true; // <=>
}

// @TODO: drop condition when PHP 7.0+ is required
if (\defined('T_COALESCE')) {
$arrayOperators[T_COALESCE] = true; // ??
}

// @TODO: drop condition when PHP 7.4+ is required
if (\defined('T_COALESCE_EQUAL')) {
$arrayOperators[T_COALESCE_EQUAL] = true; // ??=
}
Expand Down
1 change: 1 addition & 0 deletions tests/Tokenizer/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public function provideIsCommentCases()
yield $index => $test;
}

// @TODO: drop condition when PHP 8.0+ is required
if (\defined('T_ATTRIBUTE')) {
yield [new Token([T_ATTRIBUTE, '#[', 1]), false];
}
Expand Down

0 comments on commit dd2e3d6

Please sign in to comment.