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: Remove default values of $formatter and $differ parameters #262

Merged
merged 1 commit into from
Dec 15, 2019
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 [`1.3.1...master`][1.3.1...master]
## Changed

* Started using `ergebnis/composer-json-normalizer` instead of `localheinz/composer-json-normalizer`, `ergebnis/json-normalizer` instead of `localheinz/json-normalizer`, and `ergebnis/json-printer` instead of `localheinz/json-printer` ([#261]), by [@localheinz]
* Removed default values for parameters `$formatter` and `$differ` of `Localheinz\Composer\Normalize\Command\NormalizeCommand` ([#262]), by [@localheinz]

### Fixed

Expand Down Expand Up @@ -252,6 +253,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
[#207]: https://github.com/localheinz/composer-normalize/pull/207
[#235]: https://github.com/localheinz/composer-normalize/pull/235
[#261]: https://github.com/localheinz/composer-normalize/pull/261
[#262]: https://github.com/localheinz/composer-normalize/pull/262

[@localheinz]: https://github.com/localheinz
[@svenluijten]: https://github.com/svenluijten
Expand Down
30 changes: 0 additions & 30 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,6 @@

parameters:
ignoreErrors:
-
message: "#^Constructor in Localheinz\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand has parameter \\$differ with default value\\.$#"
count: 1
path: src/Command/NormalizeCommand.php

-
message: "#^Constructor in Localheinz\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand has parameter \\$formatter with default value\\.$#"
count: 1
path: src/Command/NormalizeCommand.php

-
message: "#^Method Localheinz\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand\\:\\:__construct\\(\\) has parameter \\$differ with a nullable type declaration\\.$#"
count: 1
path: src/Command/NormalizeCommand.php

-
message: "#^Method Localheinz\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand\\:\\:__construct\\(\\) has parameter \\$differ with null as default value\\.$#"
count: 1
path: src/Command/NormalizeCommand.php

-
message: "#^Method Localheinz\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand\\:\\:__construct\\(\\) has parameter \\$formatter with a nullable type declaration\\.$#"
count: 1
path: src/Command/NormalizeCommand.php

-
message: "#^Method Localheinz\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand\\:\\:__construct\\(\\) has parameter \\$formatter with null as default value\\.$#"
count: 1
path: src/Command/NormalizeCommand.php

-
message: "#^Method Localheinz\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand\\:\\:indentFrom\\(\\) has a nullable return type declaration\\.$#"
count: 1
Expand Down
15 changes: 3 additions & 12 deletions src/Command/NormalizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Composer\Command;
use Composer\Factory;
use Ergebnis\Json\Normalizer;
use Ergebnis\Json\Printer;
use Localheinz\Diff;
use Symfony\Component\Console;

Expand Down Expand Up @@ -53,22 +52,14 @@ final class NormalizeCommand extends Command\BaseCommand
public function __construct(
Factory $factory,
Normalizer\NormalizerInterface $normalizer,
?Normalizer\Format\FormatterInterface $formatter = null,
?Diff\Differ $differ = null
Normalizer\Format\FormatterInterface $formatter,
Diff\Differ $differ
) {
parent::__construct('normalize');

$this->factory = $factory;
$this->normalizer = $normalizer;
$this->formatter = $formatter ?: new Normalizer\Format\Formatter(new Printer\Printer());

if (null === $differ) {
$differ = new Diff\Differ(new Diff\Output\StrictUnifiedDiffOutputBuilder([
'fromFile' => 'original',
'toFile' => 'normalized',
]));
}

$this->formatter = $formatter;
$this->differ = $differ;
}

Expand Down
13 changes: 10 additions & 3 deletions src/NormalizePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Composer\Factory;
use Composer\IO;
use Composer\Plugin;
use Ergebnis\Composer\Json\Normalizer;
use Localheinz\Composer\Normalize\Command\SchemaUriResolver;
use Ergebnis\Composer\Json\Normalizer\ComposerJsonNormalizer;
use Ergebnis\Json\Normalizer;
use Ergebnis\Json\Printer;
use Localheinz\Diff;

final class NormalizePlugin implements Plugin\Capability\CommandProvider, Plugin\Capable, Plugin\PluginInterface
{
Expand All @@ -38,7 +40,12 @@ public function getCommands(): array
return [
new Command\NormalizeCommand(
new Factory(),
new Normalizer\ComposerJsonNormalizer(SchemaUriResolver::resolve())
new ComposerJsonNormalizer(Command\SchemaUriResolver::resolve()),
new Normalizer\Format\Formatter(new Printer\Printer()),
new Diff\Differ(new Diff\Output\StrictUnifiedDiffOutputBuilder([
'fromFile' => 'original',
'toFile' => 'normalized',
]))
),
];
}
Expand Down
7 changes: 6 additions & 1 deletion test/Integration/Command/NormalizeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Localheinz\Composer\Normalize\Test\Util\Directory;
use Localheinz\Composer\Normalize\Test\Util\Scenario;
use Localheinz\Composer\Normalize\Test\Util\State;
use Localheinz\Diff;
use PHPUnit\Framework;
use Symfony\Component\Console;
use Symfony\Component\Filesystem;
Expand Down Expand Up @@ -285,7 +286,11 @@ public function normalize(Json $json): Json
throw new \RuntimeException($this->exceptionMessage);
}
},
new Formatter(new Printer())
new Formatter(new Printer()),
new Diff\Differ(new Diff\Output\StrictUnifiedDiffOutputBuilder([
'fromFile' => 'original',
'toFile' => 'normalized',
]))
));

$input = new Console\Input\ArrayInput($scenario->consoleParameters());
Expand Down