Skip to content

Commit

Permalink
Merge pull request #421 from ergebnis/fix/static
Browse files Browse the repository at this point in the history
Fix: Methods can be static
  • Loading branch information
ergebnis-bot committed May 1, 2020
2 parents ae07699 + 0f41247 commit 3079ef8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
1 change: 1 addition & 0 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"Composer\\Plugin\\Capability\\CommandProvider",
"Composer\\Plugin\\Capable",
"Composer\\Plugin\\PluginInterface",
"Symfony\\Component\\Console\\Application",
"Symfony\\Component\\Console\\Input\\ArrayInput",
"Symfony\\Component\\Console\\Input\\InputArgument",
"Symfony\\Component\\Console\\Input\\InputInterface",
Expand Down
49 changes: 19 additions & 30 deletions src/Command/NormalizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
$io = $this->getIO();

try {
$indent = $this->indentFrom($input);
$indent = self::indentFrom($input);
} catch (\RuntimeException $exception) {
$io->writeError(\sprintf(
'<error>%s</error>',
Expand Down Expand Up @@ -154,7 +154,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
} catch (Normalizer\Exception\OriginalInvalidAccordingToSchemaException $exception) {
$io->writeError('<error>Original composer.json does not match the expected JSON schema:</error>');

$this->showValidationErrors(
self::showValidationErrors(
$io,
...$exception->errors()
);
Expand All @@ -163,7 +163,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
} catch (Normalizer\Exception\NormalizedInvalidAccordingToSchemaException $exception) {
$io->writeError('<error>Normalized composer.json does not match the expected JSON schema:</error>');

$this->showValidationErrors(
self::showValidationErrors(
$io,
...$exception->errors()
);
Expand Down Expand Up @@ -204,17 +204,15 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
$composerFile
));

$io->write([
'',
'<fg=yellow>---------- begin diff ----------</>',
]);

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

$io->write([
'',
'<fg=yellow>---------- begin diff ----------</>',
self::formatDiff($diff),
'<fg=yellow>----------- end diff -----------</>',
'',
]);
Expand All @@ -239,7 +237,8 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O

$this->resetComposer();

return $this->updateLockerInWorkingDirectory(
return self::updateLockerInWorkingDirectory(
$this->getApplication(),
$output,
\dirname($composerFile)
);
Expand All @@ -252,7 +251,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
*
* @return null|Normalizer\Format\Indent
*/
private function indentFrom(Console\Input\InputInterface $input): ?Normalizer\Format\Indent
private static function indentFrom(Console\Input\InputInterface $input): ?Normalizer\Format\Indent
{
/** @var null|string $indentSize */
$indentSize = $input->getOption('indent-size');
Expand Down Expand Up @@ -304,7 +303,7 @@ private function indentFrom(Console\Input\InputInterface $input): ?Normalizer\Fo
return $indent;
}

private function showValidationErrors(IO\IOInterface $io, string ...$errors): void
private static function showValidationErrors(IO\IOInterface $io, string ...$errors): void
{
foreach ($errors as $error) {
$io->writeError(\sprintf(
Expand All @@ -316,19 +315,8 @@ private function showValidationErrors(IO\IOInterface $io, string ...$errors): vo
$io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
}

/**
* @param string $before
* @param string $after
*
* @return string
*/
private function diff(string $before, string $after): string
private static function formatDiff(string $diff): string
{
$diff = $this->differ->diff(
$before,
$after
);

$lines = \explode(
"\n",
$diff
Expand Down Expand Up @@ -363,18 +351,19 @@ private function diff(string $before, string $after): string
/**
* @see https://getcomposer.org/doc/03-cli.md#update
*
* @param Console\Application $application
* @param Console\Output\OutputInterface $output
* @param string $workingDirectory
*
* @throws \Exception
*
* @return int
*/
private function updateLockerInWorkingDirectory(Console\Output\OutputInterface $output, string $workingDirectory): int
{
/** @var Console\Application $application */
$application = $this->getApplication();

private static function updateLockerInWorkingDirectory(
Console\Application $application,
Console\Output\OutputInterface $output,
string $workingDirectory
): int {
return $application->run(
new Console\Input\ArrayInput([
'command' => 'update',
Expand Down

0 comments on commit 3079ef8

Please sign in to comment.