diff --git a/composer.json b/composer.json index 5b6ef78..09352ac 100644 --- a/composer.json +++ b/composer.json @@ -17,11 +17,11 @@ "symfony/http-kernel": "^7.2" }, "require-dev": { - "21torr/janus": "^1.4", - "bamarni/composer-bin-plugin": "^1.8", + "21torr/janus": "^1.5.1", + "bamarni/composer-bin-plugin": "^1.8.2", "doctrine/common": "^3.5", - "roave/security-advisories": "dev-latest", - "phpunit/phpunit": "^12.2.5" + "phpunit/phpunit": "^12.2.5", + "roave/security-advisories": "dev-latest" }, "autoload": { "psr-4": { @@ -35,6 +35,7 @@ }, "config": { "allow-plugins": { + "21torr/janus": true, "bamarni/composer-bin-plugin": true }, "sort-packages": true @@ -48,11 +49,11 @@ "scripts": { "fix-lint": [ "@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --ansi", - "vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi" + "PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi" ], "lint": [ "@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --dry-run --ansi", - "vendor-bin/cs-fixer/vendor/bin/php-cs-fixer check --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi" + "PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/cs-fixer/vendor/bin/php-cs-fixer check --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi" ], "test": [ "phpunit", diff --git a/phpstan.neon b/phpstan.neon index 2300f7d..b567413 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,2 +1,14 @@ includes: - vendor/21torr/janus/phpstan/lib.neon + +parameters: + +# These are temporarily copied here, as normally they should be in the lib.neon of janus. +# However, due to a bug in PHPStan, this currently doesn't work (https://github.com/phpstan/phpstan/issues/12844) + excludePaths: + analyse: + - vendor + analyseAndScan: + - node_modules (?) + - var (?) + - vendor-bin diff --git a/src/Normalizer/SimpleNormalizer.php b/src/Normalizer/SimpleNormalizer.php index 2e71627..61c1d70 100644 --- a/src/Normalizer/SimpleNormalizer.php +++ b/src/Normalizer/SimpleNormalizer.php @@ -18,6 +18,7 @@ * = the object normalizers), as this way we can provide a full path to the invalid element in the JSON. * * @readonly + * * @final */ class SimpleNormalizer @@ -44,6 +45,7 @@ public function normalize (mixed $value, array $context = []) : mixed return $normalizedValue; } + /** */ public function normalizeArray (array $array, array $context = []) : array @@ -75,8 +77,6 @@ public function normalizeMap (array $array, array $context = []) : array|\stdCla return $normalizedValue; } - - /** * The actual normalize logic, that recursively normalizes the value. * It must never call one of the public methods above and just normalizes the value. diff --git a/src/Normalizer/Validator/ValidJsonVerifier.php b/src/Normalizer/Validator/ValidJsonVerifier.php index 1b4c346..9fcc0bd 100644 --- a/src/Normalizer/Validator/ValidJsonVerifier.php +++ b/src/Normalizer/Validator/ValidJsonVerifier.php @@ -21,7 +21,7 @@ public function ensureValidOnlyJsonTypes (mixed $value) : void if (null !== $invalidElement) { throw new IncompleteNormalizationException( - sprintf( + \sprintf( "Found a JSON-incompatible value when normalizing. Found '%s' at path '%s', but expected only scalars, arrays and empty objects.", get_debug_type($invalidElement->value), implode(".", $invalidElement->path), @@ -30,12 +30,11 @@ public function ensureValidOnlyJsonTypes (mixed $value) : void } } - /** * Searches through the value and looks for anything that isn't valid JSON * (scalars, arrays or empty objects). * - * @return InvalidJsonElement|null Returns null if everything is valid, otherwise the invalid value. + * @return InvalidJsonElement|null returns null if everything is valid, otherwise the invalid value */ private function findInvalidJsonElement (mixed $value, array $path = ["$"]) : ?InvalidJsonElement { @@ -46,14 +45,14 @@ private function findInvalidJsonElement (mixed $value, array $path = ["$"]) : ?I } // only empty stdClass objects are allowed (as they are used to serialize to `{}`) - if (is_object($value)) + if (\is_object($value)) { return $value instanceof \stdClass && [] === get_object_vars($value) ? null : new InvalidJsonElement($value, $path); } - if (is_array($value)) + if (\is_array($value)) { foreach ($value as $key => $item) { diff --git a/tests/Normalizer/SimpleNormalizerTest.php b/tests/Normalizer/SimpleNormalizerTest.php index 3ee28cf..d2043b3 100644 --- a/tests/Normalizer/SimpleNormalizerTest.php +++ b/tests/Normalizer/SimpleNormalizerTest.php @@ -3,15 +3,18 @@ namespace Tests\Torr\SimpleNormalizer\Normalizer; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ServiceLocator; use Tests\Torr\SimpleNormalizer\Fixture\DummyVO; use Torr\SimpleNormalizer\Exception\IncompleteNormalizationException; use Torr\SimpleNormalizer\Normalizer\SimpleNormalizer; -use PHPUnit\Framework\TestCase; use Torr\SimpleNormalizer\Normalizer\SimpleObjectNormalizerInterface; use Torr\SimpleNormalizer\Normalizer\Validator\ValidJsonVerifier; -class SimpleNormalizerTest extends TestCase +/** + * @internal + */ +final class SimpleNormalizerTest extends TestCase { /** * @@ -40,7 +43,7 @@ public function testJsonVerifierEnabled (callable $call) : void $verifier = $this->createMock(ValidJsonVerifier::class); $verifier - ->expects($this->once()) + ->expects(self::once()) ->method('ensureValidOnlyJsonTypes'); $normalizer = new SimpleNormalizer( @@ -59,7 +62,6 @@ public function testJsonVerifierEnabled (callable $call) : void ]); } - /** * */ @@ -68,7 +70,7 @@ public function testJsonVerifierDisabled () : void $verifier = $this->createMock(ValidJsonVerifier::class); $verifier - ->expects($this->never()) + ->expects(self::never()) ->method('ensureValidOnlyJsonTypes'); $normalizer = new SimpleNormalizer( @@ -83,7 +85,6 @@ public function testJsonVerifierDisabled () : void self::assertTrue(true); // Just to ensure the test runs without exceptions } - /** * */ @@ -100,7 +101,6 @@ public function testInvalidNormalizer () : void $normalizer->normalize(new DummyVO(42)); } - /** * */ @@ -124,15 +124,13 @@ public function testInvalidNestedNormalizer () : void ]); } - /** - * + * @return ServiceLocator */ private function createNormalizerObjectNormalizers (mixed $returnValue) : ServiceLocator { return new ServiceLocator([ - DummyVO::class => static fn () => new readonly class ($returnValue) implements SimpleObjectNormalizerInterface - { + DummyVO::class => static fn () => new readonly class($returnValue) implements SimpleObjectNormalizerInterface { public function __construct ( private mixed $returnValue, ) {} diff --git a/vendor-bin/c-norm/composer.json b/vendor-bin/c-norm/composer.json index 29d96fe..43031c1 100644 --- a/vendor-bin/c-norm/composer.json +++ b/vendor-bin/c-norm/composer.json @@ -1,6 +1,6 @@ { "require-dev": { - "ergebnis/composer-normalize": "^2.42", + "ergebnis/composer-normalize": "^2.47", "roave/security-advisories": "dev-latest" }, "config": { diff --git a/vendor-bin/cs-fixer/composer.json b/vendor-bin/cs-fixer/composer.json index ceadfce..42e20ab 100644 --- a/vendor-bin/cs-fixer/composer.json +++ b/vendor-bin/cs-fixer/composer.json @@ -1,6 +1,6 @@ { "require-dev": { - "21torr/php-cs-fixer": "^1.1.1", + "21torr/php-cs-fixer": "^1.1.5", "roave/security-advisories": "dev-latest" } } diff --git a/vendor-bin/phpstan/composer.json b/vendor-bin/phpstan/composer.json index cf165ff..4eb9387 100644 --- a/vendor-bin/phpstan/composer.json +++ b/vendor-bin/phpstan/composer.json @@ -3,14 +3,14 @@ "php": "^8.3" }, "require-dev": { - "phpstan/extension-installer": "^1.3.1", - "phpstan/phpstan": "^1.11", - "phpstan/phpstan-deprecation-rules": "^1.2", - "phpstan/phpstan-doctrine": "^1.4", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/phpstan-symfony": "^1.4", + "phpstan/extension-installer": "^1.4.2", + "phpstan/phpstan": "^2.1.11", + "phpstan/phpstan-deprecation-rules": "^2.0.1", + "phpstan/phpstan-doctrine": "^2.0.2", + "phpstan/phpstan-phpunit": "^2.0.6", + "phpstan/phpstan-symfony": "^2.0.4", "roave/security-advisories": "dev-latest", - "staabm/phpstan-todo-by": "^0.1.25" + "staabm/phpstan-todo-by": "^0.2" }, "config": { "sort-packages": true,