Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Mar 11, 2024
1 parent c740b01 commit d1e15dd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Views/ArrayView.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public function offsetExists($offset): bool
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
/** @var mixed $offset */
if (\is_numeric($offset)) {
if (!$this->numericOffsetExists($offset)) {
throw new IndexError("Index {$offset} is out of range.");
Expand All @@ -254,7 +255,7 @@ public function offsetGet($offset)
return $this->subview($offset)->toArray();
}

$strOffset = is_scalar($offset) ? strval($offset) : gettype($offset);
$strOffset = \is_scalar($offset) ? \strval($offset) : \gettype($offset);
throw new KeyError("Invalid key: \"{$strOffset}\".");
}

Expand All @@ -265,6 +266,7 @@ public function offsetGet($offset)
*/
public function offsetSet($offset, $value): void
{
/** @var mixed $offset */
if ($this->isReadonly()) {
throw new ReadonlyError("Cannot modify a readonly view.");
}
Expand All @@ -290,7 +292,7 @@ public function offsetSet($offset, $value): void
return;
}

$strOffset = is_scalar($offset) ? strval($offset) : gettype($offset);
$strOffset = \is_scalar($offset) ? \strval($offset) : \gettype($offset);
throw new KeyError("Invalid key: \"{$strOffset}\".");
}

Expand Down Expand Up @@ -334,7 +336,7 @@ protected function convertIndex(int $i): int
*/
private function numericOffsetExists($offset): bool
{
if (is_nan($offset) || is_infinite($offset)) {
if (!\is_string($offset) && \is_numeric($offset) && (\is_nan($offset) || \is_infinite($offset))) {
return false;
}

Expand Down

0 comments on commit d1e15dd

Please sign in to comment.