Skip to content
Permalink
Browse files

Tokens cleanup

  • Loading branch information...
kubawerlos committed Oct 18, 2019
1 parent 84e9715 commit e335de4ab70835fff629aeaaa61fe39ab91c63ae
Showing with 50 additions and 55 deletions.
  1. +1 −0 phpstan.neon
  2. +1 −3 src/Fixer/DataProviderReturnTypeFixer.php
  3. +48 −52 src/Fixer/OperatorLinebreakFixer.php
@@ -4,6 +4,7 @@ parameters:
- ./src
ignoreErrors:
- '#^Parameter \#\d+ \$[a-zA-Z]+ of method PhpCsFixer\\Tokenizer\\Tokens::insertAt\(\) expects#'
- '#^Parameter \#\d+ \$[a-zA-Z]+ of method PhpCsFixer\\Tokenizer\\Tokens::overrideRange\(\) expects#'

includes:
- ./dev-tools/vendor/phpstan/phpstan-strict-rules/rules.neon
@@ -108,9 +108,7 @@ private function fixNames(Tokens $tokens, int $startIndex, int $endIndex): void
if ($this->getTypeName($tokens, $typeAnalysis) !== 'iterable') {
/** @var int $startIndex */
$startIndex = $tokens->getNextMeaningfulToken($typeAnalysis->getStartIndex() - 1);
$tokens->clearRange($startIndex, $typeAnalysis->getEndIndex());
$tokens->insertAt($typeAnalysis->getEndIndex(), new Token([T_STRING, 'iterable']));
$tokens->overrideRange($startIndex, $typeAnalysis->getEndIndex(), [new Token([T_STRING, 'iterable'])]);
}
}
}
@@ -21,7 +21,7 @@ final class OperatorLinebreakFixer extends AbstractFixer implements Configuratio
/** @var string */
private $position = 'beginning';
/** @var Token[] */
/** @var array<array<int|string>|string> */
private $operators = [];
public function getDefinition(): FixerDefinitionInterface
@@ -54,62 +54,58 @@ public function getConfigurationDefinition(): FixerConfigurationResolver
public function configure(?array $configuration = null): void
{
$this->operators = [
new Token([T_LOGICAL_AND, 'and']),
new Token([T_LOGICAL_OR, 'or']),
new Token([T_LOGICAL_XOR, 'xor']),
new Token('&&'),
new Token('||'),
[T_LOGICAL_AND, 'and'],
[T_LOGICAL_OR, 'or'],
[T_LOGICAL_XOR, 'xor'],
[T_BOOLEAN_AND, '&&'],
[T_BOOLEAN_OR, '||'],
];
if (!isset($configuration['only_booleans']) || $configuration['only_booleans'] === false) {
$this->operators = \array_merge(
$this->operators,
[
new Token('+'),
new Token('-'),
new Token('*'),
new Token('/'),
new Token('%'),
new Token([T_POW, '**']),
new Token([T_PLUS_EQUAL, '+=']),
new Token([T_MINUS_EQUAL, '-=']),
new Token([T_MUL_EQUAL, '*=']),
new Token([T_DIV_EQUAL, '/=']),
new Token([T_MOD_EQUAL, '%=']),
new Token([T_POW_EQUAL, '**=']),
new Token('='),
new Token('&'),
new Token('|'),
new Token('^'),
new Token([T_SL, '<<']),
new Token([T_SR, '>>']),
new Token([T_AND_EQUAL, '&=']),
new Token([T_OR_EQUAL, '|=']),
new Token([T_XOR_EQUAL, '^=']),
new Token([T_SL_EQUAL, '<<=']),
new Token([T_SR_EQUAL, '>>=']),
new Token([T_IS_EQUAL, '==']),
new Token([T_IS_IDENTICAL, '===']),
new Token([T_IS_NOT_EQUAL, '!=']),
new Token([T_IS_NOT_EQUAL, '<>']),
new Token([T_IS_NOT_IDENTICAL, '!==']),
new Token('<'),
new Token('>'),
new Token([T_IS_SMALLER_OR_EQUAL, '<=']),
new Token([T_IS_GREATER_OR_EQUAL, '>=']),
new Token([T_SPACESHIP, '<=>']),
new Token('and'),
new Token('or'),
new Token('xor'),
new Token([T_BOOLEAN_AND, '&&']),
new Token([T_BOOLEAN_OR, '||']),
new Token('.'),
new Token([T_CONCAT_EQUAL, '.=']),
new Token([T_COALESCE, '??']),
new Token([T_DOUBLE_ARROW, '=>']),
new Token([T_OBJECT_OPERATOR, '->']),
new Token([T_PAAMAYIM_NEKUDOTAYIM, '::']),
new Token('?'),
new Token(':'),
'+',
'-',
'*',
'/',
'%',
[T_POW, '**'],
[T_PLUS_EQUAL, '+='],
[T_MINUS_EQUAL, '-='],
[T_MUL_EQUAL, '*='],
[T_DIV_EQUAL, '/='],
[T_MOD_EQUAL, '%='],
[T_POW_EQUAL, '**='],
'=',
'&',
'|',
'^',
[T_SL, '<<'],
[T_SR, '>>'],
[T_AND_EQUAL, '&='],
[T_OR_EQUAL, '|='],
[T_XOR_EQUAL, '^='],
[T_SL_EQUAL, '<<='],
[T_SR_EQUAL, '>>='],
[T_IS_EQUAL, '=='],
[T_IS_IDENTICAL, '==='],
[T_IS_NOT_EQUAL, '!='],
[T_IS_NOT_EQUAL, '<>'],
[T_IS_NOT_IDENTICAL, '!=='],
'<',
'>',
[T_IS_SMALLER_OR_EQUAL, '<='],
[T_IS_GREATER_OR_EQUAL, '>='],
[T_SPACESHIP, '<=>'],
'.',
[T_CONCAT_EQUAL, '.='],
[T_COALESCE, '??'],
[T_DOUBLE_ARROW, '=>'],
[T_OBJECT_OPERATOR, '->'],
[T_PAAMAYIM_NEKUDOTAYIM, '::'],
'?',
':',
]
);
}

0 comments on commit e335de4

Please sign in to comment.
You can’t perform that action at this time.