Skip to content

Commit b246ab6

Browse files
committed
rangeDescription
1 parent 0eff6c3 commit b246ab6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/IntRange.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ abstract protected function min(): int;
1717
/** The maximum allowed value. */
1818
abstract protected function max(): int;
1919

20-
public ?string $description = 'Checks if the given column is of the format 96-well column';
21-
2220
public function serialize($value)
2321
{
2422
if (is_int($value) && $this->isValueInExpectedRange($value)) {
2523
return $value;
2624
}
2725

2826
$notInRange = Utils::printSafe($value);
29-
throw new \InvalidArgumentException("Value not in range: {$notInRange}.");
27+
throw new \InvalidArgumentException("Value not in range {$this->rangeDescription()}: {$notInRange}.");
3028
}
3129

3230
public function parseValue($value)
@@ -36,7 +34,7 @@ public function parseValue($value)
3634
}
3735

3836
$notInRange = Utils::printSafe($value);
39-
throw new Error("Value not in range: {$notInRange}.");
37+
throw new Error("Value not in range {$this->rangeDescription()}: {$notInRange}.");
4038
}
4139

4240
public function parseLiteral(Node $valueNode, ?array $variables = null)
@@ -49,11 +47,19 @@ public function parseLiteral(Node $valueNode, ?array $variables = null)
4947
}
5048

5149
$notInRange = Printer::doPrint($valueNode);
52-
throw new Error("Value not in range: {$notInRange}.", $valueNode);
50+
throw new Error("Value not in range {$this->rangeDescription()}: {$notInRange}.", $valueNode);
5351
}
5452

5553
private function isValueInExpectedRange(int $value): bool
5654
{
5755
return $value <= static::max() && $value >= static::min();
5856
}
57+
58+
private function rangeDescription(): string
59+
{
60+
$min = static::min();
61+
$max = static::max();
62+
63+
return "{$min}-{$max}";
64+
}
5965
}

tests/IntRangeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ final class IntRangeTest extends TestCase
1010
public function testSerializeThrowsIfNotAnInt(): void
1111
{
1212
$this->expectException(\InvalidArgumentException::class);
13-
$this->expectExceptionMessage('Value not in range: "12".');
13+
$this->expectExceptionMessage('Value not in range 1-12: "12".');
1414

1515
(new UpToADozen())->serialize('12');
1616
}
1717

1818
public function testSerializeThrowsIfInvalid(): void
1919
{
2020
$this->expectException(\InvalidArgumentException::class);
21-
$this->expectExceptionMessage('Value not in range: 13.');
21+
$this->expectExceptionMessage('Value not in range 1-12: 13.');
2222

2323
(new UpToADozen())->serialize(13);
2424
}
@@ -33,7 +33,7 @@ public function testSerializePassesWhenValid(): void
3333
public function testParseValueThrowsIfInvalid(): void
3434
{
3535
$this->expectException(Error::class);
36-
$this->expectExceptionMessage('Value not in range: 13.');
36+
$this->expectExceptionMessage('Value not in range 1-12: 13.');
3737

3838
(new UpToADozen())->parseValue(13);
3939
}

0 commit comments

Comments
 (0)