1
0
Fork 0

Upgrade to react/promise 3.0.0 (#10429)

pull/11536/head
Jordi Boggiano 2023-07-20 12:52:28 +02:00 committed by GitHub
parent c1f2964105
commit e7016b00a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 93 additions and 45 deletions

View File

@ -37,7 +37,7 @@
"symfony/filesystem": "^5.4 || ^6.0 || ^7", "symfony/filesystem": "^5.4 || ^6.0 || ^7",
"symfony/finder": "^5.4 || ^6.0 || ^7", "symfony/finder": "^5.4 || ^6.0 || ^7",
"symfony/process": "^5.4 || ^6.0 || ^7", "symfony/process": "^5.4 || ^6.0 || ^7",
"react/promise": "^2.8", "react/promise": "^2.8 || ^3",
"composer/pcre": "^2.1 || ^3.1", "composer/pcre": "^2.1 || ^3.1",
"symfony/polyfill-php73": "^1.24", "symfony/polyfill-php73": "^1.24",
"symfony/polyfill-php80": "^1.24", "symfony/polyfill-php80": "^1.24",

29
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c50c89580fa044b7523cb55c2d557c87", "content-hash": "4bceaf933dcf6bc05808134e78d21496",
"packages": [ "packages": [
{ {
"name": "composer/ca-bundle", "name": "composer/ca-bundle",
@ -692,23 +692,24 @@
}, },
{ {
"name": "react/promise", "name": "react/promise",
"version": "v2.10.0", "version": "v3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/reactphp/promise.git", "url": "https://github.com/reactphp/promise.git",
"reference": "f913fb8cceba1e6644b7b90c4bfb678ed8a3ef38" "reference": "c86753c76fd3be465d93b308f18d189f01a22be4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/reactphp/promise/zipball/f913fb8cceba1e6644b7b90c4bfb678ed8a3ef38", "url": "https://api.github.com/repos/reactphp/promise/zipball/c86753c76fd3be465d93b308f18d189f01a22be4",
"reference": "f913fb8cceba1e6644b7b90c4bfb678ed8a3ef38", "reference": "c86753c76fd3be465d93b308f18d189f01a22be4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.4.0" "php": ">=7.1.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.36" "phpstan/phpstan": "1.10.20 || 1.4.10",
"phpunit/phpunit": "^9.5 || ^7.5"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -752,7 +753,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/reactphp/promise/issues", "issues": "https://github.com/reactphp/promise/issues",
"source": "https://github.com/reactphp/promise/tree/v2.10.0" "source": "https://github.com/reactphp/promise/tree/v3.0.0"
}, },
"funding": [ "funding": [
{ {
@ -760,7 +761,7 @@
"type": "open_collective" "type": "open_collective"
} }
], ],
"time": "2023-05-02T15:15:43+00:00" "time": "2023-07-11T16:12:49+00:00"
}, },
{ {
"name": "seld/jsonlint", "name": "seld/jsonlint",
@ -2034,16 +2035,16 @@
"packages-dev": [ "packages-dev": [
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "1.10.25", "version": "1.10.26",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "578f4e70d117f9a90699324c555922800ac38d8c" "reference": "5d660cbb7e1b89253a47147ae44044f49832351f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/578f4e70d117f9a90699324c555922800ac38d8c", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5d660cbb7e1b89253a47147ae44044f49832351f",
"reference": "578f4e70d117f9a90699324c555922800ac38d8c", "reference": "5d660cbb7e1b89253a47147ae44044f49832351f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2092,7 +2093,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-07-06T12:11:37+00:00" "time": "2023-07-19T12:44:37+00:00"
}, },
{ {
"name": "phpstan/phpstan-deprecation-rules", "name": "phpstan/phpstan-deprecation-rules",

View File

@ -1665,6 +1665,11 @@ parameters:
count: 3 count: 3
path: ../src/Composer/Downloader/FileDownloader.php path: ../src/Composer/Downloader/FileDownloader.php
-
message: "#^Strict comparison using \\=\\=\\= between null and Composer\\\\Util\\\\Http\\\\Response will always evaluate to false\\.$#"
count: 1
path: ../src/Composer/Downloader/FileDownloader.php
- -
message: "#^Parameter \\#3 \\$cwd of method Composer\\\\Util\\\\ProcessExecutor\\:\\:execute\\(\\) expects string\\|null, string\\|false given\\.$#" message: "#^Parameter \\#3 \\$cwd of method Composer\\\\Util\\\\ProcessExecutor\\:\\:execute\\(\\) expects string\\|null, string\\|false given\\.$#"
count: 5 count: 5
@ -2305,11 +2310,6 @@ parameters:
count: 1 count: 1
path: ../src/Composer/Installer/InstallationManager.php path: ../src/Composer/Installer/InstallationManager.php
-
message: "#^Only booleans are allowed in an if condition, React\\\\Promise\\\\PromiseInterface\\|null given\\.$#"
count: 1
path: ../src/Composer/Installer/InstallationManager.php
- -
message: "#^Only booleans are allowed in an if condition, Symfony\\\\Component\\\\Console\\\\Helper\\\\ProgressBar\\|null given\\.$#" message: "#^Only booleans are allowed in an if condition, Symfony\\\\Component\\\\Console\\\\Helper\\\\ProgressBar\\|null given\\.$#"
count: 1 count: 1

View File

@ -216,6 +216,7 @@ abstract class ArchiveDownloader extends FileDownloader
* *
* @param string $file Extracted file * @param string $file Extracted file
* @param string $path Directory * @param string $path Directory
* @phpstan-return PromiseInterface<void|null>
* *
* @throws \UnexpectedValueException If can not extract downloaded file to path * @throws \UnexpectedValueException If can not extract downloaded file to path
*/ */

View File

@ -174,6 +174,7 @@ class DownloadManager
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $targetDir target dir * @param string $targetDir target dir
* @param PackageInterface|null $prevPackage previous package instance in case of updates * @param PackageInterface|null $prevPackage previous package instance in case of updates
* @phpstan-return PromiseInterface<void|null>
* *
* @throws \InvalidArgumentException if package have no urls to download from * @throws \InvalidArgumentException if package have no urls to download from
* @throws \RuntimeException * @throws \RuntimeException
@ -241,6 +242,7 @@ class DownloadManager
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $targetDir target dir * @param string $targetDir target dir
* @param PackageInterface|null $prevPackage previous package instance in case of updates * @param PackageInterface|null $prevPackage previous package instance in case of updates
* @phpstan-return PromiseInterface<void|null>
*/ */
public function prepare(string $type, PackageInterface $package, string $targetDir, ?PackageInterface $prevPackage = null): PromiseInterface public function prepare(string $type, PackageInterface $package, string $targetDir, ?PackageInterface $prevPackage = null): PromiseInterface
{ {
@ -258,6 +260,7 @@ class DownloadManager
* *
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $targetDir target dir * @param string $targetDir target dir
* @phpstan-return PromiseInterface<void|null>
* *
* @throws \InvalidArgumentException if package have no urls to download from * @throws \InvalidArgumentException if package have no urls to download from
* @throws \RuntimeException * @throws \RuntimeException
@ -279,6 +282,7 @@ class DownloadManager
* @param PackageInterface $initial initial package version * @param PackageInterface $initial initial package version
* @param PackageInterface $target target package version * @param PackageInterface $target target package version
* @param string $targetDir target dir * @param string $targetDir target dir
* @phpstan-return PromiseInterface<void|null>
* *
* @throws \InvalidArgumentException if initial package is not installed * @throws \InvalidArgumentException if initial package is not installed
*/ */
@ -328,6 +332,7 @@ class DownloadManager
* *
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $targetDir target dir * @param string $targetDir target dir
* @phpstan-return PromiseInterface<void|null>
*/ */
public function remove(PackageInterface $package, string $targetDir): PromiseInterface public function remove(PackageInterface $package, string $targetDir): PromiseInterface
{ {
@ -347,6 +352,7 @@ class DownloadManager
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $targetDir target dir * @param string $targetDir target dir
* @param PackageInterface|null $prevPackage previous package instance in case of updates * @param PackageInterface|null $prevPackage previous package instance in case of updates
* @phpstan-return PromiseInterface<void|null>
*/ */
public function cleanup(string $type, PackageInterface $package, string $targetDir, ?PackageInterface $prevPackage = null): PromiseInterface public function cleanup(string $type, PackageInterface $package, string $targetDir, ?PackageInterface $prevPackage = null): PromiseInterface
{ {

View File

@ -34,6 +34,7 @@ interface DownloaderInterface
* This should do any network-related tasks to prepare for an upcoming install/update * This should do any network-related tasks to prepare for an upcoming install/update
* *
* @param string $path download path * @param string $path download path
* @phpstan-return PromiseInterface<void|null|string>
*/ */
public function download(PackageInterface $package, string $path, ?PackageInterface $prevPackage = null): PromiseInterface; public function download(PackageInterface $package, string $path, ?PackageInterface $prevPackage = null): PromiseInterface;
@ -49,6 +50,7 @@ interface DownloaderInterface
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path download path * @param string $path download path
* @param PackageInterface $prevPackage previous package instance in case of an update * @param PackageInterface $prevPackage previous package instance in case of an update
* @phpstan-return PromiseInterface<void|null>
*/ */
public function prepare(string $type, PackageInterface $package, string $path, ?PackageInterface $prevPackage = null): PromiseInterface; public function prepare(string $type, PackageInterface $package, string $path, ?PackageInterface $prevPackage = null): PromiseInterface;
@ -57,6 +59,7 @@ interface DownloaderInterface
* *
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path download path * @param string $path download path
* @phpstan-return PromiseInterface<void|null>
*/ */
public function install(PackageInterface $package, string $path): PromiseInterface; public function install(PackageInterface $package, string $path): PromiseInterface;
@ -66,6 +69,7 @@ interface DownloaderInterface
* @param PackageInterface $initial initial package * @param PackageInterface $initial initial package
* @param PackageInterface $target updated package * @param PackageInterface $target updated package
* @param string $path download path * @param string $path download path
* @phpstan-return PromiseInterface<void|null>
*/ */
public function update(PackageInterface $initial, PackageInterface $target, string $path): PromiseInterface; public function update(PackageInterface $initial, PackageInterface $target, string $path): PromiseInterface;
@ -74,6 +78,7 @@ interface DownloaderInterface
* *
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path download path * @param string $path download path
* @phpstan-return PromiseInterface<void|null>
*/ */
public function remove(PackageInterface $package, string $path): PromiseInterface; public function remove(PackageInterface $package, string $path): PromiseInterface;
@ -88,6 +93,7 @@ interface DownloaderInterface
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path download path * @param string $path download path
* @param PackageInterface $prevPackage previous package instance in case of an update * @param PackageInterface $prevPackage previous package instance in case of an update
* @phpstan-return PromiseInterface<void|null>
*/ */
public function cleanup(string $type, PackageInterface $package, string $path, ?PackageInterface $prevPackage = null): PromiseInterface; public function cleanup(string $type, PackageInterface $package, string $path, ?PackageInterface $prevPackage = null): PromiseInterface;
} }

View File

@ -536,6 +536,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
} }
/** /**
* @phpstan-return PromiseInterface<void|null>
* @throws \RuntimeException * @throws \RuntimeException
*/ */
protected function discardChanges(string $path): PromiseInterface protected function discardChanges(string $path): PromiseInterface
@ -551,6 +552,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
} }
/** /**
* @phpstan-return PromiseInterface<void|null>
* @throws \RuntimeException * @throws \RuntimeException
*/ */
protected function stashChanges(string $path): PromiseInterface protected function stashChanges(string $path): PromiseInterface

View File

@ -230,6 +230,9 @@ class SvnDownloader extends VcsDownloader
return "Could not retrieve changes between $fromReference and $toReference due to missing revision information"; return "Could not retrieve changes between $fromReference and $toReference due to missing revision information";
} }
/**
* @phpstan-return PromiseInterface<void|null>
*/
protected function discardChanges(string $path): PromiseInterface protected function discardChanges(string $path): PromiseInterface
{ {
if (0 !== $this->process->execute('svn revert -R .', $output, $path)) { if (0 !== $this->process->execute('svn revert -R .', $output, $path)) {

View File

@ -259,6 +259,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* if false (remove) the changes should be assumed to be lost if the operation is not aborted * if false (remove) the changes should be assumed to be lost if the operation is not aborted
* *
* @throws \RuntimeException in case the operation must be aborted * @throws \RuntimeException in case the operation must be aborted
* @phpstan-return PromiseInterface<void|null>
*/ */
protected function cleanChanges(PackageInterface $package, string $path, bool $update): PromiseInterface protected function cleanChanges(PackageInterface $package, string $path, bool $update): PromiseInterface
{ {
@ -286,6 +287,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param string $path download path * @param string $path download path
* @param string $url package url * @param string $url package url
* @param PackageInterface|null $prevPackage previous package (in case of an update) * @param PackageInterface|null $prevPackage previous package (in case of an update)
* @phpstan-return PromiseInterface<void|null>
*/ */
abstract protected function doDownload(PackageInterface $package, string $path, string $url, ?PackageInterface $prevPackage = null): PromiseInterface; abstract protected function doDownload(PackageInterface $package, string $path, string $url, ?PackageInterface $prevPackage = null): PromiseInterface;
@ -295,6 +297,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param string $path download path * @param string $path download path
* @param string $url package url * @param string $url package url
* @phpstan-return PromiseInterface<void|null>
*/ */
abstract protected function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface; abstract protected function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface;
@ -305,6 +308,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @param PackageInterface $target updated package * @param PackageInterface $target updated package
* @param string $path download path * @param string $path download path
* @param string $url package url * @param string $url package url
* @phpstan-return PromiseInterface<void|null>
*/ */
abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): PromiseInterface; abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): PromiseInterface;

View File

@ -105,6 +105,7 @@ class ZipDownloader extends ArchiveDownloader
* *
* @param string $file File to extract * @param string $file File to extract
* @param string $path Path where to extract file * @param string $path Path where to extract file
* @phpstan-return PromiseInterface<void|null>
*/ */
private function extractWithSystemUnzip(PackageInterface $package, string $file, string $path): PromiseInterface private function extractWithSystemUnzip(PackageInterface $package, string $file, string $path): PromiseInterface
{ {
@ -194,6 +195,7 @@ class ZipDownloader extends ArchiveDownloader
* *
* @param string $file File to extract * @param string $file File to extract
* @param string $path Path where to extract file * @param string $path Path where to extract file
* @phpstan-return PromiseInterface<void|null>
*/ */
private function extractWithZipArchive(PackageInterface $package, string $file, string $path): PromiseInterface private function extractWithZipArchive(PackageInterface $package, string $file, string $path): PromiseInterface
{ {

View File

@ -180,7 +180,7 @@ class InstallationManager
*/ */
public function execute(InstalledRepositoryInterface $repo, array $operations, bool $devMode = true, bool $runScripts = true, bool $downloadOnly = false): void public function execute(InstalledRepositoryInterface $repo, array $operations, bool $devMode = true, bool $runScripts = true, bool $downloadOnly = false): void
{ {
/** @var array<callable(): ?PromiseInterface> */ /** @var array<callable(): ?PromiseInterface<void|null>> */
$cleanupPromises = []; $cleanupPromises = [];
$signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) use (&$cleanupPromises) { $signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) use (&$cleanupPromises) {
@ -237,8 +237,8 @@ class InstallationManager
/** /**
* @param OperationInterface[] $operations List of operations to execute in this batch * @param OperationInterface[] $operations List of operations to execute in this batch
* @param array<callable(): ?PromiseInterface> $cleanupPromises
* @param OperationInterface[] $allOperations Complete list of operations to be executed in the install job, used for event listeners * @param OperationInterface[] $allOperations Complete list of operations to be executed in the install job, used for event listeners
* @phpstan-param array<callable(): ?PromiseInterface<void|null>> $cleanupPromises
*/ */
private function downloadAndExecuteBatch(InstalledRepositoryInterface $repo, array $operations, array &$cleanupPromises, bool $devMode, bool $runScripts, bool $downloadOnly, array $allOperations): void private function downloadAndExecuteBatch(InstalledRepositoryInterface $repo, array $operations, array &$cleanupPromises, bool $devMode, bool $runScripts, bool $downloadOnly, array $allOperations): void
{ {
@ -275,7 +275,7 @@ class InstallationManager
if ($opType !== 'uninstall') { if ($opType !== 'uninstall') {
$promise = $installer->download($package, $initialPackage); $promise = $installer->download($package, $initialPackage);
if ($promise) { if (null !== $promise) {
$promises[] = $promise; $promises[] = $promise;
} }
} }
@ -322,8 +322,8 @@ class InstallationManager
/** /**
* @param OperationInterface[] $operations List of operations to execute in this batch * @param OperationInterface[] $operations List of operations to execute in this batch
* @param array<callable(): ?PromiseInterface> $cleanupPromises
* @param OperationInterface[] $allOperations Complete list of operations to be executed in the install job, used for event listeners * @param OperationInterface[] $allOperations Complete list of operations to be executed in the install job, used for event listeners
* @phpstan-param array<callable(): ?PromiseInterface<void|null>> $cleanupPromises
*/ */
private function executeBatch(InstalledRepositoryInterface $repo, array $operations, array $cleanupPromises, bool $devMode, bool $runScripts, array $allOperations): void private function executeBatch(InstalledRepositoryInterface $repo, array $operations, array $cleanupPromises, bool $devMode, bool $runScripts, array $allOperations): void
{ {
@ -413,7 +413,7 @@ class InstallationManager
} }
/** /**
* @param PromiseInterface[] $promises * @param array<PromiseInterface<void|null>> $promises
*/ */
private function waitOnPromises(array $promises): void private function waitOnPromises(array $promises): void
{ {
@ -440,7 +440,7 @@ class InstallationManager
/** /**
* Executes download operation. * Executes download operation.
* *
* $param PackageInterface $package * @phpstan-return PromiseInterface<void|null>|null
*/ */
public function download(PackageInterface $package): ?PromiseInterface public function download(PackageInterface $package): ?PromiseInterface
{ {
@ -455,6 +455,7 @@ class InstallationManager
* *
* @param InstalledRepositoryInterface $repo repository in which to check * @param InstalledRepositoryInterface $repo repository in which to check
* @param InstallOperation $operation operation instance * @param InstallOperation $operation operation instance
* @phpstan-return PromiseInterface<void|null>|null
*/ */
public function install(InstalledRepositoryInterface $repo, InstallOperation $operation): ?PromiseInterface public function install(InstalledRepositoryInterface $repo, InstallOperation $operation): ?PromiseInterface
{ {
@ -471,6 +472,7 @@ class InstallationManager
* *
* @param InstalledRepositoryInterface $repo repository in which to check * @param InstalledRepositoryInterface $repo repository in which to check
* @param UpdateOperation $operation operation instance * @param UpdateOperation $operation operation instance
* @phpstan-return PromiseInterface<void|null>|null
*/ */
public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation): ?PromiseInterface public function update(InstalledRepositoryInterface $repo, UpdateOperation $operation): ?PromiseInterface
{ {
@ -509,6 +511,7 @@ class InstallationManager
* *
* @param InstalledRepositoryInterface $repo repository in which to check * @param InstalledRepositoryInterface $repo repository in which to check
* @param UninstallOperation $operation operation instance * @param UninstallOperation $operation operation instance
* @phpstan-return PromiseInterface<void|null>|null
*/ */
public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation): ?PromiseInterface public function uninstall(InstalledRepositoryInterface $repo, UninstallOperation $operation): ?PromiseInterface
{ {
@ -638,8 +641,8 @@ class InstallationManager
} }
/** /**
* @param array<callable(): ?PromiseInterface> $cleanupPromises
* @return void * @return void
* @phpstan-param array<callable(): ?PromiseInterface<void|null>> $cleanupPromises
*/ */
private function runCleanup(array $cleanupPromises): void private function runCleanup(array $cleanupPromises): void
{ {
@ -648,7 +651,7 @@ class InstallationManager
$this->loop->abortJobs(); $this->loop->abortJobs();
foreach ($cleanupPromises as $cleanup) { foreach ($cleanupPromises as $cleanup) {
$promises[] = new \React\Promise\Promise(static function ($resolve, $reject) use ($cleanup): void { $promises[] = new \React\Promise\Promise(static function ($resolve) use ($cleanup): void {
$promise = $cleanup(); $promise = $cleanup();
if (!$promise instanceof PromiseInterface) { if (!$promise instanceof PromiseInterface) {
$resolve(); $resolve();

View File

@ -48,6 +48,7 @@ interface InstallerInterface
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param PackageInterface $prevPackage previous package instance in case of an update * @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface|null * @return PromiseInterface|null
* @phpstan-return PromiseInterface<void|null>|null
*/ */
public function download(PackageInterface $package, ?PackageInterface $prevPackage = null); public function download(PackageInterface $package, ?PackageInterface $prevPackage = null);
@ -63,6 +64,7 @@ interface InstallerInterface
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param PackageInterface $prevPackage previous package instance in case of an update * @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface|null * @return PromiseInterface|null
* @phpstan-return PromiseInterface<void|null>|null
*/ */
public function prepare(string $type, PackageInterface $package, ?PackageInterface $prevPackage = null); public function prepare(string $type, PackageInterface $package, ?PackageInterface $prevPackage = null);
@ -72,6 +74,7 @@ interface InstallerInterface
* @param InstalledRepositoryInterface $repo repository in which to check * @param InstalledRepositoryInterface $repo repository in which to check
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @return PromiseInterface|null * @return PromiseInterface|null
* @phpstan-return PromiseInterface<void|null>|null
*/ */
public function install(InstalledRepositoryInterface $repo, PackageInterface $package); public function install(InstalledRepositoryInterface $repo, PackageInterface $package);
@ -83,6 +86,7 @@ interface InstallerInterface
* @param PackageInterface $target updated version * @param PackageInterface $target updated version
* @throws InvalidArgumentException if $initial package is not installed * @throws InvalidArgumentException if $initial package is not installed
* @return PromiseInterface|null * @return PromiseInterface|null
* @phpstan-return PromiseInterface<void|null>|null
*/ */
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target); public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target);
@ -92,6 +96,7 @@ interface InstallerInterface
* @param InstalledRepositoryInterface $repo repository in which to check * @param InstalledRepositoryInterface $repo repository in which to check
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @return PromiseInterface|null * @return PromiseInterface|null
* @phpstan-return PromiseInterface<void|null>|null
*/ */
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package); public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package);
@ -106,6 +111,7 @@ interface InstallerInterface
* @param PackageInterface $package package instance * @param PackageInterface $package package instance
* @param PackageInterface $prevPackage previous package instance in case of an update * @param PackageInterface $prevPackage previous package instance in case of an update
* @return PromiseInterface|null * @return PromiseInterface|null
* @phpstan-return PromiseInterface<void|null>|null
*/ */
public function cleanup(string $type, PackageInterface $package, ?PackageInterface $prevPackage = null); public function cleanup(string $type, PackageInterface $package, ?PackageInterface $prevPackage = null);

View File

@ -272,6 +272,7 @@ class LibraryInstaller implements InstallerInterface, BinaryPresenceInterface
/** /**
* @return PromiseInterface|null * @return PromiseInterface|null
* @phpstan-return PromiseInterface<void|null>|null
*/ */
protected function installCode(PackageInterface $package) protected function installCode(PackageInterface $package)
{ {
@ -282,6 +283,7 @@ class LibraryInstaller implements InstallerInterface, BinaryPresenceInterface
/** /**
* @return PromiseInterface|null * @return PromiseInterface|null
* @phpstan-return PromiseInterface<void|null>|null
*/ */
protected function updateCode(PackageInterface $initial, PackageInterface $target) protected function updateCode(PackageInterface $initial, PackageInterface $target)
{ {
@ -316,6 +318,7 @@ class LibraryInstaller implements InstallerInterface, BinaryPresenceInterface
/** /**
* @return PromiseInterface|null * @return PromiseInterface|null
* @phpstan-return PromiseInterface<void|null>|null
*/ */
protected function removeCode(PackageInterface $package) protected function removeCode(PackageInterface $package)
{ {

View File

@ -322,9 +322,8 @@ class VersionGuesser
$prettyVersion = 'dev-' . $candidateVersion; $prettyVersion = 'dev-' . $candidateVersion;
if ($length === 0) { if ($length === 0) {
foreach ($promises as $promise) { foreach ($promises as $promise) {
if ($promise instanceof CancellablePromiseInterface) { // to support react/promise 2.x we wrap the promise in a resolve() call for safety
$promise->cancel(); \React\Promise\resolve($promise)->cancel();
}
} }
} }
} }

View File

@ -1070,6 +1070,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
return ['namesFound' => $namesFound, 'packages' => $packages]; return ['namesFound' => $namesFound, 'packages' => $packages];
} }
/**
* @phpstan-return PromiseInterface<array{mixed, string}>
*/
private function startCachedAsyncDownload(string $fileName, ?string $packageName = null): PromiseInterface private function startCachedAsyncDownload(string $fileName, ?string $packageName = null): PromiseInterface
{ {
if (null === $this->lazyProvidersUrl) { if (null === $this->lazyProvidersUrl) {
@ -1598,6 +1601,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
} }
} }
/**
* @phpstan-return PromiseInterface<array<mixed>|true> true if the response was a 304 and the cache is fresh, otherwise it returns the decoded json
*/
private function asyncFetchFile(string $filename, string $cacheKey, ?string $lastModifiedTime = null): PromiseInterface private function asyncFetchFile(string $filename, string $cacheKey, ?string $lastModifiedTime = null): PromiseInterface
{ {
if ('' === $filename) { if ('' === $filename) {
@ -1610,7 +1616,10 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
if (isset($this->freshMetadataUrls[$filename]) && $lastModifiedTime) { if (isset($this->freshMetadataUrls[$filename]) && $lastModifiedTime) {
// make it look like we got a 304 response // make it look like we got a 304 response
return \React\Promise\resolve(true); /** @var PromiseInterface<true> $promise */
$promise = \React\Promise\resolve(true);
return $promise;
} }
$httpDownloader = $this->httpDownloader; $httpDownloader = $this->httpDownloader;

View File

@ -133,6 +133,7 @@ class Filesystem
* *
* @throws \RuntimeException * @throws \RuntimeException
* @return PromiseInterface * @return PromiseInterface
* @phpstan-return PromiseInterface<bool>
*/ */
public function removeDirectoryAsync(string $directory) public function removeDirectoryAsync(string $directory)
{ {

View File

@ -28,7 +28,7 @@ use React\Promise\PromiseInterface;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
* @phpstan-type Request array{url: non-empty-string, options: mixed[], copyTo: string|null} * @phpstan-type Request array{url: non-empty-string, options: mixed[], copyTo: string|null}
* @phpstan-type Job array{id: int, status: int, request: Request, sync: bool, origin: string, resolve?: callable, reject?: callable, curl_id?: int, response?: Response, exception?: TransportException} * @phpstan-type Job array{id: int, status: int, request: Request, sync: bool, origin: string, resolve?: callable, reject?: callable, curl_id?: int, response?: Response, exception?: \Throwable}
*/ */
class HttpDownloader class HttpDownloader
{ {
@ -123,6 +123,7 @@ class HttpDownloader
* although not all options are supported when using the default curl downloader * although not all options are supported when using the default curl downloader
* @throws TransportException * @throws TransportException
* @return PromiseInterface * @return PromiseInterface
* @phpstan-return PromiseInterface<Http\Response>
*/ */
public function add(string $url, array $options = []) public function add(string $url, array $options = [])
{ {
@ -164,6 +165,7 @@ class HttpDownloader
* although not all options are supported when using the default curl downloader * although not all options are supported when using the default curl downloader
* @throws TransportException * @throws TransportException
* @return PromiseInterface * @return PromiseInterface
* @phpstan-return PromiseInterface<Http\Response>
*/ */
public function addCopy(string $url, string $to, array $options = []) public function addCopy(string $url, string $to, array $options = [])
{ {
@ -199,6 +201,7 @@ class HttpDownloader
/** /**
* @phpstan-param Request $request * @phpstan-param Request $request
* @return array{Job, PromiseInterface} * @return array{Job, PromiseInterface}
* @phpstan-return array{Job, PromiseInterface<Http\Response>}
*/ */
private function addJob(array $request, bool $sync = false): array private function addJob(array $request, bool $sync = false): array
{ {

View File

@ -25,7 +25,7 @@ class Loop
private $httpDownloader; private $httpDownloader;
/** @var ProcessExecutor|null */ /** @var ProcessExecutor|null */
private $processExecutor; private $processExecutor;
/** @var PromiseInterface[][] */ /** @var array<int, array<PromiseInterface<mixed>>> */
private $currentPromises = []; private $currentPromises = [];
/** @var int */ /** @var int */
private $waitIndex = 0; private $waitIndex = 0;
@ -52,18 +52,17 @@ class Loop
} }
/** /**
* @param PromiseInterface[] $promises * @param array<PromiseInterface<mixed>> $promises
* @param ?ProgressBar $progress * @param ProgressBar|null $progress
*/ */
public function wait(array $promises, ?ProgressBar $progress = null): void public function wait(array $promises, ?ProgressBar $progress = null): void
{ {
/** @var \Exception|null */
$uncaught = null; $uncaught = null;
\React\Promise\all($promises)->then( \React\Promise\all($promises)->then(
static function (): void { static function (): void {
}, },
static function ($e) use (&$uncaught): void { static function (\Throwable $e) use (&$uncaught): void {
$uncaught = $e; $uncaught = $e;
} }
); );
@ -107,7 +106,7 @@ class Loop
} }
unset($this->currentPromises[$waitIndex]); unset($this->currentPromises[$waitIndex]);
if ($uncaught) { if (null !== $uncaught) {
throw $uncaught; throw $uncaught;
} }
} }
@ -116,9 +115,8 @@ class Loop
{ {
foreach ($this->currentPromises as $promiseGroup) { foreach ($this->currentPromises as $promiseGroup) {
foreach ($promiseGroup as $promise) { foreach ($promiseGroup as $promise) {
if ($promise instanceof CancellablePromiseInterface) { // to support react/promise 2.x we wrap the promise in a resolve() call for safety
$promise->cancel(); \React\Promise\resolve($promise)->cancel();
}
} }
} }
} }

View File

@ -155,6 +155,7 @@ class ProcessExecutor
* *
* @param string|list<string> $command the command to execute * @param string|list<string> $command the command to execute
* @param string $cwd the working directory * @param string $cwd the working directory
* @phpstan-return PromiseInterface<Process>
*/ */
public function executeAsync($command, ?string $cwd = null): PromiseInterface public function executeAsync($command, ?string $cwd = null): PromiseInterface
{ {

View File

@ -58,6 +58,7 @@ class SyncHelper
* Waits for a promise to resolve * Waits for a promise to resolve
* *
* @param Loop $loop Loop instance which you can get from $composer->getLoop() * @param Loop $loop Loop instance which you can get from $composer->getLoop()
* @phpstan-param PromiseInterface<mixed>|null $promise
*/ */
public static function await(Loop $loop, ?PromiseInterface $promise = null): void public static function await(Loop $loop, ?PromiseInterface $promise = null): void
{ {

View File

@ -314,7 +314,7 @@ class ZipDownloaderTest extends TestCase
} }
/** /**
* @param ?\React\Promise\PromiseInterface $promise * @param ?\React\Promise\PromiseInterface<mixed> $promise
*/ */
private function wait($promise): void private function wait($promise): void
{ {
@ -329,7 +329,7 @@ class ZipDownloaderTest extends TestCase
$e = $ex; $e = $ex;
}); });
if ($e) { if ($e !== null) {
throw $e; throw $e;
} }
} }

View File

@ -120,7 +120,6 @@ class ProcessExecutorTest extends TestCase
$process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG)); $process = new ProcessExecutor($buffer = new BufferIO('', StreamOutput::VERBOSITY_DEBUG));
$process->enableAsync(); $process->enableAsync();
$start = microtime(true); $start = microtime(true);
/** @var Promise $promise */
$promise = $process->executeAsync('sleep 2'); $promise = $process->executeAsync('sleep 2');
$this->assertEquals(1, $process->countActiveJobs()); $this->assertEquals(1, $process->countActiveJobs());
$promise->cancel(); $promise->cancel();