-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOffsetOutOfRange.php
More file actions
35 lines (28 loc) · 1000 Bytes
/
Copy pathOffsetOutOfRange.php
File metadata and controls
35 lines (28 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace TinyBlocks\HttpQuery\Exceptions;
use InvalidArgumentException;
/**
* Raised when a requested offset falls outside the valid range.
*
* The offset is zero-based, so it must be greater than or equal to 0.
*/
final class OffsetOutOfRange extends InvalidArgumentException implements HttpQueryException
{
private const string REASON_TEMPLATE = 'Offset <%d> must be greater than or equal to 0.';
private function __construct(int $offset)
{
$template = OffsetOutOfRange::REASON_TEMPLATE;
parent::__construct(message: sprintf($template, $offset));
}
/**
* Creates an OffsetOutOfRange from the offending offset.
*
* @param int $offset The offset that fell outside the valid range.
* @return OffsetOutOfRange The composed exception describing the invalid offset.
*/
public static function from(int $offset): OffsetOutOfRange
{
return new OffsetOutOfRange(offset: $offset);
}
}