Skip to content

Commit da754e2

Browse files
committed
Update react/promise
1 parent cbdc933 commit da754e2

File tree

8 files changed

+28
-43
lines changed

8 files changed

+28
-43
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"react/dns": "^1.10",
3333
"react/event-loop": "^1.2",
3434
"react/http": "^1.1",
35-
"react/promise": "^2.8",
35+
"react/promise": "^3.2",
3636
"react/socket": "^1.3",
3737
"react/stream": "^1.1",
3838
"symfony/console": "^5.4.3",

composer.lock

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline.neon

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,6 @@ parameters:
139139
count: 1
140140
path: src/Command/ErrorsConsoleStyle.php
141141

142-
-
143-
message: "#^Call to an undefined method React\\\\Promise\\\\PromiseInterface\\<Psr\\\\Http\\\\Message\\\\ResponseInterface\\>\\:\\:done\\(\\)\\.$#"
144-
count: 1
145-
path: src/Command/FixerApplication.php
146-
147-
-
148-
message: "#^Unable to resolve the template type T in call to function React\\\\Async\\\\await$#"
149-
count: 1
150-
path: src/Command/FixerApplication.php
151-
152-
-
153-
message: "#^Call to an undefined method React\\\\Promise\\\\PromiseInterface\\<React\\\\Socket\\\\ConnectionInterface\\>\\:\\:done\\(\\)\\.$#"
154-
count: 1
155-
path: src/Command/FixerWorkerCommand.php
156-
157-
-
158-
message: "#^Call to an undefined method React\\\\Promise\\\\PromiseInterface\\<React\\\\Socket\\\\ConnectionInterface\\>\\:\\:done\\(\\)\\.$#"
159-
count: 1
160-
path: src/Command/WorkerCommand.php
161-
162142
-
163143
message: "#^Variable method call on Nette\\\\Schema\\\\Elements\\\\AnyOf\\|Nette\\\\Schema\\\\Elements\\\\Structure\\|Nette\\\\Schema\\\\Elements\\\\Type\\.$#"
164144
count: 1

src/Command/FixerApplication.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
use React\EventLoop\LoopInterface;
3030
use React\EventLoop\StreamSelectLoop;
3131
use React\Http\Browser;
32-
use React\Promise\CancellablePromiseInterface;
33-
use React\Promise\ExtendedPromiseInterface;
32+
use React\Promise\PromiseInterface;
3433
use React\Socket\ConnectionInterface;
3534
use React\Socket\Connector;
3635
use React\Socket\TcpServer;
@@ -64,8 +63,8 @@
6463
class FixerApplication
6564
{
6665

67-
/** @var (ExtendedPromiseInterface&CancellablePromiseInterface)|null */
68-
private $processInProgress;
66+
/** @var PromiseInterface<string>|null */
67+
private PromiseInterface|null $processInProgress = null;
6968

7069
private bool $fileMonitorActive = true;
7170

@@ -348,7 +347,7 @@ private function downloadPhar(
348347
throw new ShouldNotHappenException(sprintf('Could not open file %s for writing.', $pharPath));
349348
}
350349
$progressBar = new ProgressBar($output);
351-
$client->requestStreaming('GET', $latestInfo['url'])->done(static function (ResponseInterface $response) use ($progressBar, $pharPathResource): void {
350+
$client->requestStreaming('GET', $latestInfo['url'])->then(static function (ResponseInterface $response) use ($progressBar, $pharPathResource): void {
352351
$body = $response->getBody();
353352
if (!$body instanceof ReadableStreamInterface) {
354353
throw new ShouldNotHappenException();
@@ -470,7 +469,7 @@ private function analyse(
470469
));
471470
$this->processInProgress = $process->run();
472471

473-
$this->processInProgress->done(function () use ($server): void {
472+
$this->processInProgress->then(function () use ($server): void {
474473
$this->processInProgress = null;
475474
$server->close();
476475
}, function (Throwable $e) use ($server, $output, $phpstanFixerEncoder): void {

src/Command/FixerWorkerCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
123123

124124
$loop = new StreamSelectLoop();
125125
$tcpConnector = new TcpConnector($loop);
126-
$tcpConnector->connect(sprintf('127.0.0.1:%d', $serverPort))->done(function (ConnectionInterface $connection) use ($container, $inceptionResult, $configuration, $input, $ignoredErrorHelperResult, $loop): void {
126+
$tcpConnector->connect(sprintf('127.0.0.1:%d', $serverPort))->then(function (ConnectionInterface $connection) use ($container, $inceptionResult, $configuration, $input, $ignoredErrorHelperResult, $loop): void {
127127
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
128128
$jsonInvalidUtf8Ignore = defined('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0;
129129
// phpcs:enable
@@ -314,6 +314,7 @@ private function filterErrors(array $errors, IgnoredErrorHelperResult $ignoredEr
314314
/**
315315
* @param string[] $files
316316
* @param callable(list<Error>, list<Error>, string[]): void $onFileAnalysisHandler
317+
* @return PromiseInterface<AnalyserResult>
317318
*/
318319
private function runAnalyser(LoopInterface $loop, Container $container, array $files, ?string $configuration, InputInterface $input, callable $onFileAnalysisHandler): PromiseInterface
319320
{

src/Command/WorkerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
126126
$analysedFiles = array_fill_keys($analysedFiles, true);
127127

128128
$tcpConnector = new TcpConnector($loop);
129-
$tcpConnector->connect(sprintf('127.0.0.1:%d', $port))->done(function (ConnectionInterface $connection) use ($container, $identifier, $output, $analysedFiles): void {
129+
$tcpConnector->connect(sprintf('127.0.0.1:%d', $port))->then(function (ConnectionInterface $connection) use ($container, $identifier, $output, $analysedFiles): void {
130130
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
131131
$jsonInvalidUtf8Ignore = defined('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0;
132132
// phpcs:enable

src/Parallel/ParallelAnalyser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function __construct(
5454
/**
5555
* @param Closure(int ): void|null $postFileCallback
5656
* @param (callable(list<Error>, list<Error>, string[]): void)|null $onFileAnalysisHandler
57+
* @return PromiseInterface<AnalyserResult>
5758
*/
5859
public function analyse(
5960
LoopInterface $loop,
@@ -83,6 +84,7 @@ public function analyse(
8384
$reachedInternalErrorsCountLimit = false;
8485
$exportedNodes = [];
8586

87+
/** @var Deferred<AnalyserResult> $deferred */
8688
$deferred = new Deferred();
8789

8890
$server = new TcpServer('127.0.0.1:0', $loop);

src/Process/ProcessPromise.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
use PHPStan\ShouldNotHappenException;
66
use React\ChildProcess\Process;
77
use React\EventLoop\LoopInterface;
8-
use React\Promise\CancellablePromiseInterface;
98
use React\Promise\Deferred;
10-
use React\Promise\ExtendedPromiseInterface;
9+
use React\Promise\PromiseInterface;
1110
use function fclose;
1211
use function rewind;
1312
use function stream_get_contents;
@@ -16,6 +15,7 @@
1615
class ProcessPromise
1716
{
1817

18+
/** @var Deferred<string> */
1919
private Deferred $deferred;
2020

2121
private ?Process $process = null;
@@ -33,9 +33,9 @@ public function getName(): string
3333
}
3434

3535
/**
36-
* @return ExtendedPromiseInterface&CancellablePromiseInterface
36+
* @return PromiseInterface<string>
3737
*/
38-
public function run(): CancellablePromiseInterface
38+
public function run(): PromiseInterface
3939
{
4040
$tmpStdOutResource = tmpfile();
4141
if ($tmpStdOutResource === false) {
@@ -72,14 +72,16 @@ public function run(): CancellablePromiseInterface
7272
}
7373

7474
if ($exitCode === 0) {
75+
if ($stdOut === false) {
76+
$stdOut = '';
77+
}
7578
$this->deferred->resolve($stdOut);
7679
return;
7780
}
7881

7982
$this->deferred->reject(new ProcessCrashedException($stdOut . $stdErr));
8083
});
8184

82-
/** @var ExtendedPromiseInterface&CancellablePromiseInterface */
8385
return $this->deferred->promise();
8486
}
8587

0 commit comments

Comments
 (0)