44namespace nickdnk \OpenAPI \Components ;
55
66use InvalidArgumentException ;
7+ use JetBrains \PhpStorm \Pure ;
78use JsonSerializable ;
89use nickdnk \OpenAPI \Components \Security \RequiredSecurityScheme ;
910use nickdnk \OpenAPI \OpenAPIDocument ;
@@ -21,90 +22,87 @@ class Endpoint implements JsonSerializable
2122 const CONTENT_TYPE_APPLICATION_JSON = 'application/json ' ;
2223 const CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlencoded ' ;
2324
24- private $ tag , $ summary , $ description , $ responses ;
2525 /**
26- * @var array|null
26+ * @var Response[]
2727 */
28- private $ requestBodies ;
29- /**
30- * @var array|null
31- */
32- private $ parameters ;
33- /**
34- * @var string
35- */
36- private $ httpMethod ;
28+ private array $ responses ;
29+
30+ /** @var Base[]|null $requestBodies */
31+ private ?array $ requestBodies ;
32+
3733 /**
38- * @var bool
34+ * @var Parameter[]|null
3935 */
40- private $ deprecated ;
36+ private ? array $ parameters ;
4137
4238 /**
4339 * @var string[]|null
4440 */
45- private $ requiredSecuritySchemes ;
41+ private ? array $ requiredSecuritySchemes ;
4642
47- /**
48- * Endpoint constructor.
49- *
50- * @param string $httpMethod
51- * @param string $summary
52- * @param string $description
53- * @param Response[] $responses
54- * @param Parameter[]|null $parameters
55- */
56- private function __construct (string $ httpMethod , string $ summary , string $ description , array $ responses ,
57- ?array $ parameters = null
43+ private ?string $ tag ;
44+ private string $ httpMethod , $ summary , $ description ;
45+ private bool $ deprecated ;
46+
47+ #[Pure]
48+ private function __construct (string $ httpMethod , string $ summary , string $ description
5849 )
5950 {
6051
61- $ this ->tag = null ; // set by section on output.
52+ $ this ->requiredSecuritySchemes = null ;
53+ $ this ->requestBodies = null ;
54+ $ this ->tag = null ;
6255 $ this ->summary = $ summary ;
6356 $ this ->description = $ description ;
64- $ this ->responses = $ responses ;
65- $ this ->parameters = $ parameters ;
57+ $ this ->responses = [] ;
58+ $ this ->parameters = null ;
6659 $ this ->httpMethod = $ httpMethod ;
6760 $ this ->deprecated = false ;
6861
6962 }
7063
64+ #[Pure]
7165 final public static function get (string $ andSummary , string $ description ): self
7266 {
7367
7468 return new self (
75- self ::GET , $ andSummary , $ description, []
69+ self ::GET , $ andSummary , $ description
7670 );
7771 }
7872
73+ #[Pure]
7974 final public static function post (string $ andSummary , string $ description ): self
8075 {
8176
8277 return new self (
83- self ::POST , $ andSummary , $ description, []
78+ self ::POST , $ andSummary , $ description
8479 );
8580 }
8681
82+ #[Pure]
8783 final public static function put (string $ andSummary , string $ description ): self
8884 {
8985
9086 return new self (
91- self ::PUT , $ andSummary , $ description, []
87+ self ::PUT , $ andSummary , $ description
9288 );
9389 }
9490
91+ #[Pure]
9592 final public static function delete (string $ andSummary , string $ description ): self
9693 {
9794
9895 return new self (
99- self ::DELETE , $ andSummary , $ description, []
96+ self ::DELETE , $ andSummary , $ description
10097 );
10198 }
10299
100+ #[Pure]
103101 final public static function patch (string $ andSummary , string $ description ): self
104102 {
105103
106104 return new self (
107- self ::PATCH , $ andSummary , $ description, []
105+ self ::PATCH , $ andSummary , $ description
108106 );
109107 }
110108
@@ -145,7 +143,7 @@ public function withParameters(Parameter ...$parameter): self
145143 *
146144 * @return Endpoint
147145 */
148- public function withRequiredSecuritySchemes ($ securityScheme ): self
146+ public function withRequiredSecuritySchemes (array | RequiredSecurityScheme $ securityScheme ): self
149147 {
150148
151149 if ($ this ->requiredSecuritySchemes === null ) {
@@ -168,7 +166,7 @@ public function withRequestBodyFromDocument(Base $class, string $contentType = s
168166 {
169167
170168 if ($ this ->httpMethod === Endpoint::GET ) {
171- throw new InvalidArgumentException ('Passed request body entity ' . ( is_string ( $ class) ? ( $ class . ' ' ) : '' ) . ' to GET endpoint. ' );
169+ throw new InvalidArgumentException ('Passed request body entity ' . $ class:: class . ' to GET endpoint. ' );
172170 }
173171
174172 if ($ this ->requestBodies === null ) {
@@ -198,6 +196,7 @@ public function withRequestBodyFromEntity(string $class, string $contentType = s
198196
199197 }
200198
199+ #[Pure]
201200 final public function getHttpMethod (): string
202201 {
203202
@@ -207,6 +206,7 @@ final public function getHttpMethod(): string
207206 /**
208207 * @return Response[]
209208 */
209+ #[Pure]
210210 final public function getResponses (): array
211211 {
212212
0 commit comments