Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Rename class #618

Merged
merged 1 commit into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ For a full diff see [`1.0.3...main`][1.0.3...main].
- 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]
- Renamed `FinalNewLineNormalizer` to `WithFinalNewLineNormalizer` ([#618]), by [@localheinz]

### Fixed

Expand Down Expand Up @@ -440,6 +441,7 @@ For a full diff see [`5d8b3e2...0.1.0`][5d8b3e2...0.1.0].
[#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
[#618]: https://github.com/ergebnis/json-normalizer/pull/618

[@BackEndTea]: https://github.com/BackEndTea
[@dependabot]: https://github.com/dependabot
Expand Down
58 changes: 29 additions & 29 deletions README.md
Expand Up @@ -32,12 +32,12 @@ This package comes with the following generic normalizers:
- [`Ergebnis\Json\Normalizer\AutoFormatNormalizer`](#autoformatnormalizer)
- [`Ergebnis\Json\Normalizer\CallableNormalizer`](#callablenormalizer)
- [`Ergebnis\Json\Normalizer\ChainNormalizer`](#chainnormalizer)
- [`Ergebnis\Json\Normalizer\FinalNewLineNormalizer`](#finalnewlinenormalizer)
- [`Ergebnis\Json\Normalizer\FixedFormatNormalizer`](#fixedformatnormalizer)
- [`Ergebnis\Json\Normalizer\IndentNormalizer`](#indentnormalizer)
- [`Ergebnis\Json\Normalizer\JsonEncodeNormalizer`](#jsonencodenormalizer)
- [`Ergebnis\Json\Normalizer\NoFinalNewLineNormalizer`](#nofinalnewlinenormalizer)
- [`Ergebnis\Json\Normalizer\SchemaNormalizer`](#schemanormalizer)
- [`Ergebnis\Json\Normalizer\WithFinalNewLineNormalizer`](#withfinalnewlinenormalizer)

:bulb: All of these normalizers implement the `Ergebnis\Json\Normalizer\NormalizerInterface`.

Expand Down Expand Up @@ -150,7 +150,7 @@ $normalizer = new Normalizer\ChainNormalizer(
$indent,
new Printer\Printer()
),
new Normalizer\FinalNewLineNormalizer()
new Normalizer\WithFinalNewLineNormalizer()
);

$normalized = $normalizer->normalize($json);
Expand All @@ -160,33 +160,6 @@ The normalized version will now contain the result of applying all normalizers i

:bulb: Be careful with the order of the normalizers, as one normalizer might override changes a previous normalizer applied.

#### `FinalNewLineNormalizer`

When you want to ensure that a JSON file has a single final new line, you can use the `FinalNewLineNormalizer`.

```php
<?php

use Ergebnis\Json\Normalizer;

$encoded = <<<'JSON'
{
"name": "Andreas Möller",
"url": "https://localheinz.com"
}


JSON;

$json = Normalizer\Json::fromEncoded($encoded);

$normalizer = new Normalizer\FinalNewLineNormalizer();

$normalized = $normalizer->normalize($json);
```

The normalized version will now have a single final new line.

#### `FixedFormatNormalizer`

When you want to normalize a JSON file with an implementation of `NormalizerInterface`, but apply a fixed formatting, you can use the `FixedFormatNormalizer`.
Expand Down Expand Up @@ -360,6 +333,33 @@ The normalized version will now be structured according to the JSON schema (in t

:bulb: For more information about JSON schema, visit [json-schema.org](http://json-schema.org).

#### `WithFinalNewLineNormalizer`

When you want to ensure that a JSON file has a single final new line, you can use the `WithFinalNewLineNormalizer`.

```php
<?php

use Ergebnis\Json\Normalizer;

$encoded = <<<'JSON'
{
"name": "Andreas Möller",
"url": "https://localheinz.com"
}


JSON;

$json = Normalizer\Json::fromEncoded($encoded);

$normalizer = new Normalizer\WithFinalNewLineNormalizer();

$normalized = $normalizer->normalize($json);
```

The normalized version will now have a single final new line.

### Vendor-specific normalizers

This package comes with the following vendor-specific normalizers:
Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer;

final class FinalNewLineNormalizer implements NormalizerInterface
final class WithFinalNewLineNormalizer implements NormalizerInterface
{
public function normalize(Json $json): Json
{
Expand Down
Expand Up @@ -13,17 +13,17 @@

namespace Ergebnis\Json\Normalizer\Test\Unit;

use Ergebnis\Json\Normalizer\FinalNewLineNormalizer;
use Ergebnis\Json\Normalizer\Json;
use Ergebnis\Json\Normalizer\WithFinalNewLineNormalizer;

/**
* @internal
*
* @covers \Ergebnis\Json\Normalizer\FinalNewLineNormalizer
* @covers \Ergebnis\Json\Normalizer\WithFinalNewLineNormalizer
*
* @uses \Ergebnis\Json\Normalizer\Json
*/
final class FinalNewLineNormalizerTest extends AbstractNormalizerTestCase
final class WithFinalNewLineNormalizerTest extends AbstractNormalizerTestCase
{
/**
* @dataProvider \Ergebnis\DataProvider\StringProvider::blank()
Expand All @@ -39,7 +39,7 @@ public function testNormalizeEnsuresSingleFinalNewLine(string $whitespace): void
JSON
);

$normalizer = new FinalNewLineNormalizer();
$normalizer = new WithFinalNewLineNormalizer();

$normalized = $normalizer->normalize($json);

Expand Down