Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For a full diff see [`2.28.3...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]

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
210 changes: 167 additions & 43 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions src/Command/NormalizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
) {
Expand Down Expand Up @@ -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);

Expand All @@ -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(),
Expand All @@ -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('<error>Original composer.json does not match the expected JSON schema:</error>');

self::showValidationErrors(
Expand All @@ -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('<error>Normalized composer.json does not match the expected JSON schema:</error>');

self::showValidationErrors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down