@@ -27,6 +27,9 @@ public function __construct(
2727 $ this ->uri = is_string ($ uri ) ? new Uri ($ uri ) : $ uri ;
2828 $ this ->headers = is_array ($ headers ) ? new Headers ($ headers ) : $ headers ;
2929 $ this ->body = $ this ->resolveRequestStream ($ body );
30+ if ($ this ->env === null ) {
31+ $ this ->env = new Environment ();
32+ }
3033 $ this ->setHostHeader ();
3134 }
3235
@@ -118,11 +121,11 @@ public function isSSL(): bool
118121 public function getPort (): int
119122 {
120123 $ serverPort = $ this ->env ->get ("SERVER_PORT " );
121- return (int )(($ serverPort ) ? $ serverPort : $ this ->uri ->getPort ());
124+ return (int )((( int ) $ serverPort > 0 ) ? $ serverPort : $ this ->uri ->getPort ());
122125 }
123126
124127 /**
125- * Set host header if missing or overwrite if custom is set.
128+ * Set the host header if missing or overwrite if custom is set.
126129 * @return void
127130 */
128131 final protected function setHostHeader (): void
@@ -146,7 +149,7 @@ private function resolveRequestStream(StreamInterface|array|string|null $body):
146149 $ body = http_build_query ($ body );
147150 }
148151 $ stream = new Stream (Stream::TEMP );
149- if (! is_null ( $ body) ) {
152+ if ($ body !== null ) {
150153 $ stream ->write ($ body );
151154 $ stream ->rewind ();
152155 }
@@ -160,7 +163,7 @@ private function resolveRequestStream(StreamInterface|array|string|null $body):
160163 */
161164 public function getCliKeyword (): ?string
162165 {
163- if (is_null ( $ this ->cliKeywords ) ) {
166+ if ($ this ->cliKeywords === null ) {
164167 $ new = [];
165168 $ arg = $ this ->getUri ()->getArgv ();
166169 foreach ($ arg as $ val ) {
@@ -185,7 +188,7 @@ public function getCliKeyword(): ?string
185188 */
186189 public function getCliArgs (): array
187190 {
188- if (is_null ( $ this ->cliArgs ) ) {
191+ if ($ this ->cliArgs === null ) {
189192 $ args = $ this ->getUri ()->getArgv ();
190193 $ this ->cliArgs = [];
191194 foreach ($ args as $ arg ) {
0 commit comments