Skip to content

Commit

Permalink
OK, this can be checked once
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Dec 14, 2021
1 parent dab5172 commit c361910
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Tokenizer/Tokens.php
Expand Up @@ -858,6 +858,13 @@ public function insertSlices(array $slices): void
$this->setSize($oldSize + $itemsCount);

krsort($slices);
$farthestSliceIndex = key($slices);

// We check only the farthest index, if it's within the size of collection, other indices will be valid too.
if (!\is_int($farthestSliceIndex) || $farthestSliceIndex > $oldSize) {
throw new \OutOfBoundsException(sprintf('Cannot insert index "%s" outside of collection.', $farthestSliceIndex));
}

$previousSliceIndex = $oldSize;

// since we only move already existing items around, we directly call into SplFixedArray::offset* methods.
Expand All @@ -867,10 +874,6 @@ public function insertSlices(array $slices): void
throw new \OutOfBoundsException(sprintf('Invalid index "%s".', $index));
}

if ($index > $oldSize) {
throw new \OutOfBoundsException(sprintf('Cannot insert index "%s" outside of collection.', $index));
}

$slice = \is_array($slice) || $slice instanceof self ? $slice : [$slice];
$sliceCount = \count($slice);

Expand Down

0 comments on commit c361910

Please sign in to comment.