Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indexes -> indices #6168

Merged
merged 1 commit into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AbstractDoctrineAnnotationFixer.php
Expand Up @@ -47,7 +47,7 @@ public function isCandidate(Tokens $tokens): bool
*/
protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
{
// fetch indexes one time, this is safe as we never add or remove a token during fixing
// fetch indices one time, this is safe as we never add or remove a token during fixing
$analyzer = new TokensAnalyzer($tokens);
$this->classyElements = $analyzer->getClassyElements();

Expand Down
4 changes: 2 additions & 2 deletions src/DocBlock/Line.php
Expand Up @@ -102,7 +102,7 @@ public function setContent(string $content): void
* Remove this line by clearing its contents.
*
* Note that this method technically brakes the internal state of the
* docblock, but is useful when we need to retain the indexes of lines
* docblock, but is useful when we need to retain the indices of lines
* during the execution of an algorithm.
*/
public function remove(): void
Expand All @@ -114,7 +114,7 @@ public function remove(): void
* Append a blank docblock line to this line's contents.
*
* Note that this method technically brakes the internal state of the
* docblock, but is useful when we need to retain the indexes of lines
* docblock, but is useful when we need to retain the indices of lines
* during the execution of an algorithm.
*/
public function addBlank(): void
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Alias/BacktickToShellExecFixer.php
Expand Up @@ -102,7 +102,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
*/
private function fixBackticks(Tokens $tokens, array $backtickTokens): void
{
// Track indexes for final override
// Track indices for final override
ksort($backtickTokens);
$openingBacktickIndex = key($backtickTokens);
end($backtickTokens);
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Alias/EregToPregFixer.php
Expand Up @@ -97,7 +97,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
break;
}

// findSequence also returns the tokens, but we're only interested in the indexes, i.e.:
// findSequence also returns the tokens, but we're only interested in the indices, i.e.:
// 0 => function name,
// 1 => bracket "("
// 2 => quoted string passed as 1st parameter
Expand Down
10 changes: 5 additions & 5 deletions src/Fixer/Alias/ModernizeStrposFixer.php
Expand Up @@ -127,19 +127,19 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
}
}

private function fixCall(Tokens $tokens, int $functionIndex, array $operatorIndexes): void
private function fixCall(Tokens $tokens, int $functionIndex, array $operatorIndices): void
{
foreach (self::REPLACEMENTS as $replacement) {
if (!$tokens[$operatorIndexes['operator_index']]->equals($replacement['operator'])) {
if (!$tokens[$operatorIndices['operator_index']]->equals($replacement['operator'])) {
continue;
}

if (!$tokens[$operatorIndexes['operand_index']]->equals($replacement['operand'], false)) {
if (!$tokens[$operatorIndices['operand_index']]->equals($replacement['operand'], false)) {
continue;
}

$tokens->clearTokenAndMergeSurroundingWhitespace($operatorIndexes['operator_index']);
$tokens->clearTokenAndMergeSurroundingWhitespace($operatorIndexes['operand_index']);
$tokens->clearTokenAndMergeSurroundingWhitespace($operatorIndices['operator_index']);
$tokens->clearTokenAndMergeSurroundingWhitespace($operatorIndices['operand_index']);
$tokens->clearTokenAndMergeSurroundingWhitespace($functionIndex);

if ($replacement['negate']) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Alias/PowToExponentiationFixer.php
Expand Up @@ -73,7 +73,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void

foreach (array_reverse($candidates) as $candidate) {
// if in the previous iteration(s) tokens were added to the collection and this is done within the tokens
// indexes of the current candidate than the index of the close ')' of the candidate has moved and so
// indices of the current candidate than the index of the close ')' of the candidate has moved and so
// the index needs to be updated
if ($previousCloseParenthesisIndex < $candidate[2]) {
$previousCloseParenthesisIndex = $candidate[2];
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php
Expand Up @@ -221,7 +221,7 @@ private function fixParent(Tokens $tokens, int $classStart, int $classEnd): void
], $classStart, $classEnd, [2 => false]);

if (null !== $parentSeq) {
// we only need indexes
// we only need indices
$parentSeq = array_keys($parentSeq);

// match either of the possibilities
Expand All @@ -242,7 +242,7 @@ private function fixParent(Tokens $tokens, int $classStart, int $classEnd): void
], $classStart, $classEnd, [2 => false]);

if (null !== $parentSeq) {
// we only need indexes
// we only need indices
$parentSeq = array_keys($parentSeq);

// replace call with parent::__construct()
Expand Down Expand Up @@ -378,7 +378,7 @@ private function findFunction(Tokens $tokens, string $name, int $startIndex, int
return null;
}

// keep only the indexes
// keep only the indices
$function = array_keys($function);

// find previous block, saving method modifiers for later use
Expand Down
Expand Up @@ -70,7 +70,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
}

/**
* @param int[] $candidates ',' indexes to fix
* @param int[] $candidates ',' indices to fix
*/
private function fixTraitUse(Tokens $tokens, int $useTraitIndex, array $candidates): void
{
Expand Down Expand Up @@ -99,18 +99,18 @@ private function fixTraitUse(Tokens $tokens, int $useTraitIndex, array $candidat
*/
private function getCandidates(Tokens $tokens, int $index): array
{
$indexes = [];
$indices = [];
$index = $tokens->getNextTokenOfKind($index, [',', ';', '{']);

while (!$tokens[$index]->equals(';')) {
if ($tokens[$index]->equals('{')) {
return []; // do not fix use cases with grouping
}

$indexes[] = $index;
$indices[] = $index;
$index = $tokens->getNextTokenOfKind($index, [',', ';', '{']);
}

return array_reverse($indexes);
return array_reverse($indices);
}
}
8 changes: 4 additions & 4 deletions src/Fixer/Comment/HeaderCommentFixer.php
Expand Up @@ -141,19 +141,19 @@ public function getPriority(): int
protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
{
$location = $this->configuration['location'];
$locationIndexes = [];
$locationIndices = [];

foreach (['after_open', 'after_declare_strict'] as $possibleLocation) {
$locationIndex = $this->findHeaderCommentInsertionIndex($tokens, $possibleLocation);

if (!isset($locationIndexes[$locationIndex]) || $possibleLocation === $location) {
$locationIndexes[$locationIndex] = $possibleLocation;
if (!isset($locationIndices[$locationIndex]) || $possibleLocation === $location) {
$locationIndices[$locationIndex] = $possibleLocation;

continue;
}
}

foreach (array_values($locationIndexes) as $possibleLocation) {
foreach (array_values($locationIndices) as $possibleLocation) {
// figure out where the comment should be placed
$headerNewIndex = $this->findHeaderCommentInsertionIndex($tokens, $possibleLocation);

Expand Down
8 changes: 4 additions & 4 deletions src/Fixer/ControlStructure/SimplifiedIfReturnFixer.php
Expand Up @@ -119,11 +119,11 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
continue;
}

$indexesToClear = array_keys($sequenceFound);
array_pop($indexesToClear); // Preserve last semicolon
rsort($indexesToClear);
$indicesToClear = array_keys($sequenceFound);
array_pop($indicesToClear); // Preserve last semicolon
rsort($indicesToClear);

foreach ($indexesToClear as $index) {
foreach ($indicesToClear as $index) {
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
}

Expand Down
Expand Up @@ -168,7 +168,7 @@ private function isClosingLineWithMeaningfulContent(Tokens $tokens, int $index):
}

/**
* @param array<array<int>> $annotationPositions Pairs of begin and end indexes of main annotations
* @param array<array<int>> $annotationPositions Pairs of begin and end indices of main annotations
*/
private function indentationCanBeFixed(Tokens $tokens, int $newLineTokenIndex, array $annotationPositions): bool
{
Expand Down
22 changes: 11 additions & 11 deletions src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php
Expand Up @@ -128,14 +128,14 @@ private function fixClass(Tokens $tokens, int $index): void
}

$docCommentIndex = $index;
$propertyIndexes = $this->findNextUntypedPropertiesDeclaration($tokens, $docCommentIndex);
$propertyIndices = $this->findNextUntypedPropertiesDeclaration($tokens, $docCommentIndex);

if ([] === $propertyIndexes) {
if ([] === $propertyIndices) {
continue;
}

$typeInfo = $this->resolveApplicableType(
$propertyIndexes,
$propertyIndices,
$this->getAnnotationsFromDocComment('var', $tokens, $docCommentIndex)
);

Expand All @@ -154,9 +154,9 @@ private function fixClass(Tokens $tokens, int $index): void
[new Token([T_WHITESPACE, ' '])]
);

$tokens->insertAt(current($propertyIndexes), $newTokens);
$tokens->insertAt(current($propertyIndices), $newTokens);

$index = max($propertyIndexes) + \count($newTokens) + 1;
$index = max($propertyIndices) + \count($newTokens) + 1;
$classEndIndex += \count($newTokens);
}
}
Expand Down Expand Up @@ -194,25 +194,25 @@ private function findNextUntypedPropertiesDeclaration(Tokens $tokens, int $index
}

/**
* @param array<string, int> $propertyIndexes
* @param array<string, int> $propertyIndices
* @param Annotation[] $annotations
*/
private function resolveApplicableType(array $propertyIndexes, array $annotations): ?array
private function resolveApplicableType(array $propertyIndices, array $annotations): ?array
{
$propertyTypes = [];

foreach ($annotations as $annotation) {
$propertyName = $annotation->getVariableName();

if (null === $propertyName) {
if (1 !== \count($propertyIndexes)) {
if (1 !== \count($propertyIndices)) {
continue;
}

$propertyName = key($propertyIndexes);
$propertyName = key($propertyIndices);
}

if (!isset($propertyIndexes[$propertyName])) {
if (!isset($propertyIndices[$propertyName])) {
continue;
}

Expand All @@ -227,7 +227,7 @@ private function resolveApplicableType(array $propertyIndexes, array $annotation
$propertyTypes[$propertyName] = $typeInfo;
}

if (\count($propertyTypes) !== \count($propertyIndexes)) {
if (\count($propertyTypes) !== \count($propertyIndices)) {
return null;
}

Expand Down
29 changes: 13 additions & 16 deletions src/Fixer/Import/GlobalNamespaceImportFixer.php
Expand Up @@ -201,8 +201,7 @@ private function importConstants(Tokens $tokens, array $useDeclarations): array
}

$analyzer = new TokensAnalyzer($tokens);

$indexes = [];
$indices = [];

for ($index = $tokens->count() - 1; $index >= 0; --$index) {
$token = $tokens[$index];
Expand Down Expand Up @@ -237,10 +236,10 @@ private function importConstants(Tokens $tokens, array $useDeclarations): array
continue;
}

$indexes[] = $index;
$indices[] = $index;
}

return $this->prepareImports($tokens, $indexes, $global, $other, true);
return $this->prepareImports($tokens, $indices, $global, $other, true);
}

/**
Expand All @@ -259,8 +258,7 @@ private function importFunctions(Tokens $tokens, array $useDeclarations): array
}

$analyzer = new FunctionsAnalyzer();

$indexes = [];
$indices = [];

for ($index = $tokens->count() - 1; $index >= 0; --$index) {
$token = $tokens[$index];
Expand Down Expand Up @@ -288,10 +286,10 @@ private function importFunctions(Tokens $tokens, array $useDeclarations): array
continue;
}

$indexes[] = $index;
$indices[] = $index;
}

return $this->prepareImports($tokens, $indexes, $global, $other, false);
return $this->prepareImports($tokens, $indices, $global, $other, false);
}

/**
Expand Down Expand Up @@ -339,8 +337,7 @@ private function importClasses(Tokens $tokens, array $useDeclarations): array
}

$analyzer = new ClassyAnalyzer();

$indexes = [];
$indices = [];

for ($index = $tokens->count() - 1; $index >= 0; --$index) {
$token = $tokens[$index];
Expand Down Expand Up @@ -372,7 +369,7 @@ private function importClasses(Tokens $tokens, array $useDeclarations): array
continue;
}

$indexes[] = $index;
$indices[] = $index;
}

$imports = [];
Expand Down Expand Up @@ -404,21 +401,21 @@ private function importClasses(Tokens $tokens, array $useDeclarations): array
}
}

return $imports + $this->prepareImports($tokens, $indexes, $global, $other, false);
return $imports + $this->prepareImports($tokens, $indices, $global, $other, false);
}

/**
* Removes the leading slash at the given indexes (when the name is not already used).
* Removes the leading slash at the given indices (when the name is not already used).
*
* @param int[] $indexes
* @param int[] $indices
*
* @return array array keys contain the names that must be imported
*/
private function prepareImports(Tokens $tokens, array $indexes, array $global, array $other, bool $caseSensitive): array
private function prepareImports(Tokens $tokens, array $indices, array $global, array $other, bool $caseSensitive): array
{
$imports = [];

foreach ($indexes as $index) {
foreach ($indices as $index) {
$name = $tokens[$index]->getContent();
$checkName = $caseSensitive ? $name : strtolower($name);

Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/Import/NoLeadingImportSlashFixer.php
Expand Up @@ -64,9 +64,9 @@ public function isCandidate(Tokens $tokens): bool
protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
$usesIndexes = $tokensAnalyzer->getImportUseIndexes();
$usesIndices = $tokensAnalyzer->getImportUseIndexes();

foreach ($usesIndexes as $idx) {
foreach ($usesIndices as $idx) {
$nextTokenIdx = $tokens->getNextMeaningfulToken($idx);
$nextToken = $tokens[$nextTokenIdx];

Expand Down