11
11
use RuntimeException ;
12
12
13
13
use function ftruncate ;
14
- use function get_class ;
15
- use function gettype ;
16
14
use function is_callable ;
17
15
use function is_object ;
18
16
use function is_resource ;
28
26
*/
29
27
final class DataResponse implements ResponseInterface
30
28
{
31
- /**
32
- * @var mixed
33
- */
34
- private $ data ;
35
-
36
29
/**
37
30
* @var resource
38
31
*/
@@ -52,13 +45,12 @@ final class DataResponse implements ResponseInterface
52
45
* @param StreamFactoryInterface $streamFactory The stream factory instance.
53
46
*/
54
47
public function __construct (
55
- $ data ,
48
+ private mixed $ data ,
56
49
int $ code ,
57
50
string $ reasonPhrase ,
58
51
ResponseFactoryInterface $ responseFactory ,
59
52
StreamFactoryInterface $ streamFactory
60
53
) {
61
- $ this ->data = $ data ;
62
54
$ this ->createResponse ($ code , $ reasonPhrase , $ responseFactory , $ streamFactory );
63
55
}
64
56
@@ -78,7 +70,6 @@ public function getBody(): StreamInterface
78
70
return $ this ->dataStream = $ this ->response ->getBody ();
79
71
}
80
72
81
- /** @var mixed */
82
73
$ data = $ this ->getData ();
83
74
84
75
if (is_string ($ data )) {
@@ -91,7 +82,7 @@ public function getBody(): StreamInterface
91
82
92
83
throw new RuntimeException (sprintf (
93
84
'The data is "%s" not a string. To get non-string data, use the "%s::getData()" method. ' ,
94
- is_object ( $ data ) ? get_class ( $ data ) : gettype ($ data ),
85
+ get_debug_type ($ data ),
95
86
self ::class,
96
87
));
97
88
}
@@ -294,7 +285,7 @@ public function hasResponseFormatter(): bool
294
285
*
295
286
* @return self
296
287
*/
297
- public function withData ($ data ): self
288
+ public function withData (mixed $ data ): self
298
289
{
299
290
if ($ this ->forcedBody ) {
300
291
throw new RuntimeException (sprintf (
0 commit comments