2 declare(strict_types = 1);
76 throw new \InvalidArgumentException(
'start must be string', 1537277163);
78 if (!is_string(
$end)) {
79 throw new \InvalidArgumentException(
'end must be string', 1537277164);
91 public function count(): int
93 return count($this->range);
99 public function generate(
string $value): ?string
107 public function resolve(
string $value): ?string
118 if (in_array($value, $this->range,
true)) {
138 $range = array_map(
'strval', range($this->start, $this->end));
140 throw new \LengthException(
141 'Range is larger than 1000 items',
154 if (!preg_match(
'#^\d+$#', $this->start)
155 || !preg_match(
'#^\d+$#', $this->end)
156 || $this->start ===
'0' || $this->end ===
'0'
157 || $this->start[0] !==
'0' && $this->end[0] !==
'0'
162 $length = strlen(max($this->start, $this->end));
164 function ($value) use ($length) {
165 return str_pad($value, $length,
'0', STR_PAD_LEFT);