diff --git a/CHANGELOG.md b/CHANGELOG.md index 00360330..3570a701 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ For a full diff see [`1.0.3...main`][1.0.3...main]. - Started using the `SchemaValidator` provided by `ergebnis/json-schema-validator` ([#595]), by [@localheinz] - Renamed `Format\JsonEncodeOptions::value()` to `Format\JsonEncodeOptions::toInt()` ([#603]), by [@localheinz] - Extracted `Format\Format::create()` as named constructor and reduced visibility of `__construct` to `private` ([#608]), by [@localheinz] +- Stopped composing `Format\Format` into `Json` ([#616]), by [@localheinz] ### Fixed @@ -438,6 +439,7 @@ For a full diff see [`5d8b3e2...0.1.0`][5d8b3e2...0.1.0]. [#597]: https://github.com/ergebnis/json-normalizer/pull/597 [#603]: https://github.com/ergebnis/json-normalizer/pull/603 [#608]: https://github.com/ergebnis/json-normalizer/pull/608 +[#616]: https://github.com/ergebnis/json-normalizer/pull/616 [@BackEndTea]: https://github.com/BackEndTea [@dependabot]: https://github.com/dependabot diff --git a/src/AutoFormatNormalizer.php b/src/AutoFormatNormalizer.php index dfa17872..04c5ce96 100644 --- a/src/AutoFormatNormalizer.php +++ b/src/AutoFormatNormalizer.php @@ -28,9 +28,11 @@ public function __construct( public function normalize(Json $json): Json { + $format = Format\Format::fromJson($json); + return $this->formatter->format( $this->normalizer->normalize($json), - $json->format(), + $format, ); } } diff --git a/src/Json.php b/src/Json.php index 22b73199..15b3cb54 100644 --- a/src/Json.php +++ b/src/Json.php @@ -24,7 +24,6 @@ final class Json * @var null|array|bool|float|int|\stdClass|string */ private $decoded; - private Format\Format $format; private function __construct( string $encoded, @@ -32,7 +31,6 @@ private function __construct( ) { $this->encoded = $encoded; $this->decoded = $decoded; - $this->format = Format\Format::fromJson($this); } /** @@ -75,14 +73,6 @@ public function encoded(): string return $this->encoded; } - /** - * Returns the format of the original JSON value. - */ - public function format(): Format\Format - { - return $this->format; - } - /** * Returns the original JSON value. */ diff --git a/test/Unit/AutoFormatNormalizerTest.php b/test/Unit/AutoFormatNormalizerTest.php index 3611fa73..233fb802 100644 --- a/test/Unit/AutoFormatNormalizerTest.php +++ b/test/Unit/AutoFormatNormalizerTest.php @@ -72,7 +72,7 @@ public function testNormalizeNormalizesAndFormatsUsingJsonFormat(): void ->method('format') ->with( self::identicalTo($normalized), - self::identicalTo($json->format()), + self::equalTo(Format\Format::fromJson($json)), ) ->willReturn($formatted); diff --git a/test/Unit/CallableNormalizerTest.php b/test/Unit/CallableNormalizerTest.php index 354dcd58..2cc610b9 100644 --- a/test/Unit/CallableNormalizerTest.php +++ b/test/Unit/CallableNormalizerTest.php @@ -21,10 +21,6 @@ * * @covers \Ergebnis\Json\Normalizer\CallableNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class CallableNormalizerTest extends AbstractNormalizerTestCase diff --git a/test/Unit/ChainNormalizerTest.php b/test/Unit/ChainNormalizerTest.php index 893524e8..a14a73de 100644 --- a/test/Unit/ChainNormalizerTest.php +++ b/test/Unit/ChainNormalizerTest.php @@ -22,10 +22,6 @@ * * @covers \Ergebnis\Json\Normalizer\ChainNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class ChainNormalizerTest extends AbstractNormalizerTestCase diff --git a/test/Unit/FinalNewLineNormalizerTest.php b/test/Unit/FinalNewLineNormalizerTest.php index f20f73e3..9f09f76f 100644 --- a/test/Unit/FinalNewLineNormalizerTest.php +++ b/test/Unit/FinalNewLineNormalizerTest.php @@ -21,10 +21,6 @@ * * @covers \Ergebnis\Json\Normalizer\FinalNewLineNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class FinalNewLineNormalizerTest extends AbstractNormalizerTestCase diff --git a/test/Unit/Format/IndentTest.php b/test/Unit/Format/IndentTest.php index 1b2089a5..5dd4c6b7 100644 --- a/test/Unit/Format/IndentTest.php +++ b/test/Unit/Format/IndentTest.php @@ -27,9 +27,6 @@ * @uses \Ergebnis\Json\Normalizer\Exception\InvalidIndentSizeException * @uses \Ergebnis\Json\Normalizer\Exception\InvalidIndentStringException * @uses \Ergebnis\Json\Normalizer\Exception\InvalidIndentStyleException - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class IndentTest extends Framework\TestCase diff --git a/test/Unit/Format/JsonEncodeOptionsTest.php b/test/Unit/Format/JsonEncodeOptionsTest.php index 3867d8b1..3825b5d6 100644 --- a/test/Unit/Format/JsonEncodeOptionsTest.php +++ b/test/Unit/Format/JsonEncodeOptionsTest.php @@ -25,10 +25,6 @@ * @covers \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions * * @uses \Ergebnis\Json\Normalizer\Exception\InvalidJsonEncodeOptionsException - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class JsonEncodeOptionsTest extends Framework\TestCase diff --git a/test/Unit/Format/NewLineTest.php b/test/Unit/Format/NewLineTest.php index b25d50fe..44ef635b 100644 --- a/test/Unit/Format/NewLineTest.php +++ b/test/Unit/Format/NewLineTest.php @@ -24,10 +24,6 @@ * @covers \Ergebnis\Json\Normalizer\Format\NewLine * * @uses \Ergebnis\Json\Normalizer\Exception\InvalidNewLineStringException - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class NewLineTest extends Framework\TestCase diff --git a/test/Unit/IndentNormalizerTest.php b/test/Unit/IndentNormalizerTest.php index 6f7294fd..f4e342a9 100644 --- a/test/Unit/IndentNormalizerTest.php +++ b/test/Unit/IndentNormalizerTest.php @@ -23,10 +23,7 @@ * * @covers \Ergebnis\Json\Normalizer\IndentNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class IndentNormalizerTest extends AbstractNormalizerTestCase diff --git a/test/Unit/JsonEncodeNormalizerTest.php b/test/Unit/JsonEncodeNormalizerTest.php index 608f7393..5a570584 100644 --- a/test/Unit/JsonEncodeNormalizerTest.php +++ b/test/Unit/JsonEncodeNormalizerTest.php @@ -22,10 +22,7 @@ * * @covers \Ergebnis\Json\Normalizer\JsonEncodeNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class JsonEncodeNormalizerTest extends AbstractNormalizerTestCase diff --git a/test/Unit/JsonTest.php b/test/Unit/JsonTest.php index 6725e1d6..c1c2f809 100644 --- a/test/Unit/JsonTest.php +++ b/test/Unit/JsonTest.php @@ -14,7 +14,6 @@ namespace Ergebnis\Json\Normalizer\Test\Unit; use Ergebnis\Json\Normalizer\Exception; -use Ergebnis\Json\Normalizer\Format; use Ergebnis\Json\Normalizer\Json; use Ergebnis\Json\Normalizer\Test; use PHPUnit\Framework; @@ -25,10 +24,6 @@ * @covers \Ergebnis\Json\Normalizer\Json * * @uses \Ergebnis\Json\Normalizer\Exception\InvalidJsonEncodedException - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine */ final class JsonTest extends Framework\TestCase { @@ -53,10 +48,6 @@ public function testFromEncodedReturnsJson(string $encoded): void self::assertSame($encoded, $json->toString()); self::assertSame($encoded, $json->encoded()); self::assertSame($encoded, \json_encode($json->decoded())); - - $format = Format\Format::fromJson($json); - - self::assertEquals($format, $json->format()); } /** diff --git a/test/Unit/NoFinalNewLineNormalizerTest.php b/test/Unit/NoFinalNewLineNormalizerTest.php index 345343d9..49a64c01 100644 --- a/test/Unit/NoFinalNewLineNormalizerTest.php +++ b/test/Unit/NoFinalNewLineNormalizerTest.php @@ -21,10 +21,6 @@ * * @covers \Ergebnis\Json\Normalizer\NoFinalNewLineNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class NoFinalNewLineNormalizerTest extends AbstractNormalizerTestCase diff --git a/test/Unit/SchemaNormalizerTest.php b/test/Unit/SchemaNormalizerTest.php index 23248470..31cb60ce 100644 --- a/test/Unit/SchemaNormalizerTest.php +++ b/test/Unit/SchemaNormalizerTest.php @@ -34,10 +34,6 @@ * @uses \Ergebnis\Json\Normalizer\Exception\SchemaUriCouldNotBeResolvedException * @uses \Ergebnis\Json\Normalizer\Exception\SchemaUriReferencesDocumentWithInvalidMediaTypeException * @uses \Ergebnis\Json\Normalizer\Exception\SchemaUriReferencesInvalidJsonDocumentException - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class SchemaNormalizerTest extends AbstractNormalizerTestCase diff --git a/test/Unit/Vendor/Composer/BinNormalizerTest.php b/test/Unit/Vendor/Composer/BinNormalizerTest.php index 00d3e6d6..a63f660d 100644 --- a/test/Unit/Vendor/Composer/BinNormalizerTest.php +++ b/test/Unit/Vendor/Composer/BinNormalizerTest.php @@ -21,10 +21,6 @@ * * @covers \Ergebnis\Json\Normalizer\Vendor\Composer\BinNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class BinNormalizerTest extends AbstractComposerTestCase diff --git a/test/Unit/Vendor/Composer/ComposerJsonNormalizerTest.php b/test/Unit/Vendor/Composer/ComposerJsonNormalizerTest.php index 7b70b0ee..133fba83 100644 --- a/test/Unit/Vendor/Composer/ComposerJsonNormalizerTest.php +++ b/test/Unit/Vendor/Composer/ComposerJsonNormalizerTest.php @@ -25,10 +25,6 @@ * @covers \Ergebnis\Json\Normalizer\Vendor\Composer\ComposerJsonNormalizer * * @uses \Ergebnis\Json\Normalizer\ChainNormalizer - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json * @uses \Ergebnis\Json\Normalizer\SchemaNormalizer * @uses \Ergebnis\Json\Normalizer\Vendor\Composer\BinNormalizer diff --git a/test/Unit/Vendor/Composer/ConfigHashNormalizerTest.php b/test/Unit/Vendor/Composer/ConfigHashNormalizerTest.php index e7217f9f..886c4b45 100644 --- a/test/Unit/Vendor/Composer/ConfigHashNormalizerTest.php +++ b/test/Unit/Vendor/Composer/ConfigHashNormalizerTest.php @@ -21,10 +21,6 @@ * * @covers \Ergebnis\Json\Normalizer\Vendor\Composer\ConfigHashNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class ConfigHashNormalizerTest extends AbstractComposerTestCase diff --git a/test/Unit/Vendor/Composer/PackageHashNormalizerTest.php b/test/Unit/Vendor/Composer/PackageHashNormalizerTest.php index 7de53b7e..96b24605 100644 --- a/test/Unit/Vendor/Composer/PackageHashNormalizerTest.php +++ b/test/Unit/Vendor/Composer/PackageHashNormalizerTest.php @@ -21,10 +21,6 @@ * * @covers \Ergebnis\Json\Normalizer\Vendor\Composer\PackageHashNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class PackageHashNormalizerTest extends AbstractComposerTestCase diff --git a/test/Unit/Vendor/Composer/VersionConstraintNormalizerTest.php b/test/Unit/Vendor/Composer/VersionConstraintNormalizerTest.php index e91f760e..c8214830 100644 --- a/test/Unit/Vendor/Composer/VersionConstraintNormalizerTest.php +++ b/test/Unit/Vendor/Composer/VersionConstraintNormalizerTest.php @@ -21,10 +21,6 @@ * * @covers \Ergebnis\Json\Normalizer\Vendor\Composer\VersionConstraintNormalizer * - * @uses \Ergebnis\Json\Normalizer\Format\Format - * @uses \Ergebnis\Json\Normalizer\Format\Indent - * @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions - * @uses \Ergebnis\Json\Normalizer\Format\NewLine * @uses \Ergebnis\Json\Normalizer\Json */ final class VersionConstraintNormalizerTest extends AbstractComposerTestCase