From 45977c7cb11f8809d5c0ef53e9e07f645858dec4 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 6 Jun 2023 15:25:54 +0200 Subject: [PATCH] refactor: update `SyncHelper` (#11485) Get rid of 3 PHPStan issues --- phpstan/baseline.neon | 15 --------------- src/Composer/Util/SyncHelper.php | 6 +++--- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index a82930c7d..11534f149 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -4933,21 +4933,6 @@ parameters: count: 1 path: ../src/Composer/Util/Svn.php - - - message: "#^Only booleans are allowed in a ternary operator condition, Composer\\\\Package\\\\PackageInterface\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/SyncHelper.php - - - - message: "#^Only booleans are allowed in an if condition, React\\\\Promise\\\\PromiseInterface\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/SyncHelper.php - - - - message: "#^Parameter \\#2 \\$target of method Composer\\\\Downloader\\\\DownloaderInterface\\:\\:update\\(\\) expects Composer\\\\Package\\\\PackageInterface, Composer\\\\Package\\\\PackageInterface\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/SyncHelper.php - - message: "#^Only booleans are allowed in &&, array\\ given on the left side\\.$#" count: 1 diff --git a/src/Composer/Util/SyncHelper.php b/src/Composer/Util/SyncHelper.php index 198169212..766dc6ce3 100644 --- a/src/Composer/Util/SyncHelper.php +++ b/src/Composer/Util/SyncHelper.php @@ -31,14 +31,14 @@ class SyncHelper */ public static function downloadAndInstallPackageSync(Loop $loop, DownloaderInterface $downloader, string $path, PackageInterface $package, ?PackageInterface $prevPackage = null): void { - $type = $prevPackage ? 'update' : 'install'; + $type = $prevPackage !== null ? 'update' : 'install'; try { self::await($loop, $downloader->download($package, $path, $prevPackage)); self::await($loop, $downloader->prepare($type, $package, $path, $prevPackage)); - if ($type === 'update') { + if ($type === 'update' && $prevPackage !== null) { self::await($loop, $downloader->update($package, $prevPackage, $path)); } else { self::await($loop, $downloader->install($package, $path)); @@ -58,7 +58,7 @@ class SyncHelper */ public static function await(Loop $loop, ?PromiseInterface $promise = null): void { - if ($promise) { + if ($promise !== null) { $loop->wait([$promise]); } }