Skip to content

Commit

Permalink
run rector to upgrade old PHP code
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Lockett <[email protected]>
  • Loading branch information
Gary Lockett committed Jun 2, 2023
1 parent 0de82ed commit 8e85139
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 41 deletions.
10 changes: 1 addition & 9 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.10.0@a5effd2d2dddd1a7ea7a0f6a051ce63ff979e356">
<files psalm-version="5.12.0@f90118cdeacd0088e7215e64c0c99ceca819e176">
<file src="src/CallbackStream.php">
<ImplementedReturnTypeMismatch>
<code>null|callable</code>
Expand Down Expand Up @@ -146,14 +146,6 @@
<code>json_encode</code>
</UnusedFunctionCall>
</file>
<file src="src/Response/RedirectResponse.php">
<DocblockTypeContradiction>
<code>gettype($uri)</code>
</DocblockTypeContradiction>
<RedundantConditionGivenDocblockType>
<code>is_object($uri)</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Response/Serializer.php">
<MixedArgument>
<code>$body</code>
Expand Down
5 changes: 2 additions & 3 deletions src/Exception/InvalidForwardedHeaderNameException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

use Laminas\Diactoros\ServerRequestFilter\FilterUsingXForwardedHeaders;

use function gettype;
use function is_object;
use function get_debug_type;
use function is_string;
use function sprintf;

Expand All @@ -16,7 +15,7 @@ class InvalidForwardedHeaderNameException extends RuntimeException implements Ex
public static function forHeader(mixed $name): self
{
if (! is_string($name)) {
$name = sprintf('(value of type %s)', is_object($name) ? $name::class : gettype($name));
$name = sprintf('(value of type %s)', get_debug_type($name));
}

return new self(sprintf(
Expand Down
5 changes: 2 additions & 3 deletions src/Exception/InvalidProxyAddressException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

namespace Laminas\Diactoros\Exception;

use function gettype;
use function is_object;
use function get_debug_type;
use function sprintf;

class InvalidProxyAddressException extends RuntimeException implements ExceptionInterface
{
public static function forInvalidProxyArgument(mixed $proxy): self
{
$type = is_object($proxy) ? $proxy::class : gettype($proxy);
$type = get_debug_type($proxy);
return new self(sprintf(
'Invalid proxy of type "%s" provided;'
. ' must be a valid IPv4 or IPv6 address, optionally with a subnet mask provided'
Expand Down
7 changes: 3 additions & 4 deletions src/HeaderSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace Laminas\Diactoros;

use function gettype;
use function get_debug_type;
use function in_array;
use function is_numeric;
use function is_object;
use function is_string;
use function ord;
use function preg_match;
Expand Down Expand Up @@ -128,7 +127,7 @@ public static function assertValid(mixed $value): void
if (! is_string($value) && ! is_numeric($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid header value type; must be a string or numeric; received %s',
is_object($value) ? $value::class : gettype($value)
get_debug_type($value)
));
}
if (! self::isValid($value)) {
Expand All @@ -151,7 +150,7 @@ public static function assertValidName(mixed $name): void
if (! is_string($name)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid header name type; expected string; received %s',
is_object($name) ? $name::class : gettype($name)
get_debug_type($name)
));
}
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/D', $name)) {
Expand Down
5 changes: 2 additions & 3 deletions src/Response/HtmlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use Laminas\Diactoros\Stream;
use Psr\Http\Message\StreamInterface;

use function gettype;
use function is_object;
use function get_debug_type;
use function is_string;
use function sprintf;

Expand Down Expand Up @@ -60,7 +59,7 @@ private function createBody($html): StreamInterface
if (! is_string($html)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid content (%s) provided to %s',
is_object($html) ? $html::class : gettype($html),
get_debug_type($html),
self::class
));
}
Expand Down
5 changes: 2 additions & 3 deletions src/Response/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use Laminas\Diactoros\Response;
use Psr\Http\Message\UriInterface;

use function gettype;
use function is_object;
use function get_debug_type;
use function is_string;
use function sprintf;

Expand All @@ -36,7 +35,7 @@ public function __construct($uri, int $status = 302, array $headers = [])
throw new Exception\InvalidArgumentException(sprintf(
'Uri provided to %s MUST be a string or Psr\Http\Message\UriInterface instance; received "%s"',
self::class,
is_object($uri) ? $uri::class : gettype($uri)
get_debug_type($uri)
));
}

Expand Down
5 changes: 2 additions & 3 deletions src/Response/TextResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use Laminas\Diactoros\Stream;
use Psr\Http\Message\StreamInterface;

use function gettype;
use function is_object;
use function get_debug_type;
use function is_string;
use function sprintf;

Expand Down Expand Up @@ -60,7 +59,7 @@ private function createBody($text): StreamInterface
if (! is_string($text)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid content (%s) provided to %s',
is_object($text) ? $text::class : gettype($text),
get_debug_type($text),
self::class
));
}
Expand Down
5 changes: 2 additions & 3 deletions src/Response/XmlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use Laminas\Diactoros\Stream;
use Psr\Http\Message\StreamInterface;

use function gettype;
use function is_object;
use function get_debug_type;
use function is_string;
use function sprintf;

Expand Down Expand Up @@ -62,7 +61,7 @@ private function createBody($xml): StreamInterface
if (! is_string($xml)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid content (%s) provided to %s',
is_object($xml) ? $xml::class : gettype($xml),
get_debug_type($xml),
self::class
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ServerRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function fromGlobals(
?array $files = null,
?FilterServerRequestInterface $requestFilter = null
): ServerRequestInterface {
$requestFilter = $requestFilter ?? FilterUsingXForwardedHeaders::trustReservedSubnets();
$requestFilter ??= FilterUsingXForwardedHeaders::trustReservedSubnets();

$server = normalizeServer(
$server ?? $_SERVER,
Expand Down
3 changes: 1 addition & 2 deletions src/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class UploadedFile implements UploadedFileInterface

private bool $moved = false;

/** @var null|StreamInterface */
private $stream;
private ?StreamInterface $stream = null;

/**
* @param string|resource|StreamInterface $streamOrFile
Expand Down
5 changes: 3 additions & 2 deletions test/Response/JsonResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use const JSON_HEX_QUOT;
use const JSON_HEX_TAG;
use const JSON_PRETTY_PRINT;
use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;

class JsonResponseTest extends TestCase
Expand Down Expand Up @@ -139,7 +140,7 @@ public function testConstructorRewindsBodyStream(): void
$json = ['test' => 'data'];
$response = new JsonResponse($json);

$actual = json_decode($response->getBody()->getContents(), true);
$actual = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
$this->assertSame($json, $actual);
}

Expand All @@ -158,7 +159,7 @@ public function testWithPayload(): void
$this->assertNotSame($response, $newResponse);

$this->assertSame($json, $newResponse->getPayload());
$decodedBody = json_decode($newResponse->getBody()->getContents(), true);
$decodedBody = json_decode($newResponse->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
$this->assertSame($json, $decodedBody);
}

Expand Down
6 changes: 3 additions & 3 deletions test/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use function fwrite;
use function imagecreate;
use function is_resource;
use function is_string;
use function shmop_open;
use function stream_get_meta_data;
use function sys_get_temp_dir;
Expand All @@ -38,8 +39,7 @@

final class StreamTest extends TestCase
{
/** @var string|null|false */
private $tmpnam;
private null|string|bool $tmpnam;

private Stream $stream;

Expand All @@ -51,7 +51,7 @@ protected function setUp(): void

protected function tearDown(): void
{
if ($this->tmpnam && file_exists($this->tmpnam)) {
if (is_string($this->tmpnam) && $this->tmpnam !== '' && file_exists($this->tmpnam)) {
unlink($this->tmpnam);
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/UploadedFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@

final class UploadedFileTest extends TestCase
{
/** @var false|null|string */
private $orgFile;
private null|string|bool $orgFile;

/** @var mixed */
private $tmpFile;
Expand Down

0 comments on commit 8e85139

Please sign in to comment.