diff --git a/CHANGELOG.md b/CHANGELOG.md index 59a1ea52..920f78b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ For a full diff see [`2.29.0...main`][2.29.0...main]. - Started injecting `Printer\Printer` instead of `Formatter\Formatter` into `NormalizeCommand` ([#1008]), by [@ergebnis-bot] - Required `composer/composer:2.5.1` for compiling `composer-normalize.phar` ([#1020]), by [@localheinz] +- Required `ergebnis/json-normalizer:^4.0.0` ([#1056]), by [@dependabot] ## [`2.29.0`][2.29.0] @@ -1000,6 +1001,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0]. [#1004]: https://github.com/ergebnis/composer-normalize/pull/1004 [#1008]: https://github.com/ergebnis/composer-normalize/pull/1008 [#1020]: https://github.com/ergebnis/composer-normalize/pull/1020 +[#1056]: https://github.com/ergebnis/composer-normalize/pull/1056 [@core23]: https://github.com/core23 [@dependabot]: https://github.com/dependabot diff --git a/composer.json b/composer.json index 975fdcf5..789da867 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "php": "~8.0.0 || ~8.1.0 || ~8.2.0", "ext-json": "*", "composer-plugin-api": "^2.0.0", - "ergebnis/json-normalizer": "~2.1.0", + "ergebnis/json": "^1.0.1", + "ergebnis/json-normalizer": "~4.0.0", "ergebnis/json-printer": "^3.3.0", "justinrainbow/json-schema": "^5.2.12", "localheinz/diff": "^1.1.1" diff --git a/composer.lock b/composer.lock index 9dc75eac..6345b627 100644 --- a/composer.lock +++ b/composer.lock @@ -4,38 +4,109 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "232b9e12f3d806298f74bb0f096f7312", + "content-hash": "885efe85f15f37dd2b7982d6d0eb444d", "packages": [ + { + "name": "ergebnis/json", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/ergebnis/json.git", + "reference": "d66ea30060856d0729a4aa319a02752519ca63a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ergebnis/json/zipball/d66ea30060856d0729a4aa319a02752519ca63a0", + "reference": "d66ea30060856d0729a4aa319a02752519ca63a0", + "shasum": "" + }, + "require": { + "php": "^8.0" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.29.0", + "ergebnis/data-provider": "^1.2.0", + "ergebnis/license": "^2.1.0", + "ergebnis/php-cs-fixer-config": "^5.0.0", + "ergebnis/phpstan-rules": "^1.0.0", + "fakerphp/faker": "^1.20.0", + "infection/infection": "~0.26.16", + "phpunit/phpunit": "^9.5.27", + "psalm/plugin-phpunit": "~0.18.4", + "vimeo/psalm": "^5.1.0" + }, + "type": "library", + "extra": { + "composer-normalize": { + "indent-size": 2, + "indent-style": "space" + } + }, + "autoload": { + "psr-4": { + "Ergebnis\\Json\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Andreas Möller", + "email": "am@localheinz.com" + } + ], + "description": "Provides a Json value object for representing a valid JSON string.", + "homepage": "https://github.com/ergebnis/json", + "keywords": [ + "json" + ], + "support": { + "issues": "https://github.com/ergebnis/json/issues", + "source": "https://github.com/ergebnis/json" + }, + "time": "2022-12-10T22:38:50+00:00" + }, { "name": "ergebnis/json-normalizer", - "version": "2.1.0", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/ergebnis/json-normalizer.git", - "reference": "2039eb11131a243b9204bf51219baa08935e6b1d" + "reference": "250f41057e1e62662c076d9c133fe487760c0c2d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ergebnis/json-normalizer/zipball/2039eb11131a243b9204bf51219baa08935e6b1d", - "reference": "2039eb11131a243b9204bf51219baa08935e6b1d", + "url": "https://api.github.com/repos/ergebnis/json-normalizer/zipball/250f41057e1e62662c076d9c133fe487760c0c2d", + "reference": "250f41057e1e62662c076d9c133fe487760c0c2d", "shasum": "" }, "require": { - "ergebnis/json-printer": "^3.2.0", - "ergebnis/json-schema-validator": "^2.0.0", + "ergebnis/json": "^1.0.1", + "ergebnis/json-pointer": "^3.2.0", + "ergebnis/json-printer": "^3.3.0", + "ergebnis/json-schema-validator": "^4.0.0", "ext-json": "*", - "justinrainbow/json-schema": "^5.2.11", - "php": "^7.4 || ^8.0" + "justinrainbow/json-schema": "^5.2.12", + "php": "~8.0.0 || ~8.1.0 || ~8.2.0" }, "require-dev": { - "ergebnis/data-provider": "^1.0.0", - "ergebnis/license": "^1.2.0", - "ergebnis/php-cs-fixer-config": "^3.4.0", - "fakerphp/faker": "^1.17.0", - "infection/infection": "~0.25.5", - "phpunit/phpunit": "^9.5.11", - "psalm/plugin-phpunit": "~0.16.1", - "vimeo/psalm": "^4.17.0" + "composer/semver": "^3.2.1", + "ergebnis/data-provider": "^1.3.0", + "ergebnis/license": "^2.1.0", + "ergebnis/php-cs-fixer-config": "^5.3.1", + "fakerphp/faker": "^1.21.0", + "infection/infection": "~0.26.19", + "phpunit/phpunit": "^9.6.3", + "psalm/plugin-phpunit": "~0.18.4", + "rector/rector": "~0.15.18", + "symfony/filesystem": "^6.0.19", + "symfony/finder": "^6.0.19", + "vimeo/psalm": "^5.7.7" + }, + "suggest": { + "composer/semver": "If you want to use ComposerJsonNormalizer or VersionConstraintNormalizer" }, "type": "library", "autoload": { @@ -63,13 +134,70 @@ "issues": "https://github.com/ergebnis/json-normalizer/issues", "source": "https://github.com/ergebnis/json-normalizer" }, - "funding": [ + "time": "2023-02-26T10:58:43+00:00" + }, + { + "name": "ergebnis/json-pointer", + "version": "3.2.0", + "source": { + "type": "git", + "url": "https://github.com/ergebnis/json-pointer.git", + "reference": "861516ff5afa1aa8905fdf3361315909523a1bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ergebnis/json-pointer/zipball/861516ff5afa1aa8905fdf3361315909523a1bf8", + "reference": "861516ff5afa1aa8905fdf3361315909523a1bf8", + "shasum": "" + }, + "require": { + "php": "^8.0" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.28.3", + "ergebnis/data-provider": "^1.2.0", + "ergebnis/license": "^2.1.0", + "ergebnis/php-cs-fixer-config": "^5.0.0", + "fakerphp/faker": "^1.20.0", + "infection/infection": "~0.26.16", + "phpunit/phpunit": "^9.5.26", + "psalm/plugin-phpunit": "~0.18.3", + "vimeo/psalm": "^4.30" + }, + "type": "library", + "extra": { + "composer-normalize": { + "indent-size": 2, + "indent-style": "space" + } + }, + "autoload": { + "psr-4": { + "Ergebnis\\Json\\Pointer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ { - "url": "https://github.com/localheinz", - "type": "github" + "name": "Andreas Möller", + "email": "am@localheinz.com" } ], - "time": "2022-01-04T11:19:55+00:00" + "description": "Provides JSON pointer as a value object.", + "homepage": "https://github.com/ergebnis/json-pointer", + "keywords": [ + "RFC6901", + "json", + "pointer" + ], + "support": { + "issues": "https://github.com/ergebnis/json-pointer/issues", + "source": "https://github.com/ergebnis/json-pointer" + }, + "time": "2022-11-28T17:03:31+00:00" }, { "name": "ergebnis/json-printer", @@ -130,33 +258,35 @@ }, { "name": "ergebnis/json-schema-validator", - "version": "2.0.0", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/ergebnis/json-schema-validator.git", - "reference": "dacd8a47c1cc2c426ec71e952da3609ebe901fac" + "reference": "a6166272ac5691a9bc791f185841e5f92a6d4723" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ergebnis/json-schema-validator/zipball/dacd8a47c1cc2c426ec71e952da3609ebe901fac", - "reference": "dacd8a47c1cc2c426ec71e952da3609ebe901fac", + "url": "https://api.github.com/repos/ergebnis/json-schema-validator/zipball/a6166272ac5691a9bc791f185841e5f92a6d4723", + "reference": "a6166272ac5691a9bc791f185841e5f92a6d4723", "shasum": "" }, "require": { + "ergebnis/json": "^1.0.0", + "ergebnis/json-pointer": "^3.2.0", "ext-json": "*", - "justinrainbow/json-schema": "^5.2.10", - "php": "^7.4 || ^8.0" + "justinrainbow/json-schema": "^5.2.12", + "php": "^8.0" }, "require-dev": { - "ergebnis/composer-normalize": "^2.18.0", - "ergebnis/data-provider": "^1.0.0", - "ergebnis/license": "^1.1.0", - "ergebnis/php-cs-fixer-config": "~3.4.0", - "fakerphp/faker": "^1.17.0", - "infection/infection": "~0.25.3", - "phpunit/phpunit": "~9.5.10", - "psalm/plugin-phpunit": "~0.16.1", - "vimeo/psalm": "^4.15.0" + "ergebnis/composer-normalize": "^2.21.0", + "ergebnis/data-provider": "^1.2.0", + "ergebnis/license": "^2.1.0", + "ergebnis/php-cs-fixer-config": "~5.0.0", + "fakerphp/faker": "^1.20.0", + "infection/infection": "~0.26.16", + "phpunit/phpunit": "~9.5.27", + "psalm/plugin-phpunit": "~0.18.4", + "vimeo/psalm": "^5.1.0" }, "type": "library", "extra": { @@ -191,13 +321,7 @@ "issues": "https://github.com/ergebnis/json-schema-validator/issues", "source": "https://github.com/ergebnis/json-schema-validator" }, - "funding": [ - { - "url": "https://github.com/localheinz", - "type": "github" - } - ], - "time": "2021-12-13T16:54:56+00:00" + "time": "2022-12-10T14:50:15+00:00" }, { "name": "justinrainbow/json-schema", diff --git a/src/Command/NormalizeCommand.php b/src/Command/NormalizeCommand.php index 82de6440..8c5b640b 100644 --- a/src/Command/NormalizeCommand.php +++ b/src/Command/NormalizeCommand.php @@ -20,6 +20,7 @@ use Composer\IO; use Ergebnis\Composer\Normalize\Exception; use Ergebnis\Composer\Normalize\Version; +use Ergebnis\Json\Json; use Ergebnis\Json\Normalizer; use Ergebnis\Json\Printer; use Localheinz\Diff; @@ -32,7 +33,7 @@ final class NormalizeCommand extends Command\BaseCommand { public function __construct( private Factory $factory, - private Normalizer\NormalizerInterface $normalizer, + private Normalizer\Normalizer $normalizer, private Printer\PrinterInterface $printer, private Diff\Differ $differ, ) { @@ -185,7 +186,7 @@ protected function execute( /** @var string $encoded */ $encoded = \file_get_contents($composerFile); - $json = Normalizer\Json::fromEncoded($encoded); + $json = Json::fromString($encoded); $format = Normalizer\Format\Format::fromJson($json); @@ -195,14 +196,14 @@ protected function execute( $normalizer = new Normalizer\ChainNormalizer( $this->normalizer, - new class($this->printer, $format) implements Normalizer\NormalizerInterface { + new class($this->printer, $format) implements Normalizer\Normalizer { public function __construct( private Printer\PrinterInterface $printer, private Normalizer\Format\Format $format, ) { } - public function normalize(Normalizer\Json $json): Normalizer\Json + public function normalize(Json $json): Json { $encoded = \json_encode( $json->decoded(), @@ -216,17 +217,17 @@ public function normalize(Normalizer\Json $json): Normalizer\Json ); if (!$this->format->hasFinalNewLine()) { - return Normalizer\Json::fromEncoded($printed); + return Json::fromString($printed); } - return Normalizer\Json::fromEncoded($printed . $this->format->newLine()->toString()); + return Json::fromString($printed . $this->format->newLine()->toString()); } }, ); try { $normalized = $normalizer->normalize($json); - } catch (Normalizer\Exception\OriginalInvalidAccordingToSchemaException $exception) { + } catch (Normalizer\Exception\OriginalInvalidAccordingToSchema $exception) { $io->writeError('Original composer.json does not match the expected JSON schema:'); self::showValidationErrors( @@ -235,7 +236,7 @@ public function normalize(Normalizer\Json $json): Normalizer\Json ); return 1; - } catch (Normalizer\Exception\NormalizedInvalidAccordingToSchemaException $exception) { + } catch (Normalizer\Exception\NormalizedInvalidAccordingToSchema $exception) { $io->writeError('Normalized composer.json does not match the expected JSON schema:'); self::showValidationErrors( diff --git a/test/Integration/Command/NormalizeCommand/Normalizer/Throws/Test.php b/test/Integration/Command/NormalizeCommand/Normalizer/Throws/Test.php index 604c70ac..de01e114 100644 --- a/test/Integration/Command/NormalizeCommand/Normalizer/Throws/Test.php +++ b/test/Integration/Command/NormalizeCommand/Normalizer/Throws/Test.php @@ -17,6 +17,7 @@ use Ergebnis\Composer\Normalize\Command\NormalizeCommand; use Ergebnis\Composer\Normalize\Test\Integration; use Ergebnis\Composer\Normalize\Test\Util; +use Ergebnis\Json\Json; use Ergebnis\Json\Normalizer; use Ergebnis\Json\Printer; use Localheinz\Diff; @@ -51,12 +52,12 @@ public function testFailsWhenNormalizerThrowsRuntimeExceptionDuringNormalization $application = self::createApplication(new NormalizeCommand( new Factory(), - new class($exceptionMessage) implements Normalizer\NormalizerInterface { + new class($exceptionMessage) implements Normalizer\Normalizer { public function __construct(private string $exceptionMessage) { } - public function normalize(Normalizer\Json $json): Normalizer\Json + public function normalize(Json $json): Json { throw new \RuntimeException($this->exceptionMessage); }