Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from localheinz/feature/import
Browse files Browse the repository at this point in the history
Enhancement: Import normalizers from localheinz/composer-normalize
  • Loading branch information
localheinz authored Nov 17, 2018
2 parents 25cc407 + 44730c4 commit 306d14e
Show file tree
Hide file tree
Showing 17 changed files with 3,432 additions and 796 deletions.
28 changes: 6 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

For a full diff see (https://github.com/localheinz/composer-json-normalizer/compare/1902cc2...HEAD).
For a full diff see [`1.0.0...master`](https://github.com/localheinz/composer-json-normalizer/compare/1.0.0...master).

### Added

*

### Changed

*

### Deprecated

*
## [`1.0.0`](https://github.com/localheinz/composer-json-normalizer/releases/tag/1.0.0)

For a full diff see [`149a393...1.0.0`](https://github.com/localheinz/composer-json-normalizer/compare/149a393...1.0.0).

### Removed

*

### Fixed

*

### Security
### Added

*
* imported all of the normalizers from [`localheinz/json-normalizer`](https://github.com/localheinz/composer-normalize/tree/dcf55c24e2dfa49f7be594bfe50aa3c636b84501) ([#1](https://github.com/localheinz/composer-json-normalizer/pull/#1)), by [@localheinz](https://github.com/localheinz)
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,99 @@ Run
$ composer require localheinz/composer-json-normalizer
```

## Usage

Create an instance of `Localheinz\Composer\Json\Normalizer\ComposerJsonNormalizer`
and use it to normalize the contents of a `composer.json`:

```php
<?php

use Localheinz\Composer\Json\Normalizer\ComposerJsonNormalizer;
use Localheinz\Json\Normalizer\Json;

$normalizer = new ComposerJsonNormalizer();

$json = Json::fromEncoded(file_get_contents(__DIR__ . '/composer.json'));

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

echo $normalized->encoded();
```

:bulb: Looking for the composer plugin? Head over to [`localheinz/composer-normalize`](https://github.com/localheinz/composer-normalize).

## Normalizers

The `ComposerJsonNormalizer` composes normalizers provided by [`localheinz/json-normalizer`](https://github.com/localheinz/json-normalizer):

* [`Localheinz\Json\Normalizer\ChainNormalizer`](https://github.com/localheinz/json-normalizer#chainnormalizer)
* [`Localheinz\Json\Normalizer\SchemaNormalizer`](https://github.com/localheinz/json-normalizer#schemanormalizer)

as well as the following normalizers provided by this package:

* [`Localheinz\Composer\Json\Normalizer\BinNormalizer`](#binnormalizer)
* [`Localheinz\Composer\Json\Normalizer\ConfigHashNormalizer`](#confighashnormalizer)
* [`Localheinz\Composer\Json\Normalizer\PackageHashNormalizer`](#packagehashnormalizer)
* [`Localheinz\Composer\Json\Normalizer\VersionConstraintNormalizer`](#versionconstraintnormalizer)

### `BinNormalizer`

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.

:bulb: Find out more about the `bin` section at https://getcomposer.org/doc/04-schema.md#bin.

### `ConfigHashNormalizer`

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.

:bulb: Find out more about the `config` section at https://getcomposer.org/doc/06-config.md.

### `PackageHashNormalizer`

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.

:bulb: 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.

### `VersionConstraintNormalizer`

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 a comma (`,`)
* *or* constraints are separated by double-pipe with a single space before and after (` || `)
* *range* constraints are separated by a single space (` `)

:bulb: Find out more about version constraints at https://getcomposer.org/doc/articles/versions.md.

## Changelog

Please have a look at [`CHANGELOG.md`](CHANGELOG.md).
Expand All @@ -30,3 +123,11 @@ Please have a look at [`CODE_OF_CONDUCT.md`](.github/CODE_OF_CONDUCT.md).
## License

This package is licensed using the MIT License.

## Credits

The algorithm for sorting packages in the [`PackageHashNormalizer`](src/PackageHashNormalizer.php) has
been adopted from [`Composer\Json\JsonManipulator::sortPackages()`](https://github.com/composer/composer/blob/1.6.2/src/Composer/Json/JsonManipulator.php#L110-L146)
(originally licensed under MIT by [Nils Adermann](https://github.com/naderman) and [Jordi Boggiano](https://github.com/seldaek)),
which I initially contributed to `composer/composer` with [`composer/composer#3549`](https://github.com/composer/composer/pull/3549)
and [`composer/composer#3872`](https://github.com/composer/composer/pull/3872).
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
}
],
"require": {
"php": "^7.1"
"php": "^7.1",
"composer/composer": "^1.1.0",
"localheinz/json-normalizer": "~0.9.0"
},
"require-dev": {
"infection/infection": "~0.11.1",
Expand Down
Loading

0 comments on commit 306d14e

Please sign in to comment.