Skip to content

Commit

Permalink
Merge pull request #616 from ergebnis/fix/format
Browse files Browse the repository at this point in the history
Fix: Do not compose `Format` into `Json`
  • Loading branch information
localheinz authored Dec 29, 2021
2 parents aa0e189 + ff7f69a commit a8203cb
Show file tree
Hide file tree
Showing 20 changed files with 6 additions and 78 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/AutoFormatNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
10 changes: 0 additions & 10 deletions src/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ final class Json
* @var null|array<mixed>|bool|float|int|\stdClass|string
*/
private $decoded;
private Format\Format $format;

private function __construct(
string $encoded,
$decoded
) {
$this->encoded = $encoded;
$this->decoded = $decoded;
$this->format = Format\Format::fromJson($this);
}

/**
Expand Down Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/AutoFormatNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 0 additions & 4 deletions test/Unit/CallableNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/ChainNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/FinalNewLineNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions test/Unit/Format/IndentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/Format/JsonEncodeOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/Format/NewLineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions test/Unit/IndentNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions test/Unit/JsonEncodeNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions test/Unit/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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());
}

/**
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/NoFinalNewLineNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/SchemaNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/Vendor/Composer/BinNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/Vendor/Composer/ComposerJsonNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/Vendor/Composer/ConfigHashNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/Vendor/Composer/PackageHashNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions test/Unit/Vendor/Composer/VersionConstraintNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8203cb

Please sign in to comment.