@@ -10,24 +10,42 @@ class ApiResponse extends JsonResponse
1010{
1111 use ValidationPreparationTrait;
1212
13- public const MSGTYPE_SUCCESS = 'success ' ;
14- public const MSGTYPE_INFO = 'info ' ;
15- public const MSGTYPE_WARNING = 'warning ' ;
16- public const MSGTYPE_ERROR = 'error ' ;
17- public const EMPTY_MESSAGES = [
13+ public const string MSGTYPE_SUCCESS = 'success ' ;
14+ public const string MSGTYPE_INFO = 'info ' ;
15+ public const string MSGTYPE_WARNING = 'warning ' ;
16+ public const string MSGTYPE_ERROR = 'error ' ;
17+ public const array EMPTY_MESSAGES = [
1818 self ::MSGTYPE_SUCCESS => [],
1919 self ::MSGTYPE_INFO => [],
2020 self ::MSGTYPE_WARNING => [],
2121 self ::MSGTYPE_ERROR => [],
2222 ];
23- public const VALID_ROOT = 'root ' ;
23+ public const string VALID_ROOT = 'root ' ;
2424
25+ /** @var array<mixed> */
2526 private array $ apiData = [];
27+
28+ /**
29+ * @var array{
30+ * 'success'?: string[],
31+ * 'info'?: string[],
32+ * 'warning'?: string[],
33+ * 'error'?: string[],
34+ * }
35+ */
2636 private array $ apiMessages = self ::EMPTY_MESSAGES ;
37+
38+ /** @var array<string, string[]> */
2739 private array $ validation = [];
40+
2841 private Throwable |null $ throwable = null ;
2942
3043
44+ /**
45+ * @param mixed $data
46+ * @param int $status
47+ * @param array<string, string|string[]|null> $headers
48+ */
3149 public function __construct (mixed $ data = [], int $ status = 200 , array $ headers = [])
3250 {
3351 parent ::__construct ('' , $ status , $ headers , true );
@@ -51,17 +69,18 @@ public function __construct(mixed $data = [], int $status = 200, array $headers
5169 /**
5270 * Factory method for chainability
5371 *
54- * @param array $data
55- * @param int $status
56- * @param array $headers
72+ * @param mixed $data
73+ * @param int $status
74+ * @param array<string, string|string[]|null> $headers
5775 *
5876 * @return ApiResponse
5977 */
60- public static function create (array $ data = [], int $ status = 200 , array $ headers = []): self
78+ public static function create (mixed $ data = [], int $ status = 200 , array $ headers = []): self
6179 {
6280 return new self ($ data , $ status , $ headers );
6381 }
6482
83+ /** @return array<mixed> */
6584 public function getData (): array
6685 {
6786 return $ this ->apiData ;
@@ -75,6 +94,11 @@ public function setData(mixed $data = []): static
7594 return $ this ;
7695 }
7796
97+ /**
98+ * @param string|null $type
99+ *
100+ * @return array<string, string[]>|string[]
101+ */
78102 public function getMessages (string |null $ type = null ): array
79103 {
80104 if (null !== $ type && array_key_exists ($ type , $ this ->apiMessages )) {
@@ -94,6 +118,12 @@ public function addMessage(string $type, string $message): self
94118 return $ this ;
95119 }
96120
121+ /**
122+ * @param string $type
123+ * @param string[] $messages
124+ *
125+ * @return $this
126+ */
97127 public function mergeMessages (string $ type , array $ messages ): self
98128 {
99129 if (array_key_exists ($ type , $ this ->apiMessages )) {
@@ -130,8 +160,15 @@ public function addValidationIssue(string $component, string $message): self
130160 return $ this ;
131161 }
132162
163+ /**
164+ * @param string $component
165+ * @param string[] $messages
166+ *
167+ * @return $this
168+ */
133169 public function mergeValidationIssues (string $ component , array $ messages ): self
134170 {
171+ // @phpstan-ignore-next-line
135172 $ messages = array_filter ($ messages , fn ($ message ): bool => is_string ($ message ) && !empty ($ message ));
136173
137174 if (empty ($ messages )) {
0 commit comments