Skip to content

Commit

Permalink
used native PHP 8 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 16, 2021
1 parent a5ff7a7 commit 8f3c79c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/HttpDI/HttpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private function sendHeaders()
continue;
}
$value = self::buildPolicy($config->$key);
if (strpos($value, "'nonce'")) {
if (str_contains($value, "'nonce'")) {
$this->initialization->addBody('$cspNonce = base64_encode(random_bytes(16));');
$value = Nette\DI\ContainerBuilder::literal(
'str_replace(?, ? . $cspNonce, ?)',
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function isModified(string|int|\DateTimeInterface $lastModified = null, s
} elseif ($ifNoneMatch !== null) {
$etag = $this->response->getHeader('ETag');

if ($etag === null || strpos(' ' . strtr($ifNoneMatch, ",\t", ' '), ' ' . $etag) === false) {
if ($etag === null || !str_contains(' ' . strtr($ifNoneMatch, ",\t", ' '), ' ' . $etag)) {
return true;

} else {
Expand Down
6 changes: 3 additions & 3 deletions src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ private function useForwardedProxy(Url $url, &$remoteAddr, &$remoteHost): void

if (isset($proxyParams['for'])) {
$address = $proxyParams['for'][0];
$remoteAddr = strpos($address, '[') === false
? explode(':', $address)[0] // IPv4
: substr($address, 1, strpos($address, ']') - 1); // IPv6
$remoteAddr = str_contains($address, '[')
? substr($address, 1, strpos($address, ']') - 1) // IPv6
: explode(':', $address)[0]; // IPv4
}

if (isset($proxyParams['host']) && count($proxyParams['host']) === 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function __destruct()
{
if (
self::$fixIE
&& strpos($_SERVER['HTTP_USER_AGENT'] ?? '', 'MSIE ') !== false
&& str_contains($_SERVER['HTTP_USER_AGENT'] ?? '', 'MSIE ')
&& in_array($this->code, [400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505], true)
&& preg_match('#^text/html(?:;|$)#', (string) $this->getHeader('Content-Type'))
) {
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function getPort(): ?int
public function setPath(string $path): static
{
$this->path = $path;
if ($this->host && substr($this->path, 0, 1) !== '/') {
if ($this->host && !str_starts_with($this->path, '/')) {
$this->path = '/' . $this->path;
}
return $this;
Expand Down Expand Up @@ -363,7 +363,7 @@ final public function export(): array
*/
private static function idnHostToUnicode(string $host): string
{
if (strpos($host, '--') === false) { // host does not contain IDN
if (!str_contains($host, '--')) { // host does not contain IDN
return $host;
}
if (function_exists('idn_to_utf8') && defined('INTL_IDNA_VARIANT_UTS46')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/UrlImmutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ final public function export(): array

protected function build(): void
{
if ($this->host && substr($this->path, 0, 1) !== '/') {
if ($this->host && !str_starts_with($this->path, '/')) {
$this->path = '/' . $this->path;
}

Expand Down

0 comments on commit 8f3c79c

Please sign in to comment.