File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,8 @@ interface AnnotatedType extends Type
1616 public function entitled (string $ title );
1717
1818 public function describedAs (string $ description );
19+
20+ public function withDefault ($ default );
21+
22+ public function withExamples (...$ examples );
1923}
Original file line number Diff line number Diff line change @@ -23,6 +23,16 @@ trait HasAnnotations
2323 */
2424 protected $ description ;
2525
26+ /**
27+ * @var mixed
28+ */
29+ protected $ default ;
30+
31+ /**
32+ * @var array<mixed>
33+ */
34+ protected $ examples ;
35+
2636 public function entitled (string $ title ): self
2737 {
2838 $ cp = clone $ this ;
@@ -51,6 +61,43 @@ public function description(): ?string
5161 return $ this ->description ;
5262 }
5363
64+ /**
65+ * @param mixed $default
66+ */
67+ public function withDefault ($ default ): self
68+ {
69+ $ cp = clone $ this ;
70+
71+ $ cp ->default = $ default ;
72+
73+ return $ cp ;
74+ }
75+
76+ /**
77+ * @return mixed
78+ */
79+ public function defaultValue ()
80+ {
81+ return $ this ->default ;
82+ }
83+
84+ public function withExamples (...$ examples ): self
85+ {
86+ $ cp = clone $ this ;
87+
88+ $ cp ->examples = $ examples ;
89+
90+ return $ cp ;
91+ }
92+
93+ /**
94+ * @return array<mixed>
95+ */
96+ public function examples (): array
97+ {
98+ return $ this ->examples ;
99+ }
100+
54101 public function annotations (): array
55102 {
56103 $ annotations = [];
@@ -63,6 +110,14 @@ public function annotations(): array
63110 $ annotations ['description ' ] = $ this ->description ;
64111 }
65112
113+ if (null !== $ this ->default ) {
114+ $ annotations ['default ' ] = $ this ->default ;
115+ }
116+
117+ if (null !== $ this ->examples ) {
118+ $ annotations ['examples ' ] = $ this ->examples ;
119+ }
120+
66121 return $ annotations ;
67122 }
68123}
You can’t perform that action at this time.
0 commit comments