Skip to content

Commit

Permalink
Move to react/async
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 22, 2022
1 parent 81de3eb commit 3df3166
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 77 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -7,7 +7,6 @@
"require": {
"php": "^8.0",
"composer-runtime-api": "^2.0",
"clue/block-react": "^1.4",
"clue/ndjson-react": "^1.0",
"composer/ca-bundle": "^1.2",
"composer/xdebug-handler": "^3.0.3",
Expand All @@ -26,6 +25,7 @@
"ondrejmirtes/better-reflection": "5.8.0.1",
"phpstan/php-8-stubs": "0.3.37",
"phpstan/phpdoc-parser": "1.8.0",
"react/async": "^3",
"react/child-process": "^0.6.4",
"react/event-loop": "^1.2",
"react/http": "^1.1",
Expand Down
145 changes: 76 additions & 69 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions src/Command/FixerApplication.php
Expand Up @@ -32,6 +32,7 @@
use PHPStan\ShouldNotHappenException;
use Psr\Http\Message\ResponseInterface;
use React\ChildProcess\Process;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use React\EventLoop\StreamSelectLoop;
use React\Http\Browser;
Expand All @@ -47,7 +48,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
use function Clue\React\Block\await;
use function count;
use function defined;
use function escapeshellarg;
Expand All @@ -63,6 +63,7 @@
use function min;
use function mkdir;
use function parse_url;
use function React\Async\await;
use function React\Promise\resolve;
use function sprintf;
use function strlen;
Expand Down Expand Up @@ -363,11 +364,8 @@ private function downloadPhar(
$output->writeln('<fg=green>Checking if there\'s a new PHPStan Pro release...</>');
}

$loop = new StreamSelectLoop();
$client = new Browser(
$loop,
new Connector(
$loop,
[
'timeout' => 5,
'tls' => [
Expand All @@ -380,9 +378,8 @@ private function downloadPhar(

/**
* @var array{url: string, version: string} $latestInfo
* @phpstan-ignore-next-line
*/
$latestInfo = Json::decode((string) await($client->get(sprintf('https://fixer-download-api.phpstan.com/latest?%s', http_build_query(['phpVersion' => PHP_VERSION_ID]))), $loop, 5.0)->getBody(), Json::FORCE_ARRAY);
$latestInfo = Json::decode((string) await($client->get(sprintf('https://fixer-download-api.phpstan.com/latest?%s', http_build_query(['phpVersion' => PHP_VERSION_ID]))))->getBody(), Json::FORCE_ARRAY);
if ($currentVersion !== null && $latestInfo['version'] === $currentVersion) {
$this->writeInfoFile($infoPath, $latestInfo['version']);
$output->writeln('<fg=green>You\'re running the latest PHPStan Pro!</>');
Expand Down Expand Up @@ -417,7 +414,7 @@ private function downloadPhar(
$output->writeln(sprintf('<fg=red>Could not download the PHPStan Pro executable:</> %s', $e->getMessage()));
});

$loop->run();
Loop::run();

fclose($pharPathResource);

Expand Down

0 comments on commit 3df3166

Please sign in to comment.