Skip to content

Commit

Permalink
Apply style fixer to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 29, 2023
1 parent 3804e3b commit ee45d5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

$config = new Amp\CodeStyle\Config;
$config->getFinder()
->in(__DIR__ . '/examples')
->in(__DIR__ . '/src')
->in(__DIR__ . '/test')
->in(__DIR__ . '/test-autobahn');
Expand Down
9 changes: 4 additions & 5 deletions examples/broadcast-server/server.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

// Note that this example requires amphp/http-server-router,
// amphp/http-server-static-content and amphp/log to be installed.
Expand All @@ -20,7 +20,6 @@
use Amp\Websocket\Server\WebsocketGateway;
use Amp\Websocket\WebsocketClient;
use Monolog\Logger;
use Psr\Log\NullLogger;
use function Amp\ByteStream\getStdout;

require __DIR__ . '/../../vendor/autoload.php';
Expand Down Expand Up @@ -50,7 +49,7 @@ public function handleClient(WebsocketClient $client, Request $request, Response
$this->gateway->addClient($client);

while ($message = $client->receive()) {
$this->gateway->broadcastText(\sprintf('%d: %s', $client->getId(), (string) $message))->ignore();
$this->gateway->broadcastText(sprintf('%d: %s', $client->getId(), (string) $message))->ignore();
}
}
};
Expand All @@ -65,7 +64,7 @@ public function handleClient(WebsocketClient $client, Request $request, Response

$errorHandler = new DefaultErrorHandler();

$router = new Router($server, new NullLogger(), $errorHandler);
$router = new Router($server, $logger, $errorHandler);
$router->addRoute('GET', '/broadcast', $websocket);
$router->setFallback(new DocumentRoot($server, $errorHandler, __DIR__ . '/public'));

Expand All @@ -74,6 +73,6 @@ public function handleClient(WebsocketClient $client, Request $request, Response
// Await SIGINT or SIGTERM to be received.
$signal = Amp\trapSignal([\SIGINT, \SIGTERM]);

$logger->info(\sprintf("Received signal %d, stopping HTTP server", $signal));
$logger->info(sprintf("Received signal %d, stopping HTTP server", $signal));

$server->stop();
13 changes: 6 additions & 7 deletions examples/stackexchange-questions/server.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

// Note that this example requires amphp/http-client, amphp/http-server-router,
// amphp/http-server-static-content and amphp/log to be installed.
Expand All @@ -22,7 +22,6 @@
use Amp\Websocket\Server\WebsocketGateway;
use Amp\Websocket\WebsocketClient;
use Monolog\Logger;
use Psr\Log\NullLogger;
use Revolt\EventLoop;
use function Amp\ByteStream\getStdout;

Expand Down Expand Up @@ -65,16 +64,16 @@ private function onStart(): void
);
$json = $response->getBody()->buffer();

$data = \json_decode($json, true);
$data = json_decode($json, true);

if (!isset($data['items'])) {
return;
}

foreach (\array_reverse($data['items']) as $question) {
foreach (array_reverse($data['items']) as $question) {
if ($this->newestQuestion === null || $question['question_id'] > $this->newestQuestion) {
$this->newestQuestion = $question['question_id'];
$this->gateway->broadcastText(\json_encode($question))->ignore();
$this->gateway->broadcastText(json_encode($question))->ignore();
}
}
});
Expand Down Expand Up @@ -104,7 +103,7 @@ public function handleClient(WebsocketClient $client, Request $request, Response
clientHandler: $clientHandler,
);

$router = new Router($server, new NullLogger(), $errorHandler);
$router = new Router($server, $logger, $errorHandler);
$router->addRoute('GET', '/live', $websocket);
$router->setFallback(new DocumentRoot($server, $errorHandler, __DIR__ . '/public'));

Expand All @@ -113,6 +112,6 @@ public function handleClient(WebsocketClient $client, Request $request, Response
// Await SIGINT or SIGTERM to be received.
$signal = Amp\trapSignal([\SIGINT, \SIGTERM]);

$logger->info(\sprintf("Received signal %d, stopping HTTP server", $signal));
$logger->info(sprintf("Received signal %d, stopping HTTP server", $signal));

$server->stop();

0 comments on commit ee45d5a

Please sign in to comment.