Skip to content

Commit 1a8e037

Browse files
committed
- force native functions
- code style
1 parent 80ddeb3 commit 1a8e037

9 files changed

Lines changed: 28 additions & 26 deletions

AcceptHeaderNegotiator.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function matches(string $accepts): array
7070
*/
7171
private function parse(string $header): \Generator
7272
{
73-
foreach (explode(',', $header) as $header) {
73+
foreach (\explode(',', $header) as $header) {
7474
yield new class($header) extends AcceptHeader {};
7575
}
7676
}
@@ -92,22 +92,22 @@ public function __construct(string $header)
9292
{
9393
$this->header = $header;
9494

95-
$header = preg_replace('/[[:space:]]/', '', $header);
96-
$bits = explode(';', $header);
97-
$type = array_shift($bits);
98-
if (!empty($type) && !preg_match('~^(\*|[a-z0-9._]+)([/|_\-])?(\*|[a-z0-9.\-_+]+)?$~i', $type, $matches)) {
99-
throw new \InvalidArgumentException(sprintf('"%s" is not a valid Access header', $header),
95+
$header = \preg_replace('/[[:space:]]/', '', $header);
96+
$bits = \explode(';', $header);
97+
$type = \array_shift($bits);
98+
if (!empty($type) && !\preg_match('~^(\*|[a-z0-9._]+)([/|_\-])?(\*|[a-z0-9.\-_+]+)?$~i', $type, $matches)) {
99+
throw new \InvalidArgumentException(\sprintf('"%s" is not a valid Access header', $header),
100100
HttpStatus::NOT_ACCEPTABLE);
101101
}
102102
$this->separator = $matches[2] ?? '/';
103-
[$type, $subtype] = explode($this->separator, $type, 2) + [1 => '*'];
103+
[$type, $subtype] = \explode($this->separator, $type, 2) + [1 => '*'];
104104
if ('*' === $type && '*' !== $subtype) {
105105
// @see https://tools.ietf.org/html/rfc7231#section-5.3.2
106-
throw new \InvalidArgumentException(sprintf('"%s" is not a valid Access header', $header),
106+
throw new \InvalidArgumentException(\sprintf('"%s" is not a valid Access header', $header),
107107
HttpStatus::NOT_ACCEPTABLE);
108108
}
109109
// @see https://tools.ietf.org/html/rfc7540#section-8.1.2
110-
$this->type = trim(strtolower($type));
110+
$this->type = \trim(\strtolower($type));
111111
/*
112112
* Uses a simple heuristic to check if subtype is part of
113113
* some convoluted media type like "vnd.api-v1+json".
@@ -117,9 +117,9 @@ public function __construct(string $header)
117117
* type like "vnd.whatever". The web world is a big mess
118118
* but this module can handle the Dunning-Kruger effect.
119119
*/
120-
$this->subtype = trim(explode('+', $subtype)[1] ?? $subtype);
120+
$this->subtype = \trim(\explode('+', $subtype)[1] ?? $subtype);
121121
$this->catchAll = ('*' === $this->type) && ('*' === $this->subtype);
122-
parse_str(join('&', $bits), $this->params);
122+
\parse_str(\join('&', $bits), $this->params);
123123
$this->quality = (float)($this->params['q'] ?? 1);
124124
unset($this->params['q']);
125125
}

Client/EncodingTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait EncodingTrait
2121

2222
public function withEncoding(int $type): static
2323
{
24-
if (in_array($type, [0, PHP_QUERY_RFC1738, PHP_QUERY_RFC3986], true)) {
24+
if (\in_array($type, [0, PHP_QUERY_RFC1738, PHP_QUERY_RFC3986], true)) {
2525
$this->encoding = $type;
2626
return $this;
2727
}

Client/Psr18Exception.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ class Psr18Exception extends \Exception implements RequestExceptionInterface, Ne
99
{
1010
private RequestInterface $request;
1111

12-
public function __construct(string $message, int $code, RequestInterface $request, \Throwable $previous = null)
13-
{
12+
public function __construct(
13+
string $message,
14+
int $code,
15+
RequestInterface $request,
16+
\Throwable $previous = null
17+
) {
1418
parent::__construct($message, $code, $previous);
1519
$this->request = $request;
1620
}

ClientRequest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353

5454
public function getMethod(): string
5555
{
56-
return strtoupper($this->method);
56+
return \strtoupper($this->method);
5757
}
5858

5959
public function withMethod($method): ClientRequest
@@ -105,7 +105,7 @@ public function withRequestTarget($requestTarget): static
105105

106106
public function getPath(): string
107107
{
108-
return str_replace($_SERVER['SCRIPT_NAME'], '', $this->uri->getPath()) ?: '/';
108+
return \str_replace($_SERVER['SCRIPT_NAME'], '', $this->uri->getPath()) ?: '/';
109109
}
110110

111111
public function getBaseUri(): string
@@ -187,9 +187,8 @@ protected function getPhpError(int $status, ?string $message = null): Response
187187
'title' => StatusCode::CODE[$status],
188188
'detail' => $message ?? \error_get_last()['message'],
189189
'instance' => (string)$this->getUri(),
190-
'type' => 'https://httpstatuses.com/' . (string)$status,
190+
'type' => 'https://httpstatuses.com/' . $status,
191191
'status' => $status,
192192
]), $status, ['Content-type' => 'application/problem+json']);
193193
}
194-
195194
}

HeaderTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use Koded\Http\Interfaces\HttpStatus;
1616

17-
1817
trait HeaderTrait
1918
{
2019
/**
@@ -210,7 +209,7 @@ protected function normalizeHeaderValue(string $name, string|array $value): arra
210209
$value = (array)$value;
211210
}
212211
try {
213-
if (empty($value = \array_map(function($v) {
212+
if (empty($value = \array_map(function($v): string {
214213
return \trim(\preg_replace('/\s+/', ' ', $v));
215214
}, $value))) {
216215
throw new \InvalidArgumentException(

MessageTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use Psr\Http\Message\StreamInterface;
1616

17-
1817
trait MessageTrait
1918
{
2019
protected string $protocolVersion = '1.1';

ServerRequest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Koded\Http\Interfaces\Request;
1616
use Psr\Http\Message\ServerRequestInterface;
1717

18-
1918
class ServerRequest extends ClientRequest implements Request
2019
{
2120
use CookieTrait, FilesTrait, ValidatableTrait;
@@ -89,7 +88,7 @@ public function withParsedBody($data): static
8988
return $instance;
9089
}
9190
throw new \InvalidArgumentException(
92-
\sprintf('Unsupported data provided (%s), Expects NULL, array or iterable', gettype($data))
91+
\sprintf('Unsupported data provided (%s), Expects NULL, array or iterable', \gettype($data))
9392
);
9493
}
9594

ServerResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ServerResponse implements Response, \JsonSerializable
3535
* @param int $statusCode [optional]
3636
* @param array $headers [optional]
3737
*/
38-
public function __construct($content = '', int $statusCode = HttpStatus::OK, array $headers = [])
38+
public function __construct(mixed $content = '', int $statusCode = HttpStatus::OK, array $headers = [])
3939
{
4040
$this->setStatus($this, $statusCode);
4141
$this->setHeaders($headers);

functions.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ function create_stream(mixed $resource, string $mode = 'r+b'): StreamInterface
5757
*
5858
* @return int The total count of bytes copied
5959
*/
60-
function stream_copy(StreamInterface $source, StreamInterface $destination, int $length = 8192): int
60+
function stream_copy(
61+
StreamInterface $source,
62+
StreamInterface $destination,
63+
int $length = 8192): int
6164
{
6265
$bytes = 0;
6366
while (false === $source->eof()) {
@@ -110,7 +113,6 @@ function normalize_files_array(array $files): array
110113
}
111114
return $file;
112115
};
113-
114116
return $sane($files);
115117
}
116118

0 commit comments

Comments
 (0)