1010use Nette \Utils \Json ;
1111use Rector \Jack \FileSystem \ComposerJsonPackageVersionUpdater ;
1212use Rector \Jack \Utils \JsonFileLoader ;
13+ use Rector \Jack \ValueObject \ChangedPackageVersion ;
1314use Symfony \Component \Console \Command \Command ;
1415use Symfony \Component \Console \Input \InputInterface ;
1516use 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}
0 commit comments