Skip to content

Commit 3a84394

Browse files
committed
fixup! cs
1 parent 168cfb7 commit 3a84394

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

src/Command/RaiseToInstalledCommand.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Nette\Utils\Json;
1111
use Rector\Jack\FileSystem\ComposerJsonPackageVersionUpdater;
1212
use Rector\Jack\Utils\JsonFileLoader;
13+
use Rector\Jack\ValueObject\ChangedPackageVersion;
1314
use Symfony\Component\Console\Command\Command;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Input\InputOption;
@@ -95,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9596
$newPackageVersion
9697
);
9798

98-
$changedPackages[] = $packageName;
99+
$changedPackages[] = new ChangedPackageVersion($packageName, $packageVersion, $newPackageVersion);
99100
continue;
100101
}
101102
}
@@ -111,8 +112,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
111112
// remove "-dev" suffix
112113
$normalizedConstraintVersion = str_replace('-dev', '', $normalizedConstraintVersion);
113114

114-
// all equal
115-
if ($normalizedConstraintVersion === $normalizedInstalledVersion) {
115+
116+
// are major + minor equal?
117+
if ($this->areMajorAndMinorVersionsEqual($normalizedConstraintVersion, $normalizedInstalledVersion)) {
116118
continue;
117119
}
118120

@@ -129,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
129131

130132
// focus on minor only
131133
// or on patch in case of 0.*
132-
$changedPackages[] = $packageName;
134+
$changedPackages[] = new ChangedPackageVersion($packageName, $packageVersion, $newRequiredVersion);
133135
}
134136

135137
if ($changedPackages === []) {
@@ -142,13 +144,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int
142144
}
143145

144146
$symfonyStyle->success(sprintf(
145-
'%d packages %s changed to installed versions.%s%s "composer update --lock" to update "composer.lock" hash',
147+
'%d package%s %s changed to installed versions.%s%s "composer update --lock" to update "composer.lock" hash',
146148
count($changedPackages),
149+
count($changedPackages) === 1 ? '' : 's',
147150
$isDryRun ? 'would be (is "--dry-run")' : 'were updated',
151+
PHP_EOL,
148152
$isDryRun ? 'Then you would run' : 'Now run',
149-
PHP_EOL
150153
));
151154

155+
foreach ($changedPackages as $changedPackage) {
156+
$symfonyStyle->writeln(sprintf(
157+
' * <fg=green>%s</> (<fg=yellow>%s</> => <fg=yellow>%s</>)',
158+
$changedPackage->getPackageName(),
159+
$changedPackage->getOldVersion(),
160+
$changedPackage->getNewVersion()
161+
));
162+
}
163+
164+
$symfonyStyle->newLine();
165+
152166
return self::SUCCESS;
153167
}
154168

@@ -172,4 +186,13 @@ private function resolveInstalledPackagesToVersions(): array
172186

173187
return $installedPackagesToVersions;
174188
}
189+
190+
private function areMajorAndMinorVersionsEqual(string $firstVersion, string $secondVersion): bool
191+
{
192+
[$firstMajor, $firstMinor] = explode('.', $firstVersion);
193+
[$secondMajor, $secondMinor] = explode('.', $secondVersion);
194+
195+
// if major and minor are equal, we can skip the update
196+
return $firstMajor === $secondMajor && $firstMinor === $secondMinor;
197+
}
175198
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Jack\ValueObject;
6+
7+
final class ChangedPackageVersion
8+
{
9+
public function __construct(
10+
private string $packageName,
11+
private string $oldVersion,
12+
private string $newVersion,
13+
)
14+
{
15+
16+
}
17+
18+
public function getPackageName(): string
19+
{
20+
return $this->packageName;
21+
}
22+
23+
public function getOldVersion(): string
24+
{
25+
return $this->oldVersion;
26+
}
27+
28+
public function getNewVersion(): string
29+
{
30+
return $this->newVersion;
31+
}
32+
}

0 commit comments

Comments
 (0)