Skip to content

Commit 41ed502

Browse files
committed
Change to strict null comparison
1 parent 859dfd2 commit 41ed502

14 files changed

Lines changed: 55 additions & 52 deletions

Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function prepareRequest(RequestInterface $request): void
126126
$this->setOption(CURLOPT_RETURNTRANSFER, true);
127127

128128
// Default auth option if get user name
129-
if (!$this->hasOption(CURLOPT_HTTPAUTH) && !is_null($request->getUri()->getPart("user"))) {
129+
if (!$this->hasOption(CURLOPT_HTTPAUTH) && $request->getUri()->getPart("user") !== null) {
130130
$this->setOption(CURLOPT_HTTPAUTH, static::DEFAULT_AUTH);
131131
}
132132

Dir.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getRoot(string $path = ""): string
5757
*/
5858
public function getLogs(string $path = ""): string
5959
{
60-
if (!is_null($this->handler)) {
60+
if ($this->handler !== null) {
6161
return $this->handler->getLogs($path);
6262
}
6363
return $this->getRoot("storage/logs/" . $path);
@@ -72,7 +72,7 @@ public function getLogs(string $path = ""): string
7272
*/
7373
public function __call($method, $args): mixed
7474
{
75-
if (!is_null($this->handler) && method_exists($this->handler, $method)) {
75+
if ($this->handler !== null && method_exists($this->handler, $method)) {
7676
return call_user_func_array([$this->handler, $method], $args);
7777
} else {
7878
throw new \BadMethodCallException("The method ({$method}) does not exist in \"".__CLASS__."\" (DirInterface or DirHandlerInterface).", 1);

Env.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Env
1616

1717
public function __construct(?string $file = null)
1818
{
19-
if (!is_null($file) && is_file($file)) {
19+
if ($file !== null && is_file($file)) {
2020
$this->loadEnvFile($file);
2121
}
2222
}

Environment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function getUriParts(array $add = []): array
7575
*/
7676
public function getPath(): string
7777
{
78-
if (is_null($this->path)) {
78+
if ($this->path === null) {
7979
$basePath = '';
8080
$requestName = Format\Str::value($this->get("SCRIPT_NAME"))->getUrlPath()->get();
8181
$requestDir = dirname($requestName);

Headers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function normalizeKey(string $key, bool $preserveCase = false): string
106106
*/
107107
final public static function getGlobalHeaders($skip = false): array
108108
{
109-
//if(is_null(static::$getGlobalHeaders)) {
109+
//if(static::$getGlobalHeaders === null) {
110110
if (!$skip && function_exists("getallheaders")) {
111111
static::$getGlobalHeaders = getallheaders();
112112
} else {

Message.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class Message implements MessageInterface
2525
*/
2626
public function getProtocolVersion()
2727
{
28-
if (is_null($this->version)) {
28+
if ($this->version === null) {
2929
$prot = explode("/", ($this->env['SERVER_PROTOCOL'] ?? "HTTP/1.1"));
3030
$this->version = end($prot);
3131
}
@@ -72,7 +72,7 @@ public function getHeader($name): array
7272
*/
7373
public function hasHeader($name): bool
7474
{
75-
if (is_null($this->headers)) {
75+
if ($this->headers === null) {
7676
throw new RequestException("Missing The HTTP Headers instance", 1);
7777
}
7878
return $this->headers->hasHeader($name);

Request.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

Response.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ public function __construct(
8888
) {
8989
$this->body = $body;
9090
$this->statusCode = $status;
91-
$this->headers = is_null($headers) ? new Headers() : $headers;
92-
$this->body = $body;
93-
if (!is_null($version)) {
91+
$this->headers = $headers === null ? new Headers() : $headers;
92+
//$this->body = $body;
93+
if ($version !== null) {
9494
$this->version = $version;
9595
}
96-
if (!is_null($phrase)) {
96+
if ($phrase !== null) {
9797
$this->phrase = $phrase;
9898
}
9999
}
@@ -116,7 +116,7 @@ public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterf
116116
* Get current response status code
117117
* @return int
118118
*/
119-
public function getStatusCode()
119+
public function getStatusCode(): int
120120
{
121121
return $this->statusCode;
122122
}
@@ -125,9 +125,9 @@ public function getStatusCode()
125125
* Get current response status phrase
126126
* @return string
127127
*/
128-
public function getReasonPhrase()
128+
public function getReasonPhrase(): string
129129
{
130-
if (is_null($this->phrase)) {
130+
if ($this->phrase === null) {
131131
$this->phrase = ($this::PHRASE[$this->statusCode] ?? "");
132132
}
133133
return $this->phrase;
@@ -230,7 +230,7 @@ public function location(string $url, int $statusCode = 302): void
230230
*/
231231
public function createHeaders(): void
232232
{
233-
if (is_null($this->hasHeadersInit)) {
233+
if ($this->hasHeadersInit === null) {
234234
$this->hasHeadersInit = true;
235235
foreach ($this->getHeaders() as $key => $_unusedVal) {
236236
$value = $this->getHeaderLine($key);

ServerRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function withCookieParams(array $cookies): self
101101
*/
102102
public function getQueryParams(): array
103103
{
104-
if (is_null($this->queryParams)) {
104+
if ($this->queryParams === null) {
105105
parse_str($this->getUri()->getQuery(), $this->queryParams);
106106
}
107107
return $this->queryParams;
@@ -188,7 +188,7 @@ public function withUploadedFiles(array $uploadedFiles): self
188188
*/
189189
public function getParsedBody(): null|array|object
190190
{
191-
if (is_null($this->parsedBody) && $this->getMethod() === "POST") {
191+
if ($this->parsedBody === null && $this->getMethod() === "POST") {
192192
$header = $this->getHeader('Content-Type');
193193
$contents = (string)$this->getBody();
194194
switch (($header[0] ?? null)) {

Stream.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ class Stream implements StreamInterface
4040
*/
4141
public function __construct(mixed $stream = null, string $permission = "r+")
4242
{
43-
if (is_null($stream)) {
43+
if ($stream === null) {
4444
$stream = $this::DEFAULT_WRAPPER;
4545
}
4646

4747
if (is_resource($stream)) {
4848
$this->resource = $stream;
4949
$this->meta = $this->getMetadata();
5050
/*
51-
if (is_null($this->meta)) {
51+
if ($this->meta === null) {
5252
throw new RuntimeException("Could not access the stream metadata.", 1);
5353
}
5454
*/
@@ -147,7 +147,7 @@ public function stats(?string $key = null): mixed
147147
{
148148
$stats = fstat($this->resource);
149149
if (is_array($stats)) {
150-
return is_null($key) ? $stats : ($stats[$key] ?? false);
150+
return $key === null ? $stats : ($stats[$key] ?? false);
151151
}
152152
return false;
153153
}
@@ -241,7 +241,7 @@ public function rewind(): void
241241
*/
242242
public function write(string $string): int
243243
{
244-
if (is_null($this->size)) {
244+
if ($this->size === null) {
245245
$this->size = 0;
246246
}
247247
return fwrite($this->resource, $string);
@@ -284,7 +284,7 @@ public function getMetadata(?string $key = null): mixed
284284
$this->readable = (bool)preg_match(self::READABLE_MATCH, $this->meta['mode']);
285285
$this->writable = (bool)preg_match(self::WRITABLE_MATCH, $this->meta['mode']);
286286
$this->seekable = $this->meta['seekable'];
287-
return (!is_null($key) ? ($this->meta[$key] ?? null) : $this->meta);
287+
return ($key !== null ? ($this->meta[$key] ?? null) : $this->meta);
288288
}
289289

290290
/**

0 commit comments

Comments
 (0)