1313
1414use Composer \Command \BaseCommand ;
1515use Composer \IO \IOInterface ;
16+ use Composer \Package \Package ;
1617use Composer \Util \ProcessExecutor ;
1718use Symfony \Component \Console \Exception \RuntimeException ;
1819use Symfony \Component \Console \Formatter \OutputFormatterStyle ;
@@ -122,7 +123,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
122123 return 1 ;
123124 }
124125
125- $ originalRecipe = $ this ->getRecipe ($ packageName , $ recipeRef , $ recipeVersion );
126+ $ installedRepo = $ this ->getComposer ()->getRepositoryManager ()->getLocalRepository ();
127+ $ package = $ installedRepo ->findPackage ($ packageName , '* ' ) ?? new Package ($ packageName , $ packageLockData ['version ' ], $ packageLockData ['version ' ]);
128+ $ originalRecipe = $ this ->getRecipe ($ package , $ recipeRef , $ recipeVersion );
126129
127130 if (null === $ originalRecipe ) {
128131 $ io ->writeError ([
@@ -134,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134137 return 1 ;
135138 }
136139
137- $ newRecipe = $ this ->getRecipe ($ packageName );
140+ $ newRecipe = $ this ->getRecipe ($ package );
138141
139142 if ($ newRecipe ->getRef () === $ originalRecipe ->getRef ()) {
140143 $ io ->write (sprintf ('This recipe for <info>%s</info> is already at the latest version. ' , $ packageName ));
@@ -259,13 +262,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
259262 return 0 ;
260263 }
261264
262- private function getRecipe (string $ packageName , string $ recipeRef = null , string $ recipeVersion = null ): ?Recipe
265+ private function getRecipe (Package $ package , string $ recipeRef = null , string $ recipeVersion = null ): ?Recipe
263266 {
264- $ installedRepo = $ this ->getComposer ()->getRepositoryManager ()->getLocalRepository ();
265- $ package = $ installedRepo ->findPackage ($ packageName , '* ' );
266- if (null === $ package ) {
267- throw new RuntimeException (sprintf ('Could not find package "%s". Try running "composer install". ' , $ packageName ));
268- }
269267 $ operation = new InformationOperation ($ package );
270268 if (null !== $ recipeRef ) {
271269 $ operation ->setSpecificRecipeVersion ($ recipeRef , $ recipeVersion );
@@ -278,10 +276,10 @@ private function getRecipe(string $packageName, string $recipeRef = null, string
278276
279277 return new Recipe (
280278 $ package ,
281- $ packageName ,
279+ $ package -> getName () ,
282280 $ operation ->getOperationType (),
283- $ recipes ['manifests ' ][$ packageName ],
284- $ recipes ['locks ' ][$ packageName ] ?? []
281+ $ recipes ['manifests ' ][$ package -> getName () ],
282+ $ recipes ['locks ' ][$ package -> getName () ] ?? []
285283 );
286284 }
287285
@@ -358,19 +356,13 @@ private function generateChangelog(Recipe $originalRecipe): ?array
358356 private function askForPackage (IOInterface $ io , Lock $ symfonyLock ): ?string
359357 {
360358 $ installedRepo = $ this ->getComposer ()->getRepositoryManager ()->getLocalRepository ();
361- $ locker = $ this ->getComposer ()->getLocker ();
362- $ lockData = $ locker ->getLockData ();
363-
364- // Merge all packages installed
365- $ packages = array_merge ($ lockData ['packages ' ], $ lockData ['packages-dev ' ]);
366359
367360 $ operations = [];
368- foreach ($ packages as $ value ) {
369- if (null === $ pkg = $ installedRepo ->findPackage ($ value ['name ' ], '* ' )) {
370- continue ;
361+ foreach ($ symfonyLock ->all () as $ name => $ lock ) {
362+ if (isset ($ lock ['recipe ' ]['ref ' ])) {
363+ $ package = $ installedRepo ->findPackage ($ name , '* ' ) ?? new Package ($ name , $ lock ['version ' ], $ lock ['version ' ]);
364+ $ operations [] = new InformationOperation ($ package );
371365 }
372-
373- $ operations [] = new InformationOperation ($ pkg );
374366 }
375367
376368 $ recipes = $ this ->flex ->fetchRecipes ($ operations , false );
0 commit comments