Skip to content

Commit

Permalink
Merge pull request #73 from utopia-php/fix-get-env-type
Browse files Browse the repository at this point in the history
fix: return type for getEnv
  • Loading branch information
TorstenDittmann authored Oct 7, 2022
2 parents f97e691 + 3b1fa2f commit 9f35d36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ public static function error(): Hook
* Method for querying env varialbles. If $key is not found $default value will be returned.
*
* @param string $key
* @param mixed $default
* @return mixed
* @param string|null $default
* @return string|null
*/
public static function getEnv(string $key, string $default = null): string
public static function getEnv(string $key, string $default = null): ?string
{
return $_SERVER[$key] ?? $default;
}
Expand Down
17 changes: 9 additions & 8 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getParam(string $key, mixed $default = null): mixed
*/
public function getParams(): array
{
return match($this->getServer('REQUEST_METHOD', '')) {
return match ($this->getServer('REQUEST_METHOD', '')) {
self::METHOD_POST,
self::METHOD_PUT,
self::METHOD_PATCH,
Expand Down Expand Up @@ -116,10 +116,10 @@ public function getPayload(string $key, mixed $default = null): mixed
* Method for querying server parameters. If $key is not found $default value will be returned.
*
* @param string $key
* @param mixed $default
* @return string
* @param string|null $default
* @return string|null
*/
public function getServer(string $key, string $default = null): string
public function getServer(string $key, string $default = null): ?string
{
return $_SERVER[$key] ?? $default;
}
Expand All @@ -135,7 +135,8 @@ public function getServer(string $key, string $default = null): string
*/
public function getIP(): string
{
$ips = explode(',', $this->getHeader('HTTP_X_FORWARDED_FOR', $this->getServer('REMOTE_ADDR', '0.0.0.0')));
$ips = explode(',', $this->getHeader('HTTP_X_FORWARDED_FOR', $this->getServer('REMOTE_ADDR') ?? '0.0.0.0'));

return trim($ips[0] ?? '');
}

Expand All @@ -150,7 +151,7 @@ public function getIP(): string
*/
public function getProtocol(): string
{
return $this->getServer('HTTP_X_FORWARDED_PROTO', $this->getServer('REQUEST_SCHEME', 'https'));
return $this->getServer('HTTP_X_FORWARDED_PROTO', $this->getServer('REQUEST_SCHEME')) ?? 'https';
}

/**
Expand Down Expand Up @@ -186,7 +187,7 @@ public function getHostname(): string
*/
public function getMethod(): string
{
return $this->getServer('REQUEST_METHOD', 'UNKNOWN');
return $this->getServer('REQUEST_METHOD') ?? 'UNKNOWN';
}

/**
Expand All @@ -198,7 +199,7 @@ public function getMethod(): string
*/
public function getURI(): string
{
return $this->getServer('REQUEST_URI', '');
return $this->getServer('REQUEST_URI') ?? '';
}

/**
Expand Down

0 comments on commit 9f35d36

Please sign in to comment.