Skip to content

Commit

Permalink
Upgrade coding standard
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Aug 23, 2024
1 parent fbf1bf0 commit 1b94f4b
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"require-dev": {
"ext-xdebug": "*",
"aplus/coding-standard": "^2.0",
"aplus/coding-standard": "^2.8",
"ergebnis/composer-normalize": "^2.25",
"jetbrains/phpstorm-attributes": "^1.0",
"phpmd/phpmd": "^2.13",
Expand Down
2 changes: 1 addition & 1 deletion src/AntiCSRF.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getToken() : ?string
*
* @return static
*/
public function setToken(string $token = null) : static
public function setToken(?string $token = null) : static
{
$_SESSION['$']['csrf_token'] = $token ?? \base64_encode(\random_bytes(8));
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/CSP.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function setDirectives(array $directives) : static
*
* @return array<string>|null
*/
public function getDirective(string $name) : array | null
public function getDirective(string $name) : ?array
{
return $this->directives[\strtolower($name)] ?? null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getStartLine() : string
}

#[Pure]
public function hasHeader(string $name, string $value = null) : bool
public function hasHeader(string $name, ?string $value = null) : bool
{
return $value === null
? $this->getHeader($name) !== null
Expand Down Expand Up @@ -460,11 +460,11 @@ protected function getUrl() : URL
/**
* Set the Message URL.
*
* @param string|URL $url
* @param URL|string $url
*
* @return static
*/
protected function setUrl(string | URL $url) : static
protected function setUrl(URL | string $url) : static
{
if (!$url instanceof URL) {
$url = new URL($url);
Expand Down
2 changes: 1 addition & 1 deletion src/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getStartLine() : string;

public function getHeader(string $name) : ?string;

public function hasHeader(string $name, string $value = null) : bool;
public function hasHeader(string $name, ?string $value = null) : bool;

/**
* @return array<string,string>
Expand Down
58 changes: 29 additions & 29 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class Request extends Message implements RequestInterface
{
/**
* @var array<string,array<mixed>|UploadedFile>
* @var array<string,UploadedFile|array<mixed>>
*/
protected array $files = [];
/**
Expand All @@ -51,7 +51,7 @@ class Request extends Message implements RequestInterface
/**
* Request X-Request-ID header.
*/
protected string | false $id;
protected false | string $id;
/**
* @var array<string,array<mixed>|null>
*/
Expand All @@ -61,8 +61,8 @@ class Request extends Message implements RequestInterface
'ENCODING' => null,
'LANGUAGE' => null,
];
protected false | URL $referrer;
protected false | UserAgent $userAgent;
protected URL | false $referrer;
protected UserAgent | false $userAgent;
protected bool $isAjax;
/**
* Tell if is a HTTPS connection.
Expand Down Expand Up @@ -299,8 +299,8 @@ protected function prepareFiles() : void
*/
protected function filterInput(
int $type,
string $name = null,
int $filter = null,
?string $name = null,
?int $filter = null,
array | int $options = 0
) : mixed {
$input = match ($type) {
Expand Down Expand Up @@ -527,8 +527,8 @@ protected function parseDigestAuth(string $attributes) : array
* @return array<mixed>|mixed|string|null
*/
public function getParsedBody(
string $name = null,
int $filter = null,
?string $name = null,
?int $filter = null,
array | int $filterOptions = 0
) : mixed {
if ($this->getMethod() === Method::POST) {
Expand Down Expand Up @@ -577,9 +577,9 @@ public function getParsedBody(
*/
public function getJson(
?bool $associative = null,
int $flags = null,
?int $flags = null,
int $depth = 512
) : array | stdClass | false {
) : array | false | stdClass {
if ($flags === null) {
$flags = $this->getJsonFlags();
}
Expand Down Expand Up @@ -744,15 +744,15 @@ public function getContentType() : ?string
* @return mixed
*/
public function getEnv(
string $name = null,
int $filter = null,
?string $name = null,
?int $filter = null,
array | int $filterOptions = 0
) : mixed {
return $this->filterInput(\INPUT_ENV, $name, $filter, $filterOptions);
}

/**
* @return array<string,array<mixed>|UploadedFile>
* @return array<string,UploadedFile|array<mixed>>
*/
public function getFiles() : array
{
Expand Down Expand Up @@ -785,8 +785,8 @@ public function getFile(string $name) : ?UploadedFile
* @return mixed
*/
public function getGet(
string $name = null,
int $filter = null,
?string $name = null,
?int $filter = null,
array | int $filterOptions = 0
) : mixed {
return $this->filterInput(\INPUT_GET, $name, $filter, $filterOptions);
Expand All @@ -806,7 +806,7 @@ public function getHost() : string
*
* @return string|null
*/
public function getId() : string | null
public function getId() : ?string
{
if (isset($this->id)) {
return $this->id === false ? null : $this->id;
Expand Down Expand Up @@ -857,7 +857,7 @@ public function isMethod(string $method) : bool
* @return mixed an array containing all data, the key value or null
* if the key was not found
*/
public function getRedirectData(string $key = null) : mixed
public function getRedirectData(?string $key = null) : mixed
{
static $data;
if ($data === null && \session_status() !== \PHP_SESSION_ACTIVE) {
Expand Down Expand Up @@ -895,8 +895,8 @@ public function getPort() : int
* @return mixed
*/
public function getPost(
string $name = null,
int $filter = null,
?string $name = null,
?int $filter = null,
array | int $filterOptions = 0
) : mixed {
return $this->filterInput(\INPUT_POST, $name, $filter, $filterOptions);
Expand All @@ -912,8 +912,8 @@ public function getPost(
* @return mixed
*/
public function getPatch(
string $name = null,
int $filter = null,
?string $name = null,
?int $filter = null,
array | int $filterOptions = 0
) : mixed {
if ($this->getMethod() === Method::PATCH) {
Expand All @@ -932,8 +932,8 @@ public function getPatch(
* @return mixed
*/
public function getPut(
string $name = null,
int $filter = null,
?string $name = null,
?int $filter = null,
array | int $filterOptions = 0
) : mixed {
if ($this->getMethod() === Method::PUT) {
Expand Down Expand Up @@ -977,8 +977,8 @@ public function getReferer() : ?URL
* @return mixed
*/
public function getServer(
string $name = null,
int $filter = null,
?string $name = null,
?int $filter = null,
array | int $filterOptions = 0
) : mixed {
return $this->filterInput(\INPUT_SERVER, $name, $filter, $filterOptions);
Expand Down Expand Up @@ -1013,11 +1013,11 @@ public function getUserAgent() : ?UserAgent
}

/**
* @param string|UserAgent $userAgent
* @param UserAgent|string $userAgent
*
* @return static
*/
protected function setUserAgent(string | UserAgent $userAgent) : static
protected function setUserAgent(UserAgent | string $userAgent) : static
{
if (!$userAgent instanceof UserAgent) {
$userAgent = new UserAgent($userAgent);
Expand Down Expand Up @@ -1118,7 +1118,7 @@ public function isPost() : bool
/**
* @see https://www.sitepoint.com/community/t/-files-array-structure/2728/5
*
* @return array<string,array<mixed>|UploadedFile>
* @return array<string,UploadedFile|array<mixed>>
*/
protected function getInputFiles() : array
{
Expand All @@ -1128,7 +1128,7 @@ protected function getInputFiles() : array
$makeObjects = static function (
array $array,
callable $makeObjects
) : array | UploadedFile {
) : UploadedFile | array {
$return = [];
foreach ($array as $k => $v) {
if (\is_array($v)) {
Expand Down
12 changes: 6 additions & 6 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function setCspReportOnly(CSP $csp) : static
*
* @return CSP|null
*/
public function getCsp() : CSP | null
public function getCsp() : ?CSP
{
return $this->csp ?? null;
}
Expand All @@ -242,7 +242,7 @@ public function getCsp() : CSP | null
*
* @return CSP|null
*/
public function getCspReportOnly() : CSP | null
public function getCspReportOnly() : ?CSP
{
return $this->cspReportOnly ?? null;
}
Expand Down Expand Up @@ -313,7 +313,7 @@ public function getStatus() : string
*
* @return static
*/
public function setStatus(int $code, string $reason = null) : static
public function setStatus(int $code, ?string $reason = null) : static
{
$this->setStatusCode($code);
$reason ?: $reason = Status::getReason($code);
Expand Down Expand Up @@ -412,7 +412,7 @@ public function isSent() : bool
*
* @return static
*/
public function redirect(string $location, array $data = [], int $code = null) : static
public function redirect(string $location, array $data = [], ?int $code = null) : static
{
if ($code === null) {
$code = $this->request->getMethod() === Method::GET
Expand Down Expand Up @@ -628,7 +628,7 @@ protected function negotiateEtag() : void
*
* @return static
*/
public function setJson(mixed $data, int $flags = null, int $depth = 512) : static
public function setJson(mixed $data, ?int $flags = null, int $depth = 512) : static
{
if ($flags === null) {
$flags = $this->getJsonFlags();
Expand Down Expand Up @@ -700,7 +700,7 @@ public function getCacheSeconds() : int
*
* @return static
*/
public function setAutoEtag(bool $active = true, string $hashAlgo = null) : static
public function setAutoEtag(bool $active = true, ?string $hashAlgo = null) : static
{
$this->autoEtag = $active;
if ($hashAlgo !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ class Status
*
* @return string
*/
public static function getReason(int $code, string $default = null) : string
public static function getReason(int $code, ?string $default = null) : string
{
$code = static::validate($code);
if (isset(static::$status[$code])) {
Expand Down
6 changes: 3 additions & 3 deletions src/UserAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public function getRobot() : ?string
* @return bool
*/
#[Pure]
public function isBrowser(string $key = null) : bool
public function isBrowser(?string $key = null) : bool
{
if ($key === null || $this->isBrowser === false) {
return $this->isBrowser;
Expand All @@ -414,7 +414,7 @@ public function isBrowser(string $key = null) : bool
* @return bool
*/
#[Pure]
public function isMobile(string $key = null) : bool
public function isMobile(?string $key = null) : bool
{
if ($key === null || $this->isMobile === false) {
return $this->isMobile;
Expand All @@ -432,7 +432,7 @@ public function isMobile(string $key = null) : bool
* @return bool
*/
#[Pure]
public function isRobot(string $key = null) : bool
public function isRobot(?string $key = null) : bool
{
if ($key === null || $this->isRobot === false) {
return $this->isRobot;
Expand Down
4 changes: 2 additions & 2 deletions tests/RequestMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ protected function prepareInput() : void

public function filterInput(
int $type,
string $name = null,
int $filter = null,
?string $name = null,
?int $filter = null,
array | int $options = []
) : mixed {
return parent::filterInput($type, $name, $filter, $options);
Expand Down

0 comments on commit 1b94f4b

Please sign in to comment.