From b978fd927a56deb1bb4a9a8ea4e560e321ad0723 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 23 Dec 2025 14:56:48 +0100 Subject: [PATCH 1/3] Bump phpunit/phpunit from 10.0 to 12.5 Because of that, we also bumped the support from PHP 8.1 to 8.3. --- .github/workflows/continuous-integration.yml | 6 ++---- README.md | 4 ++-- composer.json | 4 ++-- tests/unit/Stringifiers/CallableStringifierTest.php | 2 -- tests/unit/Stringifiers/DateTimeStringifierTest.php | 2 -- tests/unit/Stringifiers/IteratorObjectStringifierTest.php | 2 -- .../Stringifiers/JsonSerializableObjectStringifierTest.php | 2 -- .../Stringifiers/ObjectWithDebugInfoStringifierTest.php | 2 -- tests/unit/Stringifiers/StringableObjectStringifierTest.php | 2 -- tests/unit/Stringifiers/ThrowableObjectStringifierTest.php | 2 -- 10 files changed, 6 insertions(+), 22 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9e3bbfd..8926eda 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -13,8 +13,6 @@ jobs: strategy: matrix: php-version: - - "8.1" - - "8.2" - "8.3" - "8.4" - "8.5" @@ -50,7 +48,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 coverage: pcov - name: Install Dependencies @@ -74,7 +72,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 coverage: none - name: Install dependencies diff --git a/README.md b/README.md index 0fffff0..f455d23 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ using [Composer](http://getcomposer.org). composer require respect/stringifier ``` -This library requires PHP >= 8.1. +This library requires PHP >= 8.3. ## Usage @@ -190,4 +190,4 @@ echo $stringify->value(new class { } }); // Hello, world! -``` \ No newline at end of file +``` diff --git a/composer.json b/composer.json index 5d06640..3d3bf55 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^8.1" + "php": "^8.3" }, "require-dev": { "malukenho/docheader": "^0.1.7", @@ -19,7 +19,7 @@ "phpstan/phpstan-deprecation-rules": "^1.1", "phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-strict-rules": "^1.5", - "phpunit/phpunit": "^10.0", + "phpunit/phpunit": "^12.5", "respect/coding-standard": "^4.0", "squizlabs/php_codesniffer": "^3.7" }, diff --git a/tests/unit/Stringifiers/CallableStringifierTest.php b/tests/unit/Stringifiers/CallableStringifierTest.php index 23e063f..c09d411 100644 --- a/tests/unit/Stringifiers/CallableStringifierTest.php +++ b/tests/unit/Stringifiers/CallableStringifierTest.php @@ -17,7 +17,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Respect\Stringifier\Helpers\ObjectHelper; use Respect\Stringifier\Stringifiers\CallableStringifier; use Respect\Stringifier\Test\Double\FakeQuoter; use Respect\Stringifier\Test\Double\FakeStringifier; @@ -28,7 +27,6 @@ use const PHP_MAJOR_VERSION; use const PHP_MINOR_VERSION; -#[CoversClass(ObjectHelper::class)] #[CoversClass(CallableStringifier::class)] final class CallableStringifierTest extends TestCase { diff --git a/tests/unit/Stringifiers/DateTimeStringifierTest.php b/tests/unit/Stringifiers/DateTimeStringifierTest.php index 2ad39d0..955b7b5 100644 --- a/tests/unit/Stringifiers/DateTimeStringifierTest.php +++ b/tests/unit/Stringifiers/DateTimeStringifierTest.php @@ -17,11 +17,9 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Respect\Stringifier\Helpers\ObjectHelper; use Respect\Stringifier\Stringifiers\DateTimeStringifier; use Respect\Stringifier\Test\Double\FakeQuoter; -#[CoversClass(ObjectHelper::class)] #[CoversClass(DateTimeStringifier::class)] final class DateTimeStringifierTest extends TestCase { diff --git a/tests/unit/Stringifiers/IteratorObjectStringifierTest.php b/tests/unit/Stringifiers/IteratorObjectStringifierTest.php index e54fa1f..13fdb85 100644 --- a/tests/unit/Stringifiers/IteratorObjectStringifierTest.php +++ b/tests/unit/Stringifiers/IteratorObjectStringifierTest.php @@ -15,14 +15,12 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Respect\Stringifier\Helpers\ObjectHelper; use Respect\Stringifier\Stringifiers\IteratorObjectStringifier; use Respect\Stringifier\Test\Double\FakeQuoter; use Respect\Stringifier\Test\Double\FakeStringifier; use function sprintf; -#[CoversClass(ObjectHelper::class)] #[CoversClass(IteratorObjectStringifier::class)] final class IteratorObjectStringifierTest extends TestCase { diff --git a/tests/unit/Stringifiers/JsonSerializableObjectStringifierTest.php b/tests/unit/Stringifiers/JsonSerializableObjectStringifierTest.php index 4b8751a..9d1ee8b 100644 --- a/tests/unit/Stringifiers/JsonSerializableObjectStringifierTest.php +++ b/tests/unit/Stringifiers/JsonSerializableObjectStringifierTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Respect\Stringifier\Helpers\ObjectHelper; use Respect\Stringifier\Stringifiers\JsonSerializableObjectStringifier; use Respect\Stringifier\Test\Double\FakeQuoter; use Respect\Stringifier\Test\Double\FakeStringifier; @@ -22,7 +21,6 @@ use function sprintf; -#[CoversClass(ObjectHelper::class)] #[CoversClass(JsonSerializableObjectStringifier::class)] final class JsonSerializableObjectStringifierTest extends TestCase { diff --git a/tests/unit/Stringifiers/ObjectWithDebugInfoStringifierTest.php b/tests/unit/Stringifiers/ObjectWithDebugInfoStringifierTest.php index 3189c2f..3204537 100644 --- a/tests/unit/Stringifiers/ObjectWithDebugInfoStringifierTest.php +++ b/tests/unit/Stringifiers/ObjectWithDebugInfoStringifierTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Respect\Stringifier\Helpers\ObjectHelper; use Respect\Stringifier\Stringifiers\ObjectWithDebugInfoStringifier; use Respect\Stringifier\Test\Double\FakeQuoter; use Respect\Stringifier\Test\Double\FakeStringifier; @@ -22,7 +21,6 @@ use function sprintf; -#[CoversClass(ObjectHelper::class)] #[CoversClass(ObjectWithDebugInfoStringifier::class)] final class ObjectWithDebugInfoStringifierTest extends TestCase { diff --git a/tests/unit/Stringifiers/StringableObjectStringifierTest.php b/tests/unit/Stringifiers/StringableObjectStringifierTest.php index d300509..039c5a4 100644 --- a/tests/unit/Stringifiers/StringableObjectStringifierTest.php +++ b/tests/unit/Stringifiers/StringableObjectStringifierTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Respect\Stringifier\Helpers\ObjectHelper; use Respect\Stringifier\Stringifiers\StringableObjectStringifier; use Respect\Stringifier\Test\Double\FakeQuoter; use Respect\Stringifier\Test\Double\FakeStringifier; @@ -22,7 +21,6 @@ use function sprintf; -#[CoversClass(ObjectHelper::class)] #[CoversClass(StringableObjectStringifier::class)] final class StringableObjectStringifierTest extends TestCase { diff --git a/tests/unit/Stringifiers/ThrowableObjectStringifierTest.php b/tests/unit/Stringifiers/ThrowableObjectStringifierTest.php index 32ac9b9..896d525 100644 --- a/tests/unit/Stringifiers/ThrowableObjectStringifierTest.php +++ b/tests/unit/Stringifiers/ThrowableObjectStringifierTest.php @@ -19,7 +19,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Respect\Stringifier\Helpers\ObjectHelper; use Respect\Stringifier\Stringifiers\ThrowableObjectStringifier; use Respect\Stringifier\Test\Double\FakeQuoter; use Respect\Stringifier\Test\Double\FakeStringifier; @@ -30,7 +29,6 @@ use function sprintf; -#[CoversClass(ObjectHelper::class)] #[CoversClass(ThrowableObjectStringifier::class)] final class ThrowableObjectStringifierTest extends TestCase { From 784080ad0019cf76f0cd68a618aa6fd326c82286 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 23 Dec 2025 15:04:32 +0100 Subject: [PATCH 2/3] Bump phpstan/phpstan from 1.x to 2.x I also upgrade other PHPStan extensions we're using, and fixed a few issues. --- composer.json | 8 ++++---- src/Stringifiers/CallableStringifier.php | 6 +++--- tests/fixtures/WithMethods.php | 2 +- tests/src/Double/FakeStringifier.php | 2 +- tests/unit/Stringifiers/CallableStringifierTest.php | 9 +-------- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 3d3bf55..e12c006 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,10 @@ }, "require-dev": { "malukenho/docheader": "^0.1.7", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-deprecation-rules": "^1.1", - "phpstan/phpstan-phpunit": "^1.3", - "phpstan/phpstan-strict-rules": "^1.5", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^12.5", "respect/coding-standard": "^4.0", "squizlabs/php_codesniffer": "^3.7" diff --git a/src/Stringifiers/CallableStringifier.php b/src/Stringifiers/CallableStringifier.php index acf6d10..ae35f67 100644 --- a/src/Stringifiers/CallableStringifier.php +++ b/src/Stringifiers/CallableStringifier.php @@ -61,11 +61,11 @@ public function stringify(mixed $raw, int $depth): ?string return $this->buildMethod(new ReflectionMethod($raw, '__invoke'), $raw, $depth); } - if (is_array($raw) && is_object($raw[0])) { + if (is_array($raw) && is_object($raw[0]) && is_string($raw[1])) { return $this->buildMethod(new ReflectionMethod($raw[0], $raw[1]), $raw[0], $depth); } - if (is_array($raw) && is_string($raw[0])) { + if (is_array($raw) && is_string($raw[0]) && is_string($raw[1])) { return $this->buildStaticMethod(new ReflectionMethod($raw[0], $raw[1]), $depth); } @@ -81,7 +81,7 @@ public function stringify(mixed $raw, int $depth): ?string return $this->buildFunction(new ReflectionFunction($raw), $depth); } - public function buildFunction(ReflectionFunction $raw, int $depth): ?string + public function buildFunction(ReflectionFunction $raw, int $depth): string { return $this->quoter->quote($this->buildSignature($raw, $depth), $depth); } diff --git a/tests/fixtures/WithMethods.php b/tests/fixtures/WithMethods.php index 2ecddf4..524da3d 100644 --- a/tests/fixtures/WithMethods.php +++ b/tests/fixtures/WithMethods.php @@ -12,7 +12,7 @@ final class WithMethods { public function publicMethod(Iterator&Countable $parameter): ?static { - return new static(); + return $parameter instanceof SplHeap ? new static() : null; } public static function publicStaticMethod(int|float $parameter): void diff --git a/tests/src/Double/FakeStringifier.php b/tests/src/Double/FakeStringifier.php index 15d540c..1c871bb 100644 --- a/tests/src/Double/FakeStringifier.php +++ b/tests/src/Double/FakeStringifier.php @@ -18,7 +18,7 @@ final class FakeStringifier implements Stringifier { - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string { return implode('.', ['fake', $depth, hash('crc32', serialize($raw))]); } diff --git a/tests/unit/Stringifiers/CallableStringifierTest.php b/tests/unit/Stringifiers/CallableStringifierTest.php index c09d411..42f7db7 100644 --- a/tests/unit/Stringifiers/CallableStringifierTest.php +++ b/tests/unit/Stringifiers/CallableStringifierTest.php @@ -24,9 +24,6 @@ use function array_sum; use function sprintf; -use const PHP_MAJOR_VERSION; -use const PHP_MINOR_VERSION; - #[CoversClass(CallableStringifier::class)] final class CallableStringifierTest extends TestCase { @@ -76,10 +73,6 @@ public function itShouldStringifyWhenRawValueIsCallableWithDefaultValues(): void #[Test] public function itShouldStringifyWhenRawValueIsCallableThatDoesNotHaveAnAccessibleDefaultValue(): void { - if ([8, 1] !== [PHP_MAJOR_VERSION, PHP_MINOR_VERSION]) { - self::markTestSkipped('This test is not applicable to PHP 8.1+'); - } - $raw = 'array_walk'; $quoter = new FakeQuoter(); @@ -88,7 +81,7 @@ public function itShouldStringifyWhenRawValueIsCallableThatDoesNotHaveAnAccessib $actual = $sut->stringify($raw, self::DEPTH); $expected = $quoter->quote( - 'array_walk(object|array &$array, callable $callback, ?mixed $arg = fake.1.cbade92e): bool', + 'array_walk(object|array &$array, callable $callback, ?mixed $arg = fake.1.cbade92e): true', self::DEPTH ); From fa1ac4054209e9ac37a16e593818e4fdc37829ea Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 23 Dec 2025 15:25:54 +0100 Subject: [PATCH 3/3] Bump respect/coding-standard from 4 to 5 I had to make a few manual changes for everything to pass. --- composer.json | 3 +- phpcs.xml.dist | 15 +++++++ src/Helpers/ObjectHelper.php | 2 +- src/Quoters/StandardQuoter.php | 6 +-- src/Stringifier.php | 2 +- src/Stringifiers/ArrayObjectStringifier.php | 6 +-- src/Stringifiers/ArrayStringifier.php | 12 +++-- src/Stringifiers/BoolStringifier.php | 4 +- src/Stringifiers/CallableStringifier.php | 38 ++++++++++------ src/Stringifiers/CompositeStringifier.php | 20 ++++----- src/Stringifiers/DateTimeStringifier.php | 4 +- src/Stringifiers/DeclaredStringifier.php | 4 +- src/Stringifiers/EnumerationStringifier.php | 4 +- src/Stringifiers/FiberObjectStringifier.php | 8 ++-- .../InfiniteNumberStringifier.php | 4 +- .../IteratorObjectStringifier.php | 6 +-- src/Stringifiers/JsonEncodableStringifier.php | 2 +- .../JsonSerializableObjectStringifier.php | 6 +-- src/Stringifiers/NotANumberStringifier.php | 4 +- src/Stringifiers/NullStringifier.php | 4 +- src/Stringifiers/ObjectStringifier.php | 16 +++---- .../ObjectWithDebugInfoStringifier.php | 6 +-- src/Stringifiers/ResourceStringifier.php | 4 +- .../StringableObjectStringifier.php | 6 +-- .../ThrowableObjectStringifier.php | 8 ++-- src/Stringify.php | 4 +- tests/fixtures/ConcreteIterator.php | 6 +-- tests/fixtures/ConcreteJsonSerializable.php | 6 +-- tests/fixtures/WithDebugInfo.php | 4 +- tests/fixtures/WithMethods.php | 2 +- tests/integration/stringify-array.phpt | 7 +-- tests/integration/stringify-callable.phpt | 2 +- tests/src/Double/FakeQuoter.php | 2 +- tests/src/Double/LameStringifier.php | 2 +- tests/unit/Quoters/StandardQuoterTest.php | 6 +-- .../ArrayObjectStringifierTest.php | 4 +- .../Stringifiers/ArrayStringifierTest.php | 26 +++++------ .../unit/Stringifiers/BoolStringifierTest.php | 2 +- .../Stringifiers/CallableStringifierTest.php | 11 +++-- .../Stringifiers/CompositeStringifierTest.php | 2 +- .../Stringifiers/DateTimeStringifierTest.php | 8 ++-- .../Stringifiers/DeclaredStringifierTest.php | 6 +-- .../EnumerationStringifierTest.php | 2 +- .../FiberObjectStringifierTest.php | 4 +- .../InfiniteNumberStringifierTest.php | 2 +- .../IteratorObjectStringifierTest.php | 4 +- .../JsonEncodableStringifierTest.php | 2 +- .../JsonSerializableObjectStringifierTest.php | 4 +- .../NotANumberStringifierTest.php | 2 +- .../unit/Stringifiers/NullStringifierTest.php | 2 +- .../Stringifiers/ObjectStringifierTest.php | 44 +++++++++---------- .../ObjectWithDebugInfoStringifierTest.php | 4 +- .../Stringifiers/ResourceStringifierTest.php | 2 +- .../StringableObjectStringifierTest.php | 4 +- .../ThrowableObjectStringifierTest.php | 14 +++--- 55 files changed, 191 insertions(+), 193 deletions(-) diff --git a/composer.json b/composer.json index e12c006..fc4d03f 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,7 @@ "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^12.5", - "respect/coding-standard": "^4.0", - "squizlabs/php_codesniffer": "^3.7" + "respect/coding-standard": "^5.0" }, "autoload": { "psr-4": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 5f374f3..1e228c6 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -17,4 +17,19 @@ tests/fixtures/ + + tests/unit/Stringifiers/CallableStringifierTest.php + + + tests/integration/lib/helpers.php + + + tests/integration/ + + + tests/integration/ + + + tests/integration/ + diff --git a/src/Helpers/ObjectHelper.php b/src/Helpers/ObjectHelper.php index 47555c8..c3154f6 100644 --- a/src/Helpers/ObjectHelper.php +++ b/src/Helpers/ObjectHelper.php @@ -18,7 +18,7 @@ trait ObjectHelper { - private function format(object $object, ?string ...$pieces): string + private function format(object $object, string|null ...$pieces): string { $filteredPieces = array_filter($pieces); if (count($filteredPieces) === 0) { diff --git a/src/Quoters/StandardQuoter.php b/src/Quoters/StandardQuoter.php index 59c4cd4..44e6ccc 100644 --- a/src/Quoters/StandardQuoter.php +++ b/src/Quoters/StandardQuoter.php @@ -20,9 +20,9 @@ final class StandardQuoter implements Quoter { - private const OBJECT_PLACEHOLDER = ' ... }'; - private const ARRAY_PLACEHOLDER = ' ... ]'; - private const GENERIC_PLACEHOLDER = ' ...'; + private const string OBJECT_PLACEHOLDER = ' ... }'; + private const string ARRAY_PLACEHOLDER = ' ... ]'; + private const string GENERIC_PLACEHOLDER = ' ...'; public function __construct(private readonly int $maximumLength) { diff --git a/src/Stringifier.php b/src/Stringifier.php index c8d423d..7b066a3 100644 --- a/src/Stringifier.php +++ b/src/Stringifier.php @@ -12,5 +12,5 @@ interface Stringifier { - public function stringify(mixed $raw, int $depth): ?string; + public function stringify(mixed $raw, int $depth): string|null; } diff --git a/src/Stringifiers/ArrayObjectStringifier.php b/src/Stringifiers/ArrayObjectStringifier.php index 314742a..bfec6bd 100644 --- a/src/Stringifiers/ArrayObjectStringifier.php +++ b/src/Stringifiers/ArrayObjectStringifier.php @@ -21,11 +21,11 @@ final class ArrayObjectStringifier implements Stringifier public function __construct( private readonly Stringifier $stringifier, - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!$raw instanceof ArrayObject) { return null; @@ -33,7 +33,7 @@ public function stringify(mixed $raw, int $depth): ?string return $this->quoter->quote( $this->format($raw, 'getArrayCopy() =>', $this->stringifier->stringify($raw->getArrayCopy(), $depth + 1)), - $depth + $depth, ); } } diff --git a/src/Stringifiers/ArrayStringifier.php b/src/Stringifiers/ArrayStringifier.php index 1d009b9..9c85f52 100644 --- a/src/Stringifiers/ArrayStringifier.php +++ b/src/Stringifiers/ArrayStringifier.php @@ -22,17 +22,17 @@ final class ArrayStringifier implements Stringifier { - private const LIMIT_EXCEEDED_PLACEHOLDER = '...'; + private const string LIMIT_EXCEEDED_PLACEHOLDER = '...'; public function __construct( private readonly Stringifier $stringifier, private readonly Quoter $quoter, private readonly int $maximumDepth, - private readonly int $maximumNumberOfItems + private readonly int $maximumNumberOfItems, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!is_array($raw)) { return null; @@ -66,7 +66,7 @@ public function stringify(mixed $raw, int $depth): ?string return $this->quoter->quote(sprintf('[%s]', implode(', ', $items)), $depth); } - private function stringifyKeyValue(mixed $value, int $depth): ?string + private function stringifyKeyValue(mixed $value, int $depth): string|null { if (is_array($value)) { return $this->stringify($value, $depth); @@ -75,9 +75,7 @@ private function stringifyKeyValue(mixed $value, int $depth): ?string return $this->stringifier->stringify($value, $depth); } - /** - * @param mixed[] $array - */ + /** @param mixed[] $array */ private function isSequential(array $array): bool { return array_keys($array) === range(0, count($array) - 1); diff --git a/src/Stringifiers/BoolStringifier.php b/src/Stringifiers/BoolStringifier.php index 205209b..323920d 100644 --- a/src/Stringifiers/BoolStringifier.php +++ b/src/Stringifiers/BoolStringifier.php @@ -18,11 +18,11 @@ final class BoolStringifier implements Stringifier { public function __construct( - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!is_bool($raw)) { return null; diff --git a/src/Stringifiers/CallableStringifier.php b/src/Stringifiers/CallableStringifier.php index ae35f67..6158199 100644 --- a/src/Stringifiers/CallableStringifier.php +++ b/src/Stringifiers/CallableStringifier.php @@ -47,7 +47,7 @@ public function __construct( ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!is_callable($raw)) { return null; @@ -69,8 +69,7 @@ public function stringify(mixed $raw, int $depth): ?string return $this->buildStaticMethod(new ReflectionMethod($raw[0], $raw[1]), $depth); } - /** @var callable-string $raw */ - if (str_contains($raw, ':')) { + if (is_string($raw) && str_contains($raw, ':')) { /** @var class-string $class */ $class = (string) strstr($raw, ':', true); $method = substr((string) strrchr($raw, ':'), 1); @@ -78,6 +77,10 @@ public function stringify(mixed $raw, int $depth): ?string return $this->buildStaticMethod(new ReflectionMethod($class, $method), $depth); } + if (!is_string($raw)) { + return null; + } + return $this->buildFunction(new ReflectionFunction($raw), $depth); } @@ -90,7 +93,7 @@ private function buildMethod(ReflectionMethod $reflection, object $object, int $ { return $this->quoter->quote( sprintf('%s->%s', $this->getName($object), $this->buildSignature($reflection, $depth)), - $depth + $depth, ); } @@ -98,7 +101,7 @@ private function buildStaticMethod(ReflectionMethod $reflection, int $depth): st { return $this->quoter->quote( sprintf('%s::%s', $reflection->class, $this->buildSignature($reflection, $depth)), - $depth + $depth, ); } @@ -112,10 +115,10 @@ private function buildSignature(ReflectionFunctionAbstract $function, int $depth array_map( fn(ReflectionParameter $parameter): string => $this->buildParameter( $parameter, - $depth + 1 + $depth + 1, ), - $function->getParameters() - ) + $function->getParameters(), + ), ), ); @@ -125,7 +128,7 @@ private function buildSignature(ReflectionFunctionAbstract $function, int $depth ' use ($%s)', implode( ', $', - array_keys($closureUsedVariables) + array_keys($closureUsedVariables), ), ); } @@ -160,7 +163,7 @@ private function buildParameter(ReflectionParameter $reflectionParameter, int $d return $parameter; } - private function buildValue(ReflectionParameter $reflectionParameter, int $depth): ?string + private function buildValue(ReflectionParameter $reflectionParameter, int $depth): string|null { if (!$reflectionParameter->isDefaultValueAvailable()) { return $this->stringifier->stringify(null, $depth); @@ -178,19 +181,26 @@ private function buildType(ReflectionType $raw, int $depth): string if ($raw instanceof ReflectionUnionType) { return implode( '|', - array_map(fn(ReflectionType $type) => $this->buildType($type, $depth), $raw->getTypes()) + array_map(fn(ReflectionType $type) => $this->buildType($type, $depth), $raw->getTypes()), ); } if ($raw instanceof ReflectionIntersectionType) { return implode( '&', - array_map(fn(ReflectionType $type) => $this->buildType($type, $depth), $raw->getTypes()) + array_map(fn(ReflectionType $type) => $this->buildType($type, $depth), $raw->getTypes()), ); } - /** @var ReflectionNamedType $raw */ + if ($raw instanceof ReflectionNamedType) { + $type = $raw->getName(); + if ($raw->allowsNull()) { + $type = sprintf('?%s', $type); + } + + return $type; + } - return ($raw->allowsNull() ? '?' : '') . $raw->getName(); + return ''; } } diff --git a/src/Stringifiers/CompositeStringifier.php b/src/Stringifiers/CompositeStringifier.php index 4341845..21926f9 100644 --- a/src/Stringifiers/CompositeStringifier.php +++ b/src/Stringifiers/CompositeStringifier.php @@ -18,14 +18,12 @@ final class CompositeStringifier implements Stringifier { - private const MAXIMUM_DEPTH = 3; - private const MAXIMUM_NUMBER_OF_ITEMS = 5; - private const MAXIMUM_NUMBER_OF_PROPERTIES = self::MAXIMUM_NUMBER_OF_ITEMS; - private const MAXIMUM_LENGTH = 120; + private const int MAXIMUM_DEPTH = 3; + private const int MAXIMUM_NUMBER_OF_ITEMS = 5; + private const int MAXIMUM_NUMBER_OF_PROPERTIES = self::MAXIMUM_NUMBER_OF_ITEMS; + private const int MAXIMUM_LENGTH = 120; - /** - * @var Stringifier[] - */ + /** @var Stringifier[] */ private array $stringifiers = []; public function __construct(Stringifier ...$stringifiers) @@ -52,15 +50,15 @@ public static function createDefault(): self $quoter, self::MAXIMUM_DEPTH, self::MAXIMUM_NUMBER_OF_ITEMS, - ) + ), ); $stringifier->prependStringifier( new ObjectStringifier( $stringifier, $quoter, self::MAXIMUM_DEPTH, - self::MAXIMUM_NUMBER_OF_PROPERTIES - ) + self::MAXIMUM_NUMBER_OF_PROPERTIES, + ), ); $stringifier->prependStringifier($callableStringifier = new CallableStringifier($stringifier, $quoter)); $stringifier->prependStringifier(new FiberObjectStringifier($callableStringifier, $quoter)); @@ -81,7 +79,7 @@ public function prependStringifier(Stringifier $stringifier): void array_unshift($this->stringifiers, $stringifier); } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { foreach ($this->stringifiers as $stringifier) { $string = $stringifier->stringify($raw, $depth); diff --git a/src/Stringifiers/DateTimeStringifier.php b/src/Stringifiers/DateTimeStringifier.php index 6c6c9d8..926d088 100644 --- a/src/Stringifiers/DateTimeStringifier.php +++ b/src/Stringifiers/DateTimeStringifier.php @@ -21,11 +21,11 @@ final class DateTimeStringifier implements Stringifier public function __construct( private readonly Quoter $quoter, - private readonly string $format + private readonly string $format, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!$raw instanceof DateTimeInterface) { return null; diff --git a/src/Stringifiers/DeclaredStringifier.php b/src/Stringifiers/DeclaredStringifier.php index 065689a..39b59c9 100644 --- a/src/Stringifiers/DeclaredStringifier.php +++ b/src/Stringifiers/DeclaredStringifier.php @@ -22,11 +22,11 @@ final class DeclaredStringifier implements Stringifier { public function __construct( - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!is_string($raw) || $this->isNotDeclared($raw)) { return null; diff --git a/src/Stringifiers/EnumerationStringifier.php b/src/Stringifiers/EnumerationStringifier.php index 5a3f9fa..f56c63a 100644 --- a/src/Stringifiers/EnumerationStringifier.php +++ b/src/Stringifiers/EnumerationStringifier.php @@ -19,11 +19,11 @@ final class EnumerationStringifier implements Stringifier { public function __construct( - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!$raw instanceof UnitEnum) { return null; diff --git a/src/Stringifiers/FiberObjectStringifier.php b/src/Stringifiers/FiberObjectStringifier.php index 6aebd31..353396d 100644 --- a/src/Stringifiers/FiberObjectStringifier.php +++ b/src/Stringifiers/FiberObjectStringifier.php @@ -21,11 +21,11 @@ final class FiberObjectStringifier implements Stringifier { public function __construct( private readonly Stringifier $stringifier, - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!$raw instanceof Fiber) { return null; @@ -34,9 +34,9 @@ public function stringify(mixed $raw, int $depth): ?string return $this->quoter->quote( sprintf( 'Fiber { %s }', - $this->stringifier->stringify((new ReflectionFiber($raw))->getCallable(), $depth + 1) + $this->stringifier->stringify((new ReflectionFiber($raw))->getCallable(), $depth + 1), ), - $depth + $depth, ); } } diff --git a/src/Stringifiers/InfiniteNumberStringifier.php b/src/Stringifiers/InfiniteNumberStringifier.php index c485538..39ec918 100644 --- a/src/Stringifiers/InfiniteNumberStringifier.php +++ b/src/Stringifiers/InfiniteNumberStringifier.php @@ -19,11 +19,11 @@ final class InfiniteNumberStringifier implements Stringifier { public function __construct( - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!is_float($raw)) { return null; diff --git a/src/Stringifiers/IteratorObjectStringifier.php b/src/Stringifiers/IteratorObjectStringifier.php index aa0ad5a..de578af 100644 --- a/src/Stringifiers/IteratorObjectStringifier.php +++ b/src/Stringifiers/IteratorObjectStringifier.php @@ -21,11 +21,11 @@ final class IteratorObjectStringifier implements Stringifier public function __construct( private readonly Stringifier $stringifier, - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!$raw instanceof Iterator) { return null; @@ -37,7 +37,7 @@ public function stringify(mixed $raw, int $depth): ?string return $this->quoter->quote( $this->format($raw, 'current() =>', $this->stringifier->stringify($raw->current(), $depth + 1)), - $depth + $depth, ); } } diff --git a/src/Stringifiers/JsonEncodableStringifier.php b/src/Stringifiers/JsonEncodableStringifier.php index e1a21ea..36e5c77 100644 --- a/src/Stringifiers/JsonEncodableStringifier.php +++ b/src/Stringifiers/JsonEncodableStringifier.php @@ -20,7 +20,7 @@ final class JsonEncodableStringifier implements Stringifier { - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { $string = json_encode($raw, (JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION)); if ($string === false) { diff --git a/src/Stringifiers/JsonSerializableObjectStringifier.php b/src/Stringifiers/JsonSerializableObjectStringifier.php index 2d8d077..a20eced 100644 --- a/src/Stringifiers/JsonSerializableObjectStringifier.php +++ b/src/Stringifiers/JsonSerializableObjectStringifier.php @@ -21,11 +21,11 @@ final class JsonSerializableObjectStringifier implements Stringifier public function __construct( private readonly Stringifier $stringifier, - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!$raw instanceof JsonSerializable) { return null; @@ -33,7 +33,7 @@ public function stringify(mixed $raw, int $depth): ?string return $this->quoter->quote( $this->format($raw, 'jsonSerialize() =>', $this->stringifier->stringify($raw->jsonSerialize(), $depth + 1)), - $depth + $depth, ); } } diff --git a/src/Stringifiers/NotANumberStringifier.php b/src/Stringifiers/NotANumberStringifier.php index 9487cc2..63d1f52 100644 --- a/src/Stringifiers/NotANumberStringifier.php +++ b/src/Stringifiers/NotANumberStringifier.php @@ -19,11 +19,11 @@ final class NotANumberStringifier implements Stringifier { public function __construct( - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!is_float($raw)) { return null; diff --git a/src/Stringifiers/NullStringifier.php b/src/Stringifiers/NullStringifier.php index cd2c3b8..a110e34 100644 --- a/src/Stringifiers/NullStringifier.php +++ b/src/Stringifiers/NullStringifier.php @@ -16,11 +16,11 @@ final class NullStringifier implements Stringifier { public function __construct( - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if ($raw !== null) { return null; diff --git a/src/Stringifiers/ObjectStringifier.php b/src/Stringifiers/ObjectStringifier.php index d13a3a1..914e76a 100644 --- a/src/Stringifiers/ObjectStringifier.php +++ b/src/Stringifiers/ObjectStringifier.php @@ -25,17 +25,17 @@ final class ObjectStringifier implements Stringifier { use ObjectHelper; - private const LIMIT_EXCEEDED_PLACEHOLDER = '...'; + private const string LIMIT_EXCEEDED_PLACEHOLDER = '...'; public function __construct( private readonly Stringifier $stringifier, private readonly Quoter $quoter, private readonly int $maximumDepth, - private readonly int $maximumNumberOfProperties + private readonly int $maximumNumberOfProperties, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!is_object($raw)) { return null; @@ -47,13 +47,11 @@ public function stringify(mixed $raw, int $depth): ?string return $this->quoter->quote( $this->format($raw, ...$this->getProperties(new ReflectionObject($raw), $raw, $depth + 1)), - $depth + $depth, ); } - /** - * @return array - */ + /** @return array */ private function getProperties(ReflectionObject $reflectionObject, object $object, int $depth): array { $reflectionProperties = $reflectionObject->getProperties(); @@ -76,14 +74,14 @@ private function getProperties(ReflectionObject $reflectionObject, object $objec default => '+', }, $reflectionProperty->getName(), - $this->getPropertyValue($reflectionProperty, $object, $depth) + $this->getPropertyValue($reflectionProperty, $object, $depth), )); } return $properties; } - private function getPropertyValue(ReflectionProperty $reflectionProperty, object $object, int $depth): ?string + private function getPropertyValue(ReflectionProperty $reflectionProperty, object $object, int $depth): string|null { if (!$reflectionProperty->isInitialized($object)) { return '*uninitialized*'; diff --git a/src/Stringifiers/ObjectWithDebugInfoStringifier.php b/src/Stringifiers/ObjectWithDebugInfoStringifier.php index 2718620..f1cca8a 100644 --- a/src/Stringifiers/ObjectWithDebugInfoStringifier.php +++ b/src/Stringifiers/ObjectWithDebugInfoStringifier.php @@ -23,11 +23,11 @@ final class ObjectWithDebugInfoStringifier implements Stringifier public function __construct( private readonly Stringifier $stringifier, - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!(is_object($raw) && method_exists($raw, '__debugInfo'))) { return null; @@ -35,7 +35,7 @@ public function stringify(mixed $raw, int $depth): ?string return $this->quoter->quote( $this->format($raw, '__debugInfo() =>', $this->stringifier->stringify($raw->__debugInfo(), $depth + 1)), - $depth + $depth, ); } } diff --git a/src/Stringifiers/ResourceStringifier.php b/src/Stringifiers/ResourceStringifier.php index c8707cf..0f55406 100644 --- a/src/Stringifiers/ResourceStringifier.php +++ b/src/Stringifiers/ResourceStringifier.php @@ -20,11 +20,11 @@ final class ResourceStringifier implements Stringifier { public function __construct( - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!is_resource($raw)) { return null; diff --git a/src/Stringifiers/StringableObjectStringifier.php b/src/Stringifiers/StringableObjectStringifier.php index 4aff4d6..121e9dc 100644 --- a/src/Stringifiers/StringableObjectStringifier.php +++ b/src/Stringifiers/StringableObjectStringifier.php @@ -21,11 +21,11 @@ final class StringableObjectStringifier implements Stringifier public function __construct( private readonly Stringifier $stringifier, - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!$raw instanceof Stringable) { return null; @@ -33,7 +33,7 @@ public function stringify(mixed $raw, int $depth): ?string return $this->quoter->quote( $this->format($raw, '__toString() =>', $this->stringifier->stringify($raw->__toString(), $depth + 1)), - $depth + $depth, ); } } diff --git a/src/Stringifiers/ThrowableObjectStringifier.php b/src/Stringifiers/ThrowableObjectStringifier.php index ab912af..9e4a2f8 100644 --- a/src/Stringifiers/ThrowableObjectStringifier.php +++ b/src/Stringifiers/ThrowableObjectStringifier.php @@ -24,11 +24,11 @@ final class ThrowableObjectStringifier implements Stringifier public function __construct( private readonly Stringifier $stringifier, - private readonly Quoter $quoter + private readonly Quoter $quoter, ) { } - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { if (!$raw instanceof Throwable) { return null; @@ -43,9 +43,9 @@ public function stringify(mixed $raw, int $depth): ?string $raw, $this->stringifier->stringify($raw->getMessage(), $depth + 1), 'in', - $this->getSource($raw) + $this->getSource($raw), ), - $depth + $depth, ); } diff --git a/src/Stringify.php b/src/Stringify.php index c5f015e..3462365 100644 --- a/src/Stringify.php +++ b/src/Stringify.php @@ -16,10 +16,10 @@ final class Stringify { - public const STARTING_DEPTH = 0; + public const int STARTING_DEPTH = 0; public function __construct( - private readonly Stringifier $stringifier + private readonly Stringifier $stringifier, ) { } diff --git a/tests/fixtures/ConcreteIterator.php b/tests/fixtures/ConcreteIterator.php index a7f1622..604e689 100644 --- a/tests/fixtures/ConcreteIterator.php +++ b/tests/fixtures/ConcreteIterator.php @@ -8,12 +8,10 @@ declare(strict_types=1); -/** - * @implements Iterator - */ +/** @implements Iterator */ final class ConcreteIterator implements Iterator { - private const VALUES = [1, 2, 3]; + private const array VALUES = [1, 2, 3]; private int $position = 0; diff --git a/tests/fixtures/ConcreteJsonSerializable.php b/tests/fixtures/ConcreteJsonSerializable.php index 9bb555f..2a4b4f2 100644 --- a/tests/fixtures/ConcreteJsonSerializable.php +++ b/tests/fixtures/ConcreteJsonSerializable.php @@ -10,11 +10,9 @@ final class ConcreteJsonSerializable implements JsonSerializable { - public const JSON_VALUE = [1, 2, 3, 'foo' => true]; + public const array JSON_VALUE = [1, 2, 3, 'foo' => true]; - /** - * @return array - */ + /** @return array */ public function jsonSerialize(): array { return self::JSON_VALUE; diff --git a/tests/fixtures/WithDebugInfo.php b/tests/fixtures/WithDebugInfo.php index b17534e..a9eb222 100644 --- a/tests/fixtures/WithDebugInfo.php +++ b/tests/fixtures/WithDebugInfo.php @@ -10,9 +10,7 @@ final class WithDebugInfo { - /** - * @return array - */ + /** @return array */ public function __debugInfo(): array { return ['info' => 'This is the return of __debugInfo()']; diff --git a/tests/fixtures/WithMethods.php b/tests/fixtures/WithMethods.php index 524da3d..7dc2afb 100644 --- a/tests/fixtures/WithMethods.php +++ b/tests/fixtures/WithMethods.php @@ -10,7 +10,7 @@ final class WithMethods { - public function publicMethod(Iterator&Countable $parameter): ?static + public function publicMethod(Iterator&Countable $parameter): static|null { return $parameter instanceof SplHeap ? new static() : null; } diff --git a/tests/integration/stringify-array.phpt b/tests/integration/stringify-array.phpt index 0ec6ba7..ae5bee0 100644 --- a/tests/integration/stringify-array.phpt +++ b/tests/integration/stringify-array.phpt @@ -12,11 +12,8 @@ output([ 1.000, [ tmpfile(), - [ - 1, - ], - [ - ], + [1], + [], ], ], false, diff --git a/tests/integration/stringify-callable.phpt b/tests/integration/stringify-callable.phpt index 8d23380..4ad861d 100644 --- a/tests/integration/stringify-callable.phpt +++ b/tests/integration/stringify-callable.phpt @@ -16,7 +16,7 @@ outputMultiple( static fn(int $foo): bool => (bool) $foo, static function (int $foo) use ($variable): string { return $variable::class; - } + }, ); ?> --EXPECT-- diff --git a/tests/src/Double/FakeQuoter.php b/tests/src/Double/FakeQuoter.php index d2cf4b1..d56e395 100644 --- a/tests/src/Double/FakeQuoter.php +++ b/tests/src/Double/FakeQuoter.php @@ -16,7 +16,7 @@ final class FakeQuoter implements Quoter { - private const SYMBOL = '#'; + private const string SYMBOL = '#'; public function quote(string $string, int $depth): string { diff --git a/tests/src/Double/LameStringifier.php b/tests/src/Double/LameStringifier.php index 6e8d7b4..fb8ca38 100644 --- a/tests/src/Double/LameStringifier.php +++ b/tests/src/Double/LameStringifier.php @@ -14,7 +14,7 @@ final class LameStringifier implements Stringifier { - public function stringify(mixed $raw, int $depth): ?string + public function stringify(mixed $raw, int $depth): string|null { return null; } diff --git a/tests/unit/Quoters/StandardQuoterTest.php b/tests/unit/Quoters/StandardQuoterTest.php index 50aafb6..ea476e2 100644 --- a/tests/unit/Quoters/StandardQuoterTest.php +++ b/tests/unit/Quoters/StandardQuoterTest.php @@ -21,7 +21,7 @@ #[CoversClass(StandardQuoter::class)] final class StandardQuoterTest extends TestCase { - private const LIMIT = 20; + private const int LIMIT = 20; #[Test] public function itShouldNotQuoteWhenDepthIsBiggerThanZero(): void @@ -46,9 +46,7 @@ public function isShouldQuoteWhenDepthIsBiggerThanZero(string $string, string $e self::assertLessThanOrEqual(self::LIMIT, strlen($actual)); } - /** - * @return array> - */ + /** @return array> */ public static function provideData(): array { return [ diff --git a/tests/unit/Stringifiers/ArrayObjectStringifierTest.php b/tests/unit/Stringifiers/ArrayObjectStringifierTest.php index f2b45df..fc634a1 100644 --- a/tests/unit/Stringifiers/ArrayObjectStringifierTest.php +++ b/tests/unit/Stringifiers/ArrayObjectStringifierTest.php @@ -24,7 +24,7 @@ #[CoversClass(ArrayObjectStringifier::class)] final class ArrayObjectStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotAnArrayObject(): void @@ -49,7 +49,7 @@ public function itShouldStringifyRawValueWhenItIsAnArrayObject(): void $actual = $sut->stringify($raw, self::DEPTH); $expected = $quoter->quote( sprintf('ArrayObject { getArrayCopy() => %s }', $string), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); diff --git a/tests/unit/Stringifiers/ArrayStringifierTest.php b/tests/unit/Stringifiers/ArrayStringifierTest.php index 958b141..ef16b66 100644 --- a/tests/unit/Stringifiers/ArrayStringifierTest.php +++ b/tests/unit/Stringifiers/ArrayStringifierTest.php @@ -63,9 +63,9 @@ public function itShouldStringifyRawValueWhenItIsAnNonAssociativeArray(): void '[%s, %s, %s]', $stringifier->stringify($raw[0], $depth + 1), $stringifier->stringify($raw[1], $depth + 1), - $stringifier->stringify($raw[2], $depth + 1) + $stringifier->stringify($raw[2], $depth + 1), ), - $depth + $depth, ); self::assertSame($expected, $actual); @@ -91,7 +91,7 @@ public function itShouldStringifyRawValueWhenItIsAnAssociativeArray(): void $stringifier->stringify('bar', $depth + 1), $stringifier->stringify($raw['bar'], $depth + 1), ), - $depth + $depth, ); self::assertSame($expected, $actual); @@ -115,7 +115,7 @@ public function itShouldStringifyRawValueWhenIsNotSequentialArray(): void $stringifier->stringify(2, $depth + 1), $stringifier->stringify(3, $depth + 1), ), - $depth + $depth, ); self::assertSame($expected, $sut->stringify($raw, $depth)); @@ -148,13 +148,13 @@ public function itShouldStringifyRawValueWhenItIsNestedArray(): void $stringifier->stringify('d', $depth + 3), $stringifier->stringify('e', $depth + 3), ), - $depth + 2 - ) + $depth + 2, + ), ), - $depth + 1 + $depth + 1, ), ), - $depth + $depth, ); self::assertSame($expected, $actual); @@ -224,13 +224,13 @@ public function itShouldStringifyRawValueWithPlaceholderWhenItReachesTheMaximumD $stringifier->stringify('c', $depth + 3), $quoter->quote('...', $depth + 3), ), - $depth + 2 - ) + $depth + 2, + ), ), - $depth + 1 + $depth + 1, ), ), - $depth + $depth, ); self::assertSame($expected, $actual); @@ -256,7 +256,7 @@ public function itShouldStringifyRawValueWithPlaceholderWhenLimitOfItemsIsReache $stringifier->stringify(2, $depth + 1), $stringifier->stringify(3, $depth + 1), ), - $depth + $depth, ); $actual = $sut->stringify($raw, $depth); diff --git a/tests/unit/Stringifiers/BoolStringifierTest.php b/tests/unit/Stringifiers/BoolStringifierTest.php index 872f4e8..51a2a68 100644 --- a/tests/unit/Stringifiers/BoolStringifierTest.php +++ b/tests/unit/Stringifiers/BoolStringifierTest.php @@ -19,7 +19,7 @@ #[CoversClass(BoolStringifier::class)] final class BoolStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyWhenRawValueIsNotBoolean(): void diff --git a/tests/unit/Stringifiers/CallableStringifierTest.php b/tests/unit/Stringifiers/CallableStringifierTest.php index 42f7db7..fb298bb 100644 --- a/tests/unit/Stringifiers/CallableStringifierTest.php +++ b/tests/unit/Stringifiers/CallableStringifierTest.php @@ -27,7 +27,7 @@ #[CoversClass(CallableStringifier::class)] final class CallableStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyWhenRawValueIsNotCallable(): void @@ -64,7 +64,7 @@ public function itShouldStringifyWhenRawValueIsCallableWithDefaultValues(): void $actual = $sut->stringify($raw, self::DEPTH); $expected = $quoter->quote( sprintf('function (int $value = %s): int', $stringifier->stringify(1, self::DEPTH + 1)), - self::DEPTH + self::DEPTH, ); self::assertEquals($expected, $actual); @@ -82,15 +82,13 @@ public function itShouldStringifyWhenRawValueIsCallableThatDoesNotHaveAnAccessib $actual = $sut->stringify($raw, self::DEPTH); $expected = $quoter->quote( 'array_walk(object|array &$array, callable $callback, ?mixed $arg = fake.1.cbade92e): true', - self::DEPTH + self::DEPTH, ); self::assertEquals($expected, $actual); } - /** - * @return array - */ + /** @return array */ public static function callableRawValuesProvider(): array { $var1 = 1; @@ -101,6 +99,7 @@ public static function callableRawValuesProvider(): array [static fn(): int => 1, 'function (): int'], [static fn(float $value): int => (int) $value, 'function (float $value): int'], [static fn(float &$value): int => (int) $value, 'function (float &$value): int'], + // phpcs:ignore SlevomatCodingStandard.TypeHints.DNFTypeHintFormat [static fn(?float $value): int => (int) $value, 'function (?float $value): int'], [static fn(int $value = self::DEPTH): int => $value, 'function (int $value = self::DEPTH): int'], [static fn(int|float $value): int => (int) $value, 'function (int|float $value): int'], diff --git a/tests/unit/Stringifiers/CompositeStringifierTest.php b/tests/unit/Stringifiers/CompositeStringifierTest.php index fbe5099..22b1806 100644 --- a/tests/unit/Stringifiers/CompositeStringifierTest.php +++ b/tests/unit/Stringifiers/CompositeStringifierTest.php @@ -21,7 +21,7 @@ #[CoversClass(CompositeStringifier::class)] final class CompositeStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenThereAreNoStringifiersDefined(): void diff --git a/tests/unit/Stringifiers/DateTimeStringifierTest.php b/tests/unit/Stringifiers/DateTimeStringifierTest.php index 955b7b5..168ca3e 100644 --- a/tests/unit/Stringifiers/DateTimeStringifierTest.php +++ b/tests/unit/Stringifiers/DateTimeStringifierTest.php @@ -23,7 +23,7 @@ #[CoversClass(DateTimeStringifier::class)] final class DateTimeStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotInstanceOfDateTimeInterface(): void @@ -38,7 +38,7 @@ public function itShouldNotStringifyRawValueWhenItIsNotInstanceOfDateTimeInterfa public function itShouldStringifyRawValueWhenItIsInstanceOfDateTimeInterface( DateTimeInterface $raw, string $format, - string $string + string $string, ): void { $quoter = new FakeQuoter(); @@ -50,9 +50,7 @@ public function itShouldStringifyRawValueWhenItIsInstanceOfDateTimeInterface( self::assertSame($expected, $actual); } - /** - * @return array - */ + /** @return array */ public static function stringableRawValuesProvider(): array { $dateTime = new DateTime('2017-12-31T23:59:59+00:00'); diff --git a/tests/unit/Stringifiers/DeclaredStringifierTest.php b/tests/unit/Stringifiers/DeclaredStringifierTest.php index 42efcf2..af2d454 100644 --- a/tests/unit/Stringifiers/DeclaredStringifierTest.php +++ b/tests/unit/Stringifiers/DeclaredStringifierTest.php @@ -24,7 +24,7 @@ #[CoversClass(DeclaredStringifier::class)] final class DeclaredStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyWhenRawValueIsNotExists(): void @@ -48,9 +48,7 @@ public function itShouldStringifyWhenRawValueIsExists(string $raw): void self::assertEquals($expected, $actual); } - /** - * @return array> - */ + /** @return array> */ public static function existsRawValuesProvider(): array { return [ diff --git a/tests/unit/Stringifiers/EnumerationStringifierTest.php b/tests/unit/Stringifiers/EnumerationStringifierTest.php index 6178b95..a39c9a0 100644 --- a/tests/unit/Stringifiers/EnumerationStringifierTest.php +++ b/tests/unit/Stringifiers/EnumerationStringifierTest.php @@ -21,7 +21,7 @@ #[CoversClass(EnumerationStringifier::class)] final class EnumerationStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyWhenRawValueIsNotAnEnumeration(): void diff --git a/tests/unit/Stringifiers/FiberObjectStringifierTest.php b/tests/unit/Stringifiers/FiberObjectStringifierTest.php index fe1ced3..20b8c9d 100644 --- a/tests/unit/Stringifiers/FiberObjectStringifierTest.php +++ b/tests/unit/Stringifiers/FiberObjectStringifierTest.php @@ -25,7 +25,7 @@ #[CoversClass(FiberObjectStringifier::class)] final class FiberObjectStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotAnObjectWithDebugInfo(): void @@ -52,7 +52,7 @@ public function itShouldStringifyRawValueWhenItIsAnObjectWithDebugInfo(): void $actual = $sut->stringify($raw, self::DEPTH); $expected = $quoter->quote( sprintf('Fiber { %s }', $string), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); diff --git a/tests/unit/Stringifiers/InfiniteNumberStringifierTest.php b/tests/unit/Stringifiers/InfiniteNumberStringifierTest.php index 060feba..aadfe46 100644 --- a/tests/unit/Stringifiers/InfiniteNumberStringifierTest.php +++ b/tests/unit/Stringifiers/InfiniteNumberStringifierTest.php @@ -21,7 +21,7 @@ #[CoversClass(InfiniteNumberStringifier::class)] final class InfiniteNumberStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotFloat(): void diff --git a/tests/unit/Stringifiers/IteratorObjectStringifierTest.php b/tests/unit/Stringifiers/IteratorObjectStringifierTest.php index 13fdb85..1059855 100644 --- a/tests/unit/Stringifiers/IteratorObjectStringifierTest.php +++ b/tests/unit/Stringifiers/IteratorObjectStringifierTest.php @@ -24,7 +24,7 @@ #[CoversClass(IteratorObjectStringifier::class)] final class IteratorObjectStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotTraversable(): void @@ -58,7 +58,7 @@ public function itShouldStringifyRawValueWhenItIsAnInstanceOfIterator(): void 'ConcreteIterator { current() => %s }', $stringifier->stringify($raw->current(), self::DEPTH + 1), ), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); diff --git a/tests/unit/Stringifiers/JsonEncodableStringifierTest.php b/tests/unit/Stringifiers/JsonEncodableStringifierTest.php index 095322d..f8c84e4 100644 --- a/tests/unit/Stringifiers/JsonEncodableStringifierTest.php +++ b/tests/unit/Stringifiers/JsonEncodableStringifierTest.php @@ -20,7 +20,7 @@ #[CoversClass(JsonEncodableStringifier::class)] final class JsonEncodableStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItCannotBeConvertedToJson(): void diff --git a/tests/unit/Stringifiers/JsonSerializableObjectStringifierTest.php b/tests/unit/Stringifiers/JsonSerializableObjectStringifierTest.php index 9d1ee8b..5fcf4c7 100644 --- a/tests/unit/Stringifiers/JsonSerializableObjectStringifierTest.php +++ b/tests/unit/Stringifiers/JsonSerializableObjectStringifierTest.php @@ -24,7 +24,7 @@ #[CoversClass(JsonSerializableObjectStringifier::class)] final class JsonSerializableObjectStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotAnInstanceOfJsonSerializable(): void @@ -48,7 +48,7 @@ public function itShouldStringifyRawValueWhenItIsAnInstanceOfJsonSerializable(): $actual = $sut->stringify($raw, self::DEPTH); $expected = $quoter->quote( sprintf('%s { jsonSerialize() => %s }', ConcreteJsonSerializable::class, $jsonString), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); diff --git a/tests/unit/Stringifiers/NotANumberStringifierTest.php b/tests/unit/Stringifiers/NotANumberStringifierTest.php index f53b321..f89aa7f 100644 --- a/tests/unit/Stringifiers/NotANumberStringifierTest.php +++ b/tests/unit/Stringifiers/NotANumberStringifierTest.php @@ -21,7 +21,7 @@ #[CoversClass(NotANumberStringifier::class)] final class NotANumberStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotFloat(): void diff --git a/tests/unit/Stringifiers/NullStringifierTest.php b/tests/unit/Stringifiers/NullStringifierTest.php index 0c00837..b09a89e 100644 --- a/tests/unit/Stringifiers/NullStringifierTest.php +++ b/tests/unit/Stringifiers/NullStringifierTest.php @@ -19,7 +19,7 @@ #[CoversClass(NullStringifier::class)] final class NullStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotNull(): void diff --git a/tests/unit/Stringifiers/ObjectStringifierTest.php b/tests/unit/Stringifiers/ObjectStringifierTest.php index f157173..7dd3565 100644 --- a/tests/unit/Stringifiers/ObjectStringifierTest.php +++ b/tests/unit/Stringifiers/ObjectStringifierTest.php @@ -27,9 +27,9 @@ #[CoversClass(ObjectStringifier::class)] final class ObjectStringifierTest extends TestCase { - private const DEPTH = 0; - private const MAXIMUM_DEPTH = 4; - private const MAXIMUM_NUMBER_OF_PROPERTIES = 5; + private const int DEPTH = 0; + private const int MAXIMUM_DEPTH = 4; + private const int MAXIMUM_NUMBER_OF_PROPERTIES = 5; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotAnObject(): void @@ -38,7 +38,7 @@ public function itShouldNotStringifyRawValueWhenItIsNotAnObject(): void new FakeStringifier(), new FakeQuoter(), self::MAXIMUM_DEPTH, - self::MAXIMUM_NUMBER_OF_PROPERTIES + self::MAXIMUM_NUMBER_OF_PROPERTIES, ); self::assertNull($sut->stringify(true, self::DEPTH)); @@ -81,7 +81,7 @@ public function itShouldStringifyRawValueWhenItIsAnObjectWithProperties(): void $stringifier->stringify($relection->getProperty('protectedProperty')->getValue($raw), self::DEPTH + 1), $stringifier->stringify($relection->getProperty('privateProperty')->getValue($raw), self::DEPTH + 1), ), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); @@ -106,7 +106,7 @@ public function itShouldStringifyRawValueWhenItIsAnObjectWithUninitializedProper $relection->getName(), '*uninitialized*', ), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); @@ -141,15 +141,15 @@ public function itShouldStringifyRawValueWhenItIsAnObjectWithPropertiesThatAreOb sprintf( 'stdClass { +$e=%s +$f=%s }', $stringifier->stringify($raw->b->d->e, self::DEPTH + 3), - $quoter->quote('stdClass {}', self::DEPTH + 3) + $quoter->quote('stdClass {}', self::DEPTH + 3), ), - self::DEPTH + 2 - ) + self::DEPTH + 2, + ), ), - self::DEPTH + 1 - ) + self::DEPTH + 1, + ), ), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); @@ -178,15 +178,15 @@ public function itShouldStringifyRawValueWithPlaceholderWhenItReachesTheMaximumD $quoter->quote( sprintf( 'stdClass { +$property=%s }', - $quoter->quote('stdClass { ... }', $maximumDepth) + $quoter->quote('stdClass { ... }', $maximumDepth), ), - self::DEPTH + 2 - ) + self::DEPTH + 2, + ), ), - self::DEPTH + 1 - ) + self::DEPTH + 1, + ), ), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); @@ -216,7 +216,7 @@ public function itShouldStringifyRawValueWithPlaceholderWhenItReachesLimitOfItem $stringifier->stringify($raw->b, self::DEPTH + 1), $stringifier->stringify($raw->c, self::DEPTH + 1), ), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); @@ -238,9 +238,9 @@ public function itShouldStringifyRawValueWhenItIsAnAnonymousClass(): void $expected = $quoter->quote( sprintf( 'class { +$foo=%s }', - $stringifier->stringify($raw->foo, self::DEPTH + 1) + $stringifier->stringify($raw->foo, self::DEPTH + 1), ), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); @@ -258,7 +258,7 @@ public function itShouldStringifyRawValueWhenItIsAnAnonymousClassExtendingAnothe new FakeStringifier(), $quoter, self::MAXIMUM_DEPTH, - self::MAXIMUM_NUMBER_OF_PROPERTIES + self::MAXIMUM_NUMBER_OF_PROPERTIES, ); $actual = $sut->stringify($raw, self::DEPTH); diff --git a/tests/unit/Stringifiers/ObjectWithDebugInfoStringifierTest.php b/tests/unit/Stringifiers/ObjectWithDebugInfoStringifierTest.php index 3204537..aa6e3b7 100644 --- a/tests/unit/Stringifiers/ObjectWithDebugInfoStringifierTest.php +++ b/tests/unit/Stringifiers/ObjectWithDebugInfoStringifierTest.php @@ -24,7 +24,7 @@ #[CoversClass(ObjectWithDebugInfoStringifier::class)] final class ObjectWithDebugInfoStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotAnObjectWithDebugInfo(): void @@ -49,7 +49,7 @@ public function itShouldStringifyRawValueWhenItIsAnObjectWithDebugInfo(): void $actual = $sut->stringify($raw, self::DEPTH); $expected = $quoter->quote( sprintf('%s { __debugInfo() => %s }', WithDebugInfo::class, $string), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); diff --git a/tests/unit/Stringifiers/ResourceStringifierTest.php b/tests/unit/Stringifiers/ResourceStringifierTest.php index 0a4901f..91a26f9 100644 --- a/tests/unit/Stringifiers/ResourceStringifierTest.php +++ b/tests/unit/Stringifiers/ResourceStringifierTest.php @@ -21,7 +21,7 @@ #[CoversClass(ResourceStringifier::class)] final class ResourceStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotOfTypeResource(): void diff --git a/tests/unit/Stringifiers/StringableObjectStringifierTest.php b/tests/unit/Stringifiers/StringableObjectStringifierTest.php index 039c5a4..ff2228c 100644 --- a/tests/unit/Stringifiers/StringableObjectStringifierTest.php +++ b/tests/unit/Stringifiers/StringableObjectStringifierTest.php @@ -24,7 +24,7 @@ #[CoversClass(StringableObjectStringifier::class)] final class StringableObjectStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function itShouldNotStringifyRawValueWhenItIsNotAnInstanceOfStringable(): void @@ -49,7 +49,7 @@ public function itShouldStringifyRawValueWhenItIsAnInstanceOfStringable(): void $actual = $sut->stringify($raw, self::DEPTH); $expected = $quoter->quote( sprintf('%s { __toString() => %s }', ConcreteStringable::class, $string), - self::DEPTH + self::DEPTH, ); self::assertSame($expected, $actual); diff --git a/tests/unit/Stringifiers/ThrowableObjectStringifierTest.php b/tests/unit/Stringifiers/ThrowableObjectStringifierTest.php index 896d525..4758cdb 100644 --- a/tests/unit/Stringifiers/ThrowableObjectStringifierTest.php +++ b/tests/unit/Stringifiers/ThrowableObjectStringifierTest.php @@ -32,7 +32,7 @@ #[CoversClass(ThrowableObjectStringifier::class)] final class ThrowableObjectStringifierTest extends TestCase { - private const DEPTH = 0; + private const int DEPTH = 0; #[Test] public function isShouldNotStringifyRawValueWhenItIsNotThrowable(): void @@ -59,7 +59,7 @@ public function itShouldStringifyRawValueWhenItIsThrowableWithMessage(Throwable $stringifier->stringify($raw->getMessage(), self::DEPTH + 1), $raw->getLine(), ), - self::DEPTH + self::DEPTH, ); self::assertSame($expectedValue, $actual); @@ -81,15 +81,13 @@ public function itShouldStringifyRawValueWhenItIsThrowableWithoutMessage(Throwab $raw::class, $raw->getLine(), ), - self::DEPTH + self::DEPTH, ); self::assertSame($expectedValue, $actual); } - /** - * @return array - */ + /** @return array */ public static function throwableWithMessageProvider(): array { return [ @@ -100,9 +98,7 @@ public static function throwableWithMessageProvider(): array ]; } - /** - * @return array - */ + /** @return array */ public static function throwableWithoutMessageProvider(): array { return [