Skip to content

Commit 202408c

Browse files
committed
Rename ToolSchema constructors
1 parent 013ec46 commit 202408c

File tree

11 files changed

+102
-102
lines changed

11 files changed

+102
-102
lines changed

src/Schema/Tool/ToolSchema/ToolSchema.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,39 +66,39 @@ public static function root(self ...$properties): ObjectType
6666
/**
6767
* @param non-empty-string $name
6868
*/
69-
public static function fromArray(string $name): ArrayType
69+
public static function asArray(string $name): ArrayType
7070
{
7171
return new ArrayType($name);
7272
}
7373

7474
/**
7575
* @param non-empty-string $name
7676
*/
77-
public static function fromBoolean(string $name): BooleanType
77+
public static function asBoolean(string $name): BooleanType
7878
{
7979
return new BooleanType($name);
8080
}
8181

8282
/**
8383
* @param non-empty-string $name
8484
*/
85-
public static function fromInteger(string $name): IntegerType
85+
public static function asInteger(string $name): IntegerType
8686
{
8787
return new IntegerType($name);
8888
}
8989

9090
/**
9191
* @param non-empty-string $name
9292
*/
93-
public static function fromNull(string $name): NullType
93+
public static function asNull(string $name): NullType
9494
{
9595
return new NullType($name);
9696
}
9797

9898
/**
9999
* @param non-empty-string $name
100100
*/
101-
public static function fromNumber(string $name): NumberType
101+
public static function asNumber(string $name): NumberType
102102
{
103103
return new NumberType($name);
104104
}
@@ -110,15 +110,15 @@ public static function fromNumber(string $name): NumberType
110110
* @param non-empty-string $name
111111
* @param self<covariant Tu, covariant Tv> ...$properties
112112
*/
113-
public static function fromObject(string $name, self ...$properties): ObjectType
113+
public static function asObject(string $name, self ...$properties): ObjectType
114114
{
115115
return new ObjectType($name, ...$properties);
116116
}
117117

118118
/**
119119
* @param non-empty-string $name
120120
*/
121-
public static function fromString(string $name): StringType
121+
public static function asString(string $name): StringType
122122
{
123123
return new StringType($name);
124124
}

tests/Schema/Result/ListToolsResultTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testResultCanBeJsonSerialized(): void
3737
title: 'Weather Information Provider',
3838
description: 'Get the current weather in a given location',
3939
inputSchema: ToolSchema::root(
40-
ToolSchema::fromString('location')->description('City name or zip code')->required(),
40+
ToolSchema::asString('location')->description('City name or zip code')->required(),
4141
),
4242
icons: [
4343
new Icon('https://example.com/weather-icon.png', 'image/png', ['64x64']),

tests/Schema/Tool/ToolSchema/ArrayTypeTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ final class ArrayTypeTest extends TestCase
2828
{
2929
public function testArraySchemaCanBeJsonSerialized(): void
3030
{
31-
$schema = ToolSchema::fromArray('items');
31+
$schema = ToolSchema::asArray('items');
3232

3333
self::assertSame(['type' => 'array'], $schema->toArray());
3434
self::assertSame('{"type":"array"}', json_encode($schema));
3535
}
3636

3737
public function testArraySchemaCanSetMinItems(): void
3838
{
39-
$schema = ToolSchema::fromArray('items')->minItems(1);
39+
$schema = ToolSchema::asArray('items')->minItems(1);
4040

4141
self::assertSame(['type' => 'array', 'minItems' => 1], $schema->toArray());
4242
self::assertSame('{"type":"array","minItems":1}', json_encode($schema));
@@ -47,20 +47,20 @@ public function testArraySchemaDoesNotAcceptNegativeMinItems(): void
4747
$this->expectException(\InvalidArgumentException::class);
4848
$this->expectExceptionMessage('The minimum number of items must be a non-negative integer.');
4949

50-
ToolSchema::fromArray('items')->minItems(-1);
50+
ToolSchema::asArray('items')->minItems(-1);
5151
}
5252

5353
public function testArraySchemaCanSetZeroMinItems(): void
5454
{
55-
$schema = ToolSchema::fromArray('items')->minItems(0);
55+
$schema = ToolSchema::asArray('items')->minItems(0);
5656

5757
self::assertSame(['type' => 'array', 'minItems' => 0], $schema->toArray());
5858
self::assertSame('{"type":"array","minItems":0}', json_encode($schema));
5959
}
6060

6161
public function testArraySchemaCanSetMaxItems(): void
6262
{
63-
$schema = ToolSchema::fromArray('items')->maxItems(5);
63+
$schema = ToolSchema::asArray('items')->maxItems(5);
6464

6565
self::assertSame(['type' => 'array', 'maxItems' => 5], $schema->toArray());
6666
self::assertSame('{"type":"array","maxItems":5}', json_encode($schema));
@@ -71,31 +71,31 @@ public function testArraySchemaDoesNotAcceptNegativeMaxItems(): void
7171
$this->expectException(\InvalidArgumentException::class);
7272
$this->expectExceptionMessage('The maximum number of items must be a non-negative integer.');
7373

74-
ToolSchema::fromArray('items')->maxItems(-1);
74+
ToolSchema::asArray('items')->maxItems(-1);
7575
}
7676

7777
public function testArraySchemaCanSetZeroMaxItems(): void
7878
{
79-
$schema = ToolSchema::fromArray('items')->maxItems(0);
79+
$schema = ToolSchema::asArray('items')->maxItems(0);
8080

8181
self::assertSame(['type' => 'array', 'maxItems' => 0], $schema->toArray());
8282
self::assertSame('{"type":"array","maxItems":0}', json_encode($schema));
8383
}
8484

8585
public function testArraySchemaCanSetUniqueItems(): void
8686
{
87-
$schema = ToolSchema::fromArray('items')->uniqueItems(true);
87+
$schema = ToolSchema::asArray('items')->uniqueItems(true);
8888
self::assertSame(['type' => 'array', 'uniqueItems' => true], $schema->toArray());
8989
self::assertSame('{"type":"array","uniqueItems":true}', json_encode($schema));
9090

91-
$schema = ToolSchema::fromArray('items')->uniqueItems(false);
91+
$schema = ToolSchema::asArray('items')->uniqueItems(false);
9292
self::assertSame(['type' => 'array', 'uniqueItems' => false], $schema->toArray());
9393
self::assertSame('{"type":"array","uniqueItems":false}', json_encode($schema));
9494
}
9595

9696
public function testArraySchemaCanSetPrefixItems(): void
9797
{
98-
$schema = ToolSchema::fromArray('items')->prefixItems(ToolSchema::fromString('item1'));
98+
$schema = ToolSchema::asArray('items')->prefixItems(ToolSchema::asString('item1'));
9999

100100
self::assertSame([
101101
'type' => 'array',
@@ -109,7 +109,7 @@ public function testArraySchemaCanSetPrefixItems(): void
109109

110110
public function testArraySchemaCanSetItemsSchema(): void
111111
{
112-
$schema = ToolSchema::fromArray('items')->items(ToolSchema::fromString('item'));
112+
$schema = ToolSchema::asArray('items')->items(ToolSchema::asString('item'));
113113

114114
self::assertSame([
115115
'type' => 'array',
@@ -123,14 +123,14 @@ public function testArraySchemaCanSetItemsSchema(): void
123123

124124
public function testArraySchemaCanSetAllOptions(): void
125125
{
126-
$schema = ToolSchema::fromArray('items')
126+
$schema = ToolSchema::asArray('items')
127127
->title('Items')
128128
->description('An array of items')
129129
->minItems(1)
130130
->maxItems(5)
131131
->uniqueItems(true)
132-
->prefixItems(ToolSchema::fromString('item1'))
133-
->items(ToolSchema::fromString('item'))
132+
->prefixItems(ToolSchema::asString('item1'))
133+
->items(ToolSchema::asString('item'))
134134
->default(['item1', 'item2'])
135135
;
136136

tests/Schema/Tool/ToolSchema/BooleanTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class BooleanTypeTest extends TestCase
2828
{
2929
public function testBooleanSchemaCanBeJsonSerialized(): void
3030
{
31-
$schema = ToolSchema::fromBoolean('isActive')
31+
$schema = ToolSchema::asBoolean('isActive')
3232
->title('Is Active')
3333
->description('Indicates whether the user is active.')
3434
->default(true)

tests/Schema/Tool/ToolSchema/IntegerTypeTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,31 @@ final class IntegerTypeTest extends TestCase
2828
{
2929
public function testIntegerSchemaCanBeJsonSerialized(): void
3030
{
31-
$schema = ToolSchema::fromInteger('rating');
31+
$schema = ToolSchema::asInteger('rating');
3232

3333
self::assertSame(['type' => 'integer', 'multipleOf' => 1], $schema->toArray());
3434
self::assertSame('{"type":"integer","multipleOf":1}', json_encode($schema));
3535
}
3636

3737
public function testIntegerSchemaCanSetMinimum(): void
3838
{
39-
$schema = ToolSchema::fromInteger('rating')->minimum(1);
39+
$schema = ToolSchema::asInteger('rating')->minimum(1);
4040

4141
self::assertSame(['type' => 'integer', 'minimum' => 1, 'multipleOf' => 1], $schema->toArray());
4242
self::assertSame('{"type":"integer","minimum":1,"multipleOf":1}', json_encode($schema));
4343
}
4444

4545
public function testIntegerSchemaCanSetMaximum(): void
4646
{
47-
$schema = ToolSchema::fromInteger('rating')->maximum(5);
47+
$schema = ToolSchema::asInteger('rating')->maximum(5);
4848

4949
self::assertSame(['type' => 'integer', 'maximum' => 5, 'multipleOf' => 1], $schema->toArray());
5050
self::assertSame('{"type":"integer","maximum":5,"multipleOf":1}', json_encode($schema));
5151
}
5252

5353
public function testIntegerSchemaAllowsSameMinimumAndMaximum(): void
5454
{
55-
$schema = ToolSchema::fromInteger('rating')->minimum(5)->maximum(5);
55+
$schema = ToolSchema::asInteger('rating')->minimum(5)->maximum(5);
5656

5757
self::assertSame([
5858
'type' => 'integer',
@@ -68,7 +68,7 @@ public function testIntegerSchemaAllowsSameMinimumAndMaximum(): void
6868

6969
public function testIntegerSchemaAllowsSameDefaultAsMinimum(): void
7070
{
71-
$schema = ToolSchema::fromInteger('rating')->minimum(1)->default(1);
71+
$schema = ToolSchema::asInteger('rating')->minimum(1)->default(1);
7272

7373
self::assertSame([
7474
'type' => 'integer',
@@ -84,7 +84,7 @@ public function testIntegerSchemaAllowsSameDefaultAsMinimum(): void
8484

8585
public function testIntegerSchemaAllowsSameDefaultAsMaximum(): void
8686
{
87-
$schema = ToolSchema::fromInteger('rating')->maximum(5)->default(5);
87+
$schema = ToolSchema::asInteger('rating')->maximum(5)->default(5);
8888

8989
self::assertSame([
9090
'type' => 'integer',
@@ -100,7 +100,7 @@ public function testIntegerSchemaAllowsSameDefaultAsMaximum(): void
100100

101101
public function testIntegerSchemaCanSetAllConstraints(): void
102102
{
103-
$schema = ToolSchema::fromInteger('rating')
103+
$schema = ToolSchema::asInteger('rating')
104104
->minimum(1)
105105
->maximum(5)
106106
;
@@ -122,28 +122,28 @@ public function testIntegerSchemaDoesNotAllowMinimumGreaterThanMaximum(): void
122122
$this->expectException(\LogicException::class);
123123
$this->expectExceptionMessage('The minimum value cannot be greater than the maximum value.');
124124

125-
ToolSchema::fromInteger('rating')->minimum(5)->maximum(1)->toArray();
125+
ToolSchema::asInteger('rating')->minimum(5)->maximum(1)->toArray();
126126
}
127127

128128
public function testIntegerSchemaDoesNotAllowDefaultLessThanMinimum(): void
129129
{
130130
$this->expectException(\LogicException::class);
131131
$this->expectExceptionMessage('The default value cannot be less than the minimum value.');
132132

133-
ToolSchema::fromInteger('rating')->minimum(1)->default(0)->toArray();
133+
ToolSchema::asInteger('rating')->minimum(1)->default(0)->toArray();
134134
}
135135

136136
public function testIntegerSchemaDoesNotAllowDefaultGreaterThanMaximum(): void
137137
{
138138
$this->expectException(\LogicException::class);
139139
$this->expectExceptionMessage('The default value cannot be greater than the maximum value.');
140140

141-
ToolSchema::fromInteger('rating')->maximum(5)->default(6)->toArray();
141+
ToolSchema::asInteger('rating')->maximum(5)->default(6)->toArray();
142142
}
143143

144144
public function testIntegerSchemaCanSetDescriptionAndTitle(): void
145145
{
146-
$schema = ToolSchema::fromInteger('rating')
146+
$schema = ToolSchema::asInteger('rating')
147147
->description('The rating of the product')
148148
->title('Product Rating')
149149
->minimum(1)

tests/Schema/Tool/ToolSchema/NullTypeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ final class NullTypeTest extends TestCase
2828
{
2929
public function testNullSchemaCanBeJsonSerialized(): void
3030
{
31-
$schema = ToolSchema::fromNull('nullableProp');
31+
$schema = ToolSchema::asNull('nullableProp');
3232

3333
self::assertSame(['type' => 'null'], $schema->toArray());
3434
self::assertSame('{"type":"null"}', json_encode($schema));
3535
}
3636

3737
public function testNullSchemaCanHaveDescriptionAndTitle(): void
3838
{
39-
$schema = ToolSchema::fromNull('nullableProp')
39+
$schema = ToolSchema::asNull('nullableProp')
4040
->description('This property can be null.')
4141
->title('Nullable Property')
4242
;

0 commit comments

Comments
 (0)