11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Lanin \Laravel \ApiExceptions ;
46
57use Illuminate \Contracts \Support \Arrayable ;
1012
1113abstract class ApiException extends IdException implements Jsonable, \JsonSerializable, Arrayable
1214{
13- protected $ headers = [];
14-
15- /**
16- * @param int $statusCode
17- * @param string $id
18- * @param string $message
19- * @param \Throwable|null $previous
20- * @param array $headers
21- */
22- public function __construct ($ statusCode = 0 , $ id = '' , $ message = '' , ?\Throwable $ previous = null , array $ headers = [])
23- {
24- $ this ->headers = $ headers ;
25-
15+ public function __construct (
16+ int $ statusCode = 0 ,
17+ string $ id = '' ,
18+ string $ message = '' ,
19+ ?\Throwable $ previous = null ,
20+ protected array $ headers = [],
21+ ) {
2622 parent ::__construct ($ id , $ message , $ previous , $ statusCode );
2723 }
2824
29- /**
30- * Return headers array.
31- *
32- * @return array
33- */
34- public function getHeaders ()
25+ public function getHeaders (): array
3526 {
3627 return $ this ->headers ;
3728 }
3829
39- /**
40- * Convert the object into something JSON serializable.
41- *
42- * @return array
43- */
44- public function jsonSerialize ()
30+ public function jsonSerialize (): mixed
4531 {
4632 return $ this ->toArray ();
4733 }
4834
49- /**
50- * Convert exception to JSON.
51- *
52- * @param int $options
53- * @return array
54- */
55- public function toJson ($ options = 0 )
35+ public function toJson ($ options = 0 ): string
5636 {
5737 return json_encode ($ this ->toArray ());
5838 }
5939
60- /**
61- * Convert exception to array.
62- *
63- * @return array
64- */
65- public function toArray ()
40+ public function toArray (): array
6641 {
6742 $ e = $ this ;
6843
@@ -76,7 +51,7 @@ public function toArray()
7651
7752 if ($ e instanceof ApiException) {
7853 $ meta = $ this ->getMeta ();
79- if (! empty ($ meta )) {
54+ if (!empty ($ meta )) {
8055 $ return ['meta ' ] = $ meta ;
8156 }
8257 }
@@ -88,20 +63,16 @@ public function toArray()
8863 return $ return ;
8964 }
9065
91- /**
92- * Prepare exception for report.
93- *
94- * @return string
95- */
96- public function toReport ()
66+ public function toReport (): self
9767 {
9868 return $ this ;
9969 }
10070
10171 /**
10272 * Add extra info to the output.
103- *
104- * @return mixed
10573 */
106- public function getMeta () {}
74+ public function getMeta (): array
75+ {
76+ return [];
77+ }
10778}
0 commit comments