99
1010class FieldBuilder
1111{
12- /** @var array<string, mixed|array<string|mixed>> */
13- private array $ parameters = [];
12+ private string $ name ;
13+
14+ private Type $ type ;
15+
16+ private string |null $ description = null ;
17+
18+ private string |null $ deprecationReason = null ;
19+
20+ /** @psalm-var callable(mixed, array<mixed>, mixed, ResolveInfo) : mixed|null */
21+ private $ resolve ;
22+
23+ /** @psalm-var array<string, array<string, mixed>>|null */
24+ private array |null $ args = null ;
1425
1526 final private function __construct (string $ name , Type $ type )
1627 {
17- $ this ->parameters [ ' name ' ] = $ name ;
18- $ this ->parameters [ ' type ' ] = $ type ;
28+ $ this ->name = $ name ;
29+ $ this ->type = $ type ;
1930 }
2031
2132 /**
@@ -31,7 +42,7 @@ public static function create(string $name, Type $type): self
3142 */
3243 public function setDescription (string $ description ): self
3344 {
34- $ this ->parameters [ ' description ' ] = $ description ;
45+ $ this ->description = $ description ;
3546
3647 return $ this ;
3748 }
@@ -41,16 +52,22 @@ public function setDescription(string $description): self
4152 */
4253 public function addArgument (string $ name , Type $ type , ?string $ description = null , mixed $ defaultValue = null ): self
4354 {
44- $ this ->parameters ['args ' ][$ name ] = ['type ' => $ type ];
55+ if ($ this ->args === null ) {
56+ $ this ->args = [];
57+ }
58+
59+ $ value = ['type ' => $ type ];
4560
4661 if ($ description !== null ) {
47- $ this -> parameters [ ' args ' ][ $ name ] ['description ' ] = $ description ;
62+ $ value ['description ' ] = $ description ;
4863 }
4964
5065 if ($ defaultValue !== null ) {
51- $ this -> parameters [ ' args ' ][ $ name ] ['defaultValue ' ] = $ defaultValue ;
66+ $ value ['defaultValue ' ] = $ defaultValue ;
5267 }
5368
69+ $ this ->args [$ name ] = $ value ;
70+
5471 return $ this ;
5572 }
5673
@@ -63,7 +80,7 @@ public function addArgument(string $name, Type $type, ?string $description = nul
6380 */
6481 public function setResolver (callable $ resolver ): self
6582 {
66- $ this ->parameters [ ' resolve ' ] = $ resolver ;
83+ $ this ->resolve = $ resolver ;
6784
6885 return $ this ;
6986 }
@@ -73,7 +90,7 @@ public function setResolver(callable $resolver): self
7390 */
7491 public function setDeprecationReason (string $ reason ): self
7592 {
76- $ this ->parameters [ ' deprecationReason ' ] = $ reason ;
93+ $ this ->deprecationReason = $ reason ;
7794
7895 return $ this ;
7996 }
@@ -83,6 +100,13 @@ public function setDeprecationReason(string $reason): self
83100 */
84101 public function build (): array
85102 {
86- return $ this ->parameters ;
103+ return [
104+ 'args ' => $ this ->args ,
105+ 'name ' => $ this ->name ,
106+ 'description ' => $ this ->description ,
107+ 'deprecationReason ' => $ this ->deprecationReason ,
108+ 'resolve ' => $ this ->resolve ,
109+ 'type ' => $ this ->type ,
110+ ];
87111 }
88112}
0 commit comments