2121 */
2222class Message implements MessageInterface
2323{
24- private $ version = '1.1 ' ;
25- private $ headers = [];
26- private $ body ;
27-
28- public function __construct (string $ version = '1.1 ' , array $ headers = [], StreamInterface $ body = null )
29- {
30- $ this ->version = $ version ;
31- $ this ->headers = $ headers ;
32- $ this ->body = $ body ?? new Stream ();
24+ public function __construct (
25+ private readonly string $ version = '1.1 ' ,
26+ private array $ headers = [],
27+ private readonly StreamInterface $ body = new Stream (),
28+ ) {
3329 }
3430
3531 public function getProtocolVersion (): string
3632 {
3733 return $ this ->version ;
3834 }
3935
40- /**
41- * {@inheritdoc}
42- *
43- * @return static
44- */
45- public function withProtocolVersion ($ version ): MessageInterface
36+ public function withProtocolVersion ($ version ): never
4637 {
4738 throw new \BadMethodCallException ('Not implemented. ' );
4839 }
@@ -67,34 +58,19 @@ public function getHeaderLine($name): string
6758 return $ this ->hasHeader ($ name ) ? implode (', ' , $ this ->headers [$ name ]) : '' ;
6859 }
6960
70- /**
71- * {@inheritdoc}
72- *
73- * @return static
74- */
75- public function withHeader ($ name , $ value ): MessageInterface
61+ public function withHeader ($ name , $ value ): static
7662 {
7763 $ this ->headers [$ name ] = (array ) $ value ;
7864
7965 return $ this ;
8066 }
8167
82- /**
83- * {@inheritdoc}
84- *
85- * @return static
86- */
87- public function withAddedHeader ($ name , $ value ): MessageInterface
68+ public function withAddedHeader ($ name , $ value ): never
8869 {
8970 throw new \BadMethodCallException ('Not implemented. ' );
9071 }
9172
92- /**
93- * {@inheritdoc}
94- *
95- * @return static
96- */
97- public function withoutHeader ($ name ): MessageInterface
73+ public function withoutHeader ($ name ): static
9874 {
9975 unset($ this ->headers [$ name ]);
10076
@@ -108,10 +84,8 @@ public function getBody(): StreamInterface
10884
10985 /**
11086 * {@inheritdoc}
111- *
112- * @return static
11387 */
114- public function withBody (StreamInterface $ body ): MessageInterface
88+ public function withBody (StreamInterface $ body ): never
11589 {
11690 throw new \BadMethodCallException ('Not implemented. ' );
11791 }
0 commit comments