1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Lanin \Laravel \ApiExceptions ;
4
6
5
7
use Illuminate \Contracts \Support \Arrayable ;
10
12
11
13
abstract class ApiException extends IdException implements Jsonable, \JsonSerializable, Arrayable
12
14
{
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
+ ) {
26
22
parent ::__construct ($ id , $ message , $ previous , $ statusCode );
27
23
}
28
24
29
- /**
30
- * Return headers array.
31
- *
32
- * @return array
33
- */
34
- public function getHeaders ()
25
+ public function getHeaders (): array
35
26
{
36
27
return $ this ->headers ;
37
28
}
38
29
39
- /**
40
- * Convert the object into something JSON serializable.
41
- *
42
- * @return array
43
- */
44
- public function jsonSerialize ()
30
+ public function jsonSerialize (): mixed
45
31
{
46
32
return $ this ->toArray ();
47
33
}
48
34
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
56
36
{
57
37
return json_encode ($ this ->toArray ());
58
38
}
59
39
60
- /**
61
- * Convert exception to array.
62
- *
63
- * @return array
64
- */
65
- public function toArray ()
40
+ public function toArray (): array
66
41
{
67
42
$ e = $ this ;
68
43
@@ -76,7 +51,7 @@ public function toArray()
76
51
77
52
if ($ e instanceof ApiException) {
78
53
$ meta = $ this ->getMeta ();
79
- if (! empty ($ meta )) {
54
+ if (!empty ($ meta )) {
80
55
$ return ['meta ' ] = $ meta ;
81
56
}
82
57
}
@@ -88,20 +63,16 @@ public function toArray()
88
63
return $ return ;
89
64
}
90
65
91
- /**
92
- * Prepare exception for report.
93
- *
94
- * @return string
95
- */
96
- public function toReport ()
66
+ public function toReport (): self
97
67
{
98
68
return $ this ;
99
69
}
100
70
101
71
/**
102
72
* Add extra info to the output.
103
- *
104
- * @return mixed
105
73
*/
106
- public function getMeta () {}
74
+ public function getMeta (): array
75
+ {
76
+ return [];
77
+ }
107
78
}
0 commit comments