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

Enhancement: Use Php73 rule set #846

Merged
merged 2 commits into from Dec 28, 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
6 changes: 3 additions & 3 deletions .php-cs-fixer.php
Expand Up @@ -18,15 +18,15 @@
__DIR__ . '/LICENSE.md',
License\Range::since(
License\Year::fromString('2018'),
new \DateTimeZone('UTC')
new \DateTimeZone('UTC'),
),
License\Holder::fromString('Andreas Möller'),
License\Url::fromString('https://github.com/ergebnis/composer-normalize')
License\Url::fromString('https://github.com/ergebnis/composer-normalize'),
);

$license->save();

$config = PhpCsFixer\Config\Factory::fromRuleSet(new PhpCsFixer\Config\RuleSet\Php71($license->header()));
$config = PhpCsFixer\Config\Factory::fromRuleSet(new PhpCsFixer\Config\RuleSet\Php73($license->header()));

$config->getFinder()
->exclude([
Expand Down
4 changes: 2 additions & 2 deletions bin/laxify-schema.php
Expand Up @@ -15,13 +15,13 @@

$schema = \json_decode(
\file_get_contents($schemaFile),
false
false,
);

$schema->additionalProperties = true;
$schema->required = [];

\file_put_contents($schemaFile, \json_encode(
$schema,
\JSON_PRETTY_PRINT | \JSON_PRESERVE_ZERO_FRACTION | \JSON_UNESCAPED_SLASHES
\JSON_PRETTY_PRINT | \JSON_PRESERVE_ZERO_FRACTION | \JSON_UNESCAPED_SLASHES,
));
4 changes: 2 additions & 2 deletions phar/composer-normalize.php
Expand Up @@ -28,7 +28,7 @@
new Diff\Differ(new Diff\Output\StrictUnifiedDiffOutputBuilder([
'fromFile' => 'original',
'toFile' => 'normalized',
]))
])),
);

$application = new Application();
Expand All @@ -42,7 +42,7 @@
0,
[
'normalize',
]
],
);
}

Expand Down
84 changes: 42 additions & 42 deletions src/Command/NormalizeCommand.php
Expand Up @@ -58,46 +58,46 @@ protected function configure(): void
new Console\Input\InputArgument(
'file',
Console\Input\InputArgument::OPTIONAL,
'Path to composer.json file'
'Path to composer.json file',
),
new Console\Input\InputOption(
'diff',
null,
Console\Input\InputOption::VALUE_NONE,
'Show the results of normalizing'
'Show the results of normalizing',
),
new Console\Input\InputOption(
'dry-run',
null,
Console\Input\InputOption::VALUE_NONE,
'Show the results of normalizing, but do not modify any files'
'Show the results of normalizing, but do not modify any files',
),
new Console\Input\InputOption(
'indent-size',
null,
Console\Input\InputOption::VALUE_REQUIRED,
'Indent size (an integer greater than 0); should be used with the --indent-style option'
'Indent size (an integer greater than 0); should be used with the --indent-style option',
),
new Console\Input\InputOption(
'indent-style',
null,
Console\Input\InputOption::VALUE_REQUIRED,
\sprintf(
'Indent style (one of "%s"); should be used with the --indent-size option',
\implode('", "', \array_keys(Normalizer\Format\Indent::CHARACTERS))
)
\implode('", "', \array_keys(Normalizer\Format\Indent::CHARACTERS)),
),
),
new Console\Input\InputOption(
'no-check-lock',
null,
Console\Input\InputOption::VALUE_NONE,
'Do not check if lock file is up to date'
'Do not check if lock file is up to date',
),
new Console\Input\InputOption(
'no-update-lock',
null,
Console\Input\InputOption::VALUE_NONE,
'Do not update lock file if it exists'
'Do not update lock file if it exists',
),
]);
}
Expand All @@ -111,7 +111,7 @@ protected function execute(
$io->write([
\sprintf(
'Running %s.',
Version::long()
Version::long(),
),
'',
]);
Expand All @@ -123,7 +123,7 @@ protected function execute(
} catch (\RuntimeException $exception) {
$io->writeError(\sprintf(
'<error>%s</error>',
$exception->getMessage()
$exception->getMessage(),
));

return 1;
Expand All @@ -141,15 +141,15 @@ protected function execute(

$composer = $this->factory->createComposer(
$io,
$composerFile
$composerFile,
);

try {
$indentFromExtra = self::indentFromExtra($composer->getPackage()->getExtra());
} catch (\RuntimeException $exception) {
$io->writeError(\sprintf(
'<error>%s</error>',
$exception->getMessage()
$exception->getMessage(),
));

return 1;
Expand All @@ -172,7 +172,7 @@ protected function execute(
) {
$io->writeError(\sprintf(
'<error>%s is not writable.</error>',
$composerFile
$composerFile,
));

return 1;
Expand Down Expand Up @@ -203,7 +203,7 @@ protected function execute(

self::showValidationErrors(
$io,
...$exception->errors()
...$exception->errors(),
);

return 1;
Expand All @@ -212,14 +212,14 @@ protected function execute(

self::showValidationErrors(
$io,
...$exception->errors()
...$exception->errors(),
);

return 1;
} catch (\RuntimeException $exception) {
$io->writeError(\sprintf(
'<error>%s</error>',
$exception->getMessage()
$exception->getMessage(),
));

return 1;
Expand All @@ -233,13 +233,13 @@ protected function execute(

$formatted = $this->formatter->format(
$normalized,
$format
$format,
);

if ($json->encoded() === $formatted->encoded()) {
$io->write(\sprintf(
'<info>%s is already normalized.</info>',
$composerFile
$composerFile,
));

return 0;
Expand All @@ -251,12 +251,12 @@ protected function execute(
) {
$io->writeError(\sprintf(
'<error>%s is not normalized.</error>',
$composerFile
$composerFile,
));

$diff = $this->differ->diff(
$json->encoded(),
$formatted->encoded()
$formatted->encoded(),
);

$io->write([
Expand All @@ -274,12 +274,12 @@ protected function execute(

\file_put_contents(
$composerFile,
$formatted->encoded()
$formatted->encoded(),
);

$io->write(\sprintf(
'<info>Successfully normalized %s.</info>',
$composerFile
$composerFile,
));

if (
Expand All @@ -299,7 +299,7 @@ protected function execute(
return self::updateLockerInWorkingDirectory(
$application,
$output,
\dirname($composerFile)
\dirname($composerFile),
);
}

Expand Down Expand Up @@ -328,7 +328,7 @@ private static function indentFromInput(Console\Input\InputInterface $input): ?N
if (null === $indentStyle) {
throw new \RuntimeException(\sprintf(
'When using the indent-size option, an indent style (one of "%s") needs to be specified using the indent-style option.',
\implode('", "', \array_keys(Normalizer\Format\Indent::CHARACTERS))
\implode('", "', \array_keys(Normalizer\Format\Indent::CHARACTERS)),
));
}

Expand All @@ -338,21 +338,21 @@ private static function indentFromInput(Console\Input\InputInterface $input): ?N
) {
throw new \RuntimeException(\sprintf(
'Indent size needs to be an integer greater than 0, but "%s" is not.',
$indentSize
$indentSize,
));
}

if (!\array_key_exists($indentStyle, Normalizer\Format\Indent::CHARACTERS)) {
throw new \RuntimeException(\sprintf(
'Indent style needs to be one of "%s", but "%s" is not.',
\implode('", "', \array_keys(Normalizer\Format\Indent::CHARACTERS)),
$indentStyle
$indentStyle,
));
}

return Normalizer\Format\Indent::fromSizeAndStyle(
(int) $indentSize,
$indentStyle
$indentStyle,
);
}

Expand All @@ -375,31 +375,31 @@ private static function indentFromExtra(array $extra): ?Normalizer\Format\Indent
if (!\is_array($configuration)) {
throw new \RuntimeException(\sprintf(
'Configuration in composer extra requires keys "%s" with corresponding values."',
\implode('", "', $requiredKeys)
\implode('", "', $requiredKeys),
));
}

$missingKeys = \array_diff(
$requiredKeys,
\array_keys($configuration)
\array_keys($configuration),
);

if ([] !== $missingKeys) {
throw new \RuntimeException(\sprintf(
'Configuration in composer extra requires keys "%s" with corresponding values."',
\implode('", "', $requiredKeys)
\implode('", "', $requiredKeys),
));
}

$extraKeys = \array_diff(
\array_keys($configuration),
$requiredKeys
$requiredKeys,
);

if ([] !== $extraKeys) {
throw new \RuntimeException(\sprintf(
'Configuration in composer extra does not allow extra keys "%s"."',
\implode('", "', $extraKeys)
\implode('", "', $extraKeys),
));
}

Expand All @@ -408,14 +408,14 @@ private static function indentFromExtra(array $extra): ?Normalizer\Format\Indent
if (!\is_int($indentSize)) {
throw new \RuntimeException(\sprintf(
'Indent size needs to be an integer, got %s instead.',
\gettype($indentSize)
\gettype($indentSize),
));
}

if (1 > $indentSize) {
throw new \RuntimeException(\sprintf(
'Indent size needs to be an integer greater than 0, but %d is not.',
$indentSize
$indentSize,
));
}

Expand All @@ -424,21 +424,21 @@ private static function indentFromExtra(array $extra): ?Normalizer\Format\Indent
if (!\is_string($indentStyle)) {
throw new \RuntimeException(\sprintf(
'Indent style needs to be a string, got %s instead.',
\gettype($indentStyle)
\gettype($indentStyle),
));
}

if (!\array_key_exists($indentStyle, Normalizer\Format\Indent::CHARACTERS)) {
throw new \RuntimeException(\sprintf(
'Indent style needs to be one of "%s", but "%s" is not.',
\implode('", "', \array_keys(Normalizer\Format\Indent::CHARACTERS)),
$indentStyle
$indentStyle,
));
}

return Normalizer\Format\Indent::fromSizeAndStyle(
$indentSize,
$indentStyle
$indentStyle,
);
}

Expand All @@ -449,7 +449,7 @@ private static function showValidationErrors(
foreach ($errors as $error) {
$io->writeError(\sprintf(
'<error>- %s</error>',
$error
$error,
));
}

Expand All @@ -460,7 +460,7 @@ private static function formatDiff(string $diff): string
{
$lines = \explode(
"\n",
$diff
$diff,
);

$formatted = \array_map(static function (string $line): string {
Expand All @@ -473,7 +473,7 @@ private static function formatDiff(string $diff): string
'<fg=green>$1</>',
'<fg=red>$1</>',
],
$line
$line,
);

if (!\is_string($replaced)) {
Expand All @@ -485,7 +485,7 @@ private static function formatDiff(string $diff): string

return \implode(
"\n",
$formatted
$formatted,
);
}

Expand All @@ -509,7 +509,7 @@ private static function updateLockerInWorkingDirectory(
'--no-scripts' => true,
'--working-dir' => $workingDirectory,
]),
$output
$output,
);
}
}