1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2025 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Schema\Tool\ToolSchema;
15:
16: /**
17: * The `integer` type is a subtype of `number` type used for validating only integer numbers.
18: *
19: * @extends ToolSchema<int, array{
20: * type: 'integer',
21: * description?: non-empty-string,
22: * title?: non-empty-string,
23: * minimum?: int,
24: * maximum?: int,
25: * multipleOf: 1,
26: * default?: int,
27: * }>
28: */
29: final class IntegerType extends ToolSchema
30: {
31: private ?int $minimum = null;
32: private ?int $maximum = null;
33:
34: public function minimum(int $minimum): self
35: {
36: $this->minimum = $minimum;
37:
38: return $this;
39: }
40:
41: public function maximum(int $maximum): self
42: {
43: $this->maximum = $maximum;
44:
45: return $this;
46: }
47:
48: #[\Override]
49: public function toArray(): array
50: {
51: if (isset($this->minimum, $this->maximum) && $this->minimum > $this->maximum) {
52: throw new \LogicException('The minimum value cannot be greater than the maximum value.');
53: }
54:
55: if (isset($this->default, $this->minimum) && $this->default < $this->minimum) {
56: throw new \LogicException('The default value cannot be less than the minimum value.');
57: }
58:
59: if (isset($this->default, $this->maximum) && $this->default > $this->maximum) {
60: throw new \LogicException('The default value cannot be greater than the maximum value.');
61: }
62:
63: return array_filter([
64: 'type' => 'integer',
65: 'description' => $this->description,
66: 'title' => $this->title,
67: 'minimum' => $this->minimum,
68: 'maximum' => $this->maximum,
69: 'multipleOf' => 1,
70: 'default' => $this->default,
71: ], static fn(mixed $value): bool => null !== $value);
72: }
73: }
74: