Skip to content

Commit f825f13

Browse files
committed
Created alternative solution for pull request #119 where the same thing is achieved but without needing to pass Composer instance through different function parameters, should solve #118
1 parent e1422d7 commit f825f13

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/Compatibility/Executor.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Vaimo\ComposerPatches\Compatibility;
77

8+
use Vaimo\ComposerPatches\Exceptions\OperationFailure;
89
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
910
use Composer\Repository\WritableRepositoryInterface;
1011
use Composer\DependencyResolver\Operation\InstallOperation;
@@ -82,15 +83,28 @@ public function processReinstallOperation(
8283
return $installationManager->install($repository, $installOperation);
8384
}
8485

85-
return $installationManager
86-
->uninstall($repository, $uninstallOperation)
87-
->then(function () use ($installationManager, $installOperation, $repository) {
88-
$package = $installOperation->getPackage();
89-
$installationManager->getInstaller($package->getType())
90-
->download($package)
91-
->then(function () use ($installationManager, $installOperation, $repository) {
92-
$installationManager->install($repository, $installOperation);
93-
});
94-
});
86+
$package = $installOperation->getPackage();
87+
$installer = $installationManager->getInstaller($package->getType());
88+
89+
$uninstallPromise = $installationManager->uninstall($repository, $uninstallOperation);
90+
if (!$uninstallPromise) {
91+
throw new OperationFailure(sprintf('Uninstallation of %s failed', $package->getName()));
92+
}
93+
94+
$downloadPromise = $installer->download($package);
95+
if (!$downloadPromise) {
96+
throw new OperationFailure(sprintf('Download of %s failed', $package->getName()));
97+
}
98+
99+
$promise = \React\Promise\all([$uninstallPromise, $downloadPromise]);
100+
101+
return $promise->then(static function () use ($installationManager, $installOperation, $repository, $package) {
102+
$installPromise = $installationManager->install($repository, $installOperation);
103+
if (!$installPromise) {
104+
throw new OperationFailure(sprintf('Install of %s failed', $package->getName()));
105+
}
106+
107+
return $installPromise->then(static function () {});
108+
});
95109
}
96110
}

0 commit comments

Comments
 (0)