Skip to content

Commit a8203cb

Browse files
authored
Merge pull request #616 from ergebnis/fix/format
Fix: Do not compose `Format` into `Json`
2 parents aa0e189 + ff7f69a commit a8203cb

20 files changed

Lines changed: 6 additions & 78 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ For a full diff see [`1.0.3...main`][1.0.3...main].
1616
- Started using the `SchemaValidator` provided by `ergebnis/json-schema-validator` ([#595]), by [@localheinz]
1717
- Renamed `Format\JsonEncodeOptions::value()` to `Format\JsonEncodeOptions::toInt()` ([#603]), by [@localheinz]
1818
- Extracted `Format\Format::create()` as named constructor and reduced visibility of `__construct` to `private` ([#608]), by [@localheinz]
19+
- Stopped composing `Format\Format` into `Json` ([#616]), by [@localheinz]
1920

2021
### Fixed
2122

@@ -438,6 +439,7 @@ For a full diff see [`5d8b3e2...0.1.0`][5d8b3e2...0.1.0].
438439
[#597]: https://github.com/ergebnis/json-normalizer/pull/597
439440
[#603]: https://github.com/ergebnis/json-normalizer/pull/603
440441
[#608]: https://github.com/ergebnis/json-normalizer/pull/608
442+
[#616]: https://github.com/ergebnis/json-normalizer/pull/616
441443

442444
[@BackEndTea]: https://github.com/BackEndTea
443445
[@dependabot]: https://github.com/dependabot

src/AutoFormatNormalizer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public function __construct(
2828

2929
public function normalize(Json $json): Json
3030
{
31+
$format = Format\Format::fromJson($json);
32+
3133
return $this->formatter->format(
3234
$this->normalizer->normalize($json),
33-
$json->format(),
35+
$format,
3436
);
3537
}
3638
}

src/Json.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ final class Json
2424
* @var null|array<mixed>|bool|float|int|\stdClass|string
2525
*/
2626
private $decoded;
27-
private Format\Format $format;
2827

2928
private function __construct(
3029
string $encoded,
3130
$decoded
3231
) {
3332
$this->encoded = $encoded;
3433
$this->decoded = $decoded;
35-
$this->format = Format\Format::fromJson($this);
3634
}
3735

3836
/**
@@ -75,14 +73,6 @@ public function encoded(): string
7573
return $this->encoded;
7674
}
7775

78-
/**
79-
* Returns the format of the original JSON value.
80-
*/
81-
public function format(): Format\Format
82-
{
83-
return $this->format;
84-
}
85-
8676
/**
8777
* Returns the original JSON value.
8878
*/

test/Unit/AutoFormatNormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testNormalizeNormalizesAndFormatsUsingJsonFormat(): void
7272
->method('format')
7373
->with(
7474
self::identicalTo($normalized),
75-
self::identicalTo($json->format()),
75+
self::equalTo(Format\Format::fromJson($json)),
7676
)
7777
->willReturn($formatted);
7878

test/Unit/CallableNormalizerTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
*
2222
* @covers \Ergebnis\Json\Normalizer\CallableNormalizer
2323
*
24-
* @uses \Ergebnis\Json\Normalizer\Format\Format
25-
* @uses \Ergebnis\Json\Normalizer\Format\Indent
26-
* @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions
27-
* @uses \Ergebnis\Json\Normalizer\Format\NewLine
2824
* @uses \Ergebnis\Json\Normalizer\Json
2925
*/
3026
final class CallableNormalizerTest extends AbstractNormalizerTestCase

test/Unit/ChainNormalizerTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
*
2323
* @covers \Ergebnis\Json\Normalizer\ChainNormalizer
2424
*
25-
* @uses \Ergebnis\Json\Normalizer\Format\Format
26-
* @uses \Ergebnis\Json\Normalizer\Format\Indent
27-
* @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions
28-
* @uses \Ergebnis\Json\Normalizer\Format\NewLine
2925
* @uses \Ergebnis\Json\Normalizer\Json
3026
*/
3127
final class ChainNormalizerTest extends AbstractNormalizerTestCase

test/Unit/FinalNewLineNormalizerTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
*
2222
* @covers \Ergebnis\Json\Normalizer\FinalNewLineNormalizer
2323
*
24-
* @uses \Ergebnis\Json\Normalizer\Format\Format
25-
* @uses \Ergebnis\Json\Normalizer\Format\Indent
26-
* @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions
27-
* @uses \Ergebnis\Json\Normalizer\Format\NewLine
2824
* @uses \Ergebnis\Json\Normalizer\Json
2925
*/
3026
final class FinalNewLineNormalizerTest extends AbstractNormalizerTestCase

test/Unit/Format/IndentTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
* @uses \Ergebnis\Json\Normalizer\Exception\InvalidIndentSizeException
2828
* @uses \Ergebnis\Json\Normalizer\Exception\InvalidIndentStringException
2929
* @uses \Ergebnis\Json\Normalizer\Exception\InvalidIndentStyleException
30-
* @uses \Ergebnis\Json\Normalizer\Format\Format
31-
* @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions
32-
* @uses \Ergebnis\Json\Normalizer\Format\NewLine
3330
* @uses \Ergebnis\Json\Normalizer\Json
3431
*/
3532
final class IndentTest extends Framework\TestCase

test/Unit/Format/JsonEncodeOptionsTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
* @covers \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions
2626
*
2727
* @uses \Ergebnis\Json\Normalizer\Exception\InvalidJsonEncodeOptionsException
28-
* @uses \Ergebnis\Json\Normalizer\Format\Format
29-
* @uses \Ergebnis\Json\Normalizer\Format\Indent
30-
* @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions
31-
* @uses \Ergebnis\Json\Normalizer\Format\NewLine
3228
* @uses \Ergebnis\Json\Normalizer\Json
3329
*/
3430
final class JsonEncodeOptionsTest extends Framework\TestCase

test/Unit/Format/NewLineTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
* @covers \Ergebnis\Json\Normalizer\Format\NewLine
2525
*
2626
* @uses \Ergebnis\Json\Normalizer\Exception\InvalidNewLineStringException
27-
* @uses \Ergebnis\Json\Normalizer\Format\Format
28-
* @uses \Ergebnis\Json\Normalizer\Format\Indent
29-
* @uses \Ergebnis\Json\Normalizer\Format\JsonEncodeOptions
30-
* @uses \Ergebnis\Json\Normalizer\Format\NewLine
3127
* @uses \Ergebnis\Json\Normalizer\Json
3228
*/
3329
final class NewLineTest extends Framework\TestCase

0 commit comments

Comments
 (0)