length(); if ($offset < -$len || $offset > $len) { throw new InvalidArgumentException("Offset must be in range [-$len, $len]"); } if ($offset < 0) { $offset += $len; } return $offset; } /** * @param int $offset * @param int|null $length * * @return int * * @internal * */ protected function prepareLength(int $offset, ?int $length): int { $length = (null === $length) ? ($this->length() - $offset) : ( ($length < 0) ? ($length + $this->length() - $offset) : $length ); if ($length < 0) { throw new InvalidArgumentException('Length too small'); } if ($offset + $length > $this->length()) { throw new InvalidArgumentException('Length too large'); } return $length; } }