Provides normalizers for normalizing composer.json
.
Run
$ composer require ergebnis/composer-json-normalizer
Create an instance of Ergebnis\Composer\Json\Normalizer\ComposerJsonNormalizer
and use it to normalize the contents of a composer.json
:
<?php
use Ergebnis\Composer\Json\Normalizer\ComposerJsonNormalizer;
use Ergebnis\Json\Normalizer\Json;
$normalizer = new ComposerJsonNormalizer('https://getcomposer.org/schema.json');
$json = Json::fromEncoded(file_get_contents(__DIR__ . '/composer.json'));
$normalized = $normalizer->normalize($json);
echo $normalized->encoded();
💡 Looking for the composer plugin? Head over to localheinz/composer-normalize
.
The ComposerJsonNormalizer
composes normalizers provided by localheinz/json-normalizer
:
as well as the following normalizers provided by this package:
Ergebnis\Composer\Json\Normalizer\BinNormalizer
Ergebnis\Composer\Json\Normalizer\ConfigHashNormalizer
Ergebnis\Composer\Json\Normalizer\PackageHashNormalizer
Ergebnis\Composer\Json\Normalizer\VersionConstraintNormalizer
If composer.json
contains an array of scripts in the bin
section,
the BinNormalizer
will sort the elements of the bin
section by value in ascending order.
💡 Find out more about the bin
section at https://getcomposer.org/doc/04-schema.md#bin.
If composer.json
contains any configuration in the
config
extra
scripts-descriptions
sections, the ConfigHashNormalizer
will sort the content of these sections
by key in ascending order.
💡 Find out more about the config
section at https://getcomposer.org/doc/06-config.md.
If composer.json
contains any configuration in the
conflict
provide
replace
require
require-dev
suggest
sections, the PackageHashNormalizer
will sort the content of these sections.
💡 This transfers the behaviour from using the --sort-packages
or
sort-packages
configuration flag to other sections. Find out more about
the --sort-packages
flag and configuration at https://getcomposer.org/doc/06-config.md#sort-packages
and https://getcomposer.org/doc/03-cli.md#require.
If composer.json
contains version constraints in the
conflict
provide
replace
require
require-dev
sections, the VersionConstraintNormalizer
will ensure that
- all constraints are trimmed
- and constraints are separated by a single space (
,
) - or constraints are separated by double-pipe with a single space before and after (
||
) - range constraints are separated by a single space (
💡 Find out more about version constraints at https://getcomposer.org/doc/articles/versions.md.
Please have a look at CHANGELOG.md
.
Please have a look at CONTRIBUTING.md
.
Please have a look at CODE_OF_CONDUCT.md
.
This package is licensed using the MIT License.
The algorithm for sorting packages in the PackageHashNormalizer
has
been adopted from Composer\Json\JsonManipulator::sortPackages()
(originally licensed under MIT by Nils Adermann and Jordi Boggiano),
which I initially contributed to composer/composer
with composer/composer#3549
and composer/composer#3872
.