Skip to content

Commit 91c763b

Browse files
committed
Fix code style for examples
1 parent 763ab7c commit 91c763b

File tree

18 files changed

+113
-71
lines changed

18 files changed

+113
-71
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/composer.lock
55
/vendor
66
.phpunit.result.cache
7+
.phpunit.cache/

benchmark/consumer.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
namespace Bunny;
46

5-
require_once __DIR__ . "/../vendor/autoload.php";
7+
use function getmypid;
8+
use function microtime;
9+
use function printf;
10+
11+
require_once __DIR__ . '/../vendor/autoload.php';
612

713
$c = new Client();
814
$ch = $c->connect()->channel();
915

10-
$ch->queueDeclare("bench_queue");
11-
$ch->exchangeDeclare("bench_exchange");
12-
$ch->queueBind("bench_exchange", "bench_queue");
16+
$ch->queueDeclare('bench_queue');
17+
$ch->exchangeDeclare('bench_exchange');
18+
$ch->queueBind('bench_exchange', 'bench_queue');
1319

1420
$t = null;
1521
$count = 0;
1622

17-
$ch->consume(function (Message $msg, Channel $ch, Client $c) use (&$t, &$count): void {
23+
$ch->consume(static function (Message $msg, Channel $ch, Client $c) use (&$t, &$count): void {
1824
if ($t === null) {
1925
$t = microtime(true);
2026
}
2127

22-
if ($msg->content === "quit") {
28+
if ($msg->content === 'quit') {
2329
printf("Pid: %s, Count: %s, Time: %.4f\n", getmypid(), $count, microtime(true) - $t);
2430
$c->disconnect();
2531
} else {
2632
++$count;
2733
}
28-
29-
}, "bench_queue", "", false, true);
34+
}, 'bench_queue', '', false, true);

benchmark/endian.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?php
22

3-
define("N", 1000000);
3+
declare(strict_types = 1);
44

5-
function swapEndian64Strrev($s): string
5+
define('N', 1000000);
6+
7+
function swapEndian64Strrev(string $s): string
68
{
79
return strrev($s);
810
}
911

10-
function swapEndian64Concat($s): string
12+
function swapEndian64Concat(string $s): string
1113
{
1214
return $s[7] . $s[6] . $s[5] . $s[4] . $s[3] . $s[2] . $s[1] . $s[0];
1315
}
1416

15-
function swapEndian64Index($s): string
17+
function swapEndian64Index(string $s): string
1618
{
17-
$rs = "00000000";
19+
$rs = '00000000';
1820
$rs[0] = $s[7];
1921
$rs[1] = $s[6];
2022
$rs[2] = $s[5];
@@ -23,25 +25,29 @@ function swapEndian64Index($s): string
2325
$rs[5] = $s[2];
2426
$rs[6] = $s[1];
2527
$rs[7] = $s[0];
28+
2629
return $rs;
2730
}
2831

29-
$s = pack("NN", 1, 1);
32+
$s = pack('NN', 1, 1);
3033

3134
$t = microtime(true);
3235
for ($i = 0; $i < N; ++$i) {
3336
swapEndian64Strrev($s);
3437
}
38+
3539
var_dump(microtime(true) - $t);
3640

3741
$t = microtime(true);
3842
for ($i = 0; $i < N; ++$i) {
3943
swapEndian64Concat($s);
4044
}
45+
4146
var_dump(microtime(true) - $t);
4247

4348
$t = microtime(true);
4449
for ($i = 0; $i < N; ++$i) {
4550
swapEndian64Index($s);
4651
}
52+
4753
var_dump(microtime(true) - $t);

benchmark/producer.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
namespace Bunny;
46

5-
require_once __DIR__ . "/../vendor/autoload.php";
7+
use function microtime;
8+
9+
require_once __DIR__ . '/../vendor/autoload.php';
610

711
$c = new Client();
812
$c->connect();
913
$ch = $c->channel();
1014

11-
$ch->queueDeclare("bench_queue");
12-
$ch->exchangeDeclare("bench_exchange");
13-
$ch->queueBind("bench_exchange", "bench_queue");
15+
$ch->queueDeclare('bench_queue');
16+
$ch->exchangeDeclare('bench_exchange');
17+
$ch->queueBind('bench_exchange', 'bench_queue');
1418

15-
$body = <<<EOT
19+
$body = <<<'EOT'
1620
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
1721
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
1822
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
@@ -29,11 +33,11 @@
2933
$max = isset($argv[1]) ? (int) $argv[1] : 1;
3034

3135
for ($i = 0; $i < $max; $i++) {
32-
$ch->publish($body, [], "bench_exchange");
36+
$ch->publish($body, [], 'bench_exchange');
3337
}
3438

3539
echo microtime(true) - $time, "\n";
3640

37-
$ch->publish("quit", [], "bench_exchange");
41+
$ch->publish('quit', [], 'bench_exchange');
3842

3943
$c->disconnect();

examples/ssl/05-client-verify-multiple-files.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@
2222
'passphrase' => 'passphrase-for-client.key',
2323
],
2424
];
25-

examples/worker.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3-
use Bunny\Client;
3+
declare(strict_types = 1);
4+
45
use Bunny\Channel;
6+
use Bunny\Client;
57
use Bunny\Message;
68
use React\EventLoop\Loop;
79
use function React\Async\async;
@@ -12,15 +14,15 @@
1214
$consumerTag = null;
1315

1416
// Capture signals - SIGINT = Ctrl+C; SIGTERM = `kill`
15-
Loop::addSignal(SIGINT, function (int $signal) use (&$channel, &$consumerTag): void {
17+
Loop::addSignal(SIGINT, static function (int $signal) use (&$channel, &$consumerTag): void {
1618
print 'Consumer cancelled\n';
1719
$channel->cancel($consumerTag);
1820

1921
Loop::addTimer(3, static function (): void {
2022
Loop::stop();
2123
});
2224
});
23-
Loop::addSignal(SIGTERM, function (int $signal) use (&$channel, &$consumerTag): void {
25+
Loop::addSignal(SIGTERM, static function (int $signal) use (&$channel, &$consumerTag): void {
2426
print 'Consumer cancelled\n';
2527
$channel->cancel($consumerTag);
2628

@@ -30,11 +32,11 @@
3032
});
3133

3234
$clientConfig = [
33-
"host" => "rabbitmq.example.com",
34-
"port" => 5672,
35-
"vhost" => "/",
36-
"user" => "appuser",
37-
"password" => "apppass",
35+
'host' => 'rabbitmq.example.com',
36+
'port' => 5672,
37+
'vhost' => '/',
38+
'user' => 'appuser',
39+
'password' => 'apppass',
3840
];
3941

4042
$client = new Client($clientConfig);
@@ -44,7 +46,7 @@
4446
$channelRef = $channel;
4547
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
4648
$response = $channel->consume(
47-
async(function (Message $message, Channel $channel): void {
49+
async(static function (Message $message, Channel $channel): void {
4850
echo ' [x] Received ', $message->content, "\n";
4951

5052
// Do some work - we generate password hashes with a high cost
@@ -54,6 +56,7 @@
5456
print 'WU {$i}\n';
5557
password_hash(random_bytes(255), PASSWORD_BCRYPT, ['cost' => 15]);
5658
}
59+
5760
echo ' [x] Done ', $message->content, "\n";
5861

5962
$channel->ack($message);

tutorial/1-hello-world/receive.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
use Bunny\Channel;
46
use Bunny\Client;
57
use Bunny\Message;
@@ -14,8 +16,8 @@
1416
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
1517

1618
$channel->consume(
17-
function (Message $message, Channel $channel): void {
18-
echo " [x] Received ", $message->content, "\n";
19+
static function (Message $message, Channel $channel): void {
20+
echo ' [x] Received ', $message->content, "\n";
1921
},
2022
'hello',
2123
'',

tutorial/1-hello-world/send.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
use Bunny\Client;
46

57
require dirname(__DIR__, 2) . '/vendor/autoload.php';

tutorial/2-work-queues/new_task.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
use Bunny\Client;
46

57
require dirname(__DIR__, 2) . '/vendor/autoload.php';
@@ -12,13 +14,11 @@
1214
$data = implode(' ', array_slice($argv, 1));
1315
$channel->publish(
1416
$data,
15-
[
16-
'delivery-mode' => 2
17-
],
17+
['delivery-mode' => 2],
1818
'',
19-
'task_queue'
19+
'task_queue',
2020
);
21-
echo " [x] Sent '{$data}'\n";
21+
echo " [x] Sent '$data'\n";
2222

2323
$channel->close();
2424
$client->disconnect();

tutorial/2-work-queues/worker.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
use Bunny\Channel;
46
use Bunny\Client;
57
use Bunny\Message;
@@ -15,11 +17,11 @@
1517

1618
$channel->qos(0, 1);
1719
$channel->consume(
18-
function (Message $message, Channel $channel, Client $client): void {
19-
echo " [x] Received ", $message->content, "\n";
20+
static function (Message $message, Channel $channel, Client $client): void {
21+
echo ' [x] Received ', $message->content, "\n";
2022
sleep(substr_count($message->content, '.'));
21-
echo " [x] Done", "\n";
23+
echo ' [x] Done', "\n";
2224
$channel->ack($message);
2325
},
24-
'task_queue'
26+
'task_queue',
2527
);

tutorial/3-publish-subscribe/emit_log.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
use Bunny\Client;
46

57
require dirname(__DIR__, 2) . '/vendor/autoload.php';
@@ -11,7 +13,7 @@
1113

1214
$data = implode(' ', array_slice($argv, 1));
1315
$channel->publish($data, [], 'logs');
14-
echo " [x] Sent '{$data}'\n";
16+
echo " [x] Sent '$data'\n";
1517

1618
$channel->close();
1719
$client->disconnect();

tutorial/3-publish-subscribe/receive_logs.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
use Bunny\Channel;
46
use Bunny\Client;
57
use Bunny\Message;
@@ -16,11 +18,11 @@
1618
echo ' [*] Waiting for logs. To exit press CTRL+C', "\n";
1719

1820
$channel->consume(
19-
function (Message $message, Channel $channel, Client $client): void {
21+
static function (Message $message, Channel $channel, Client $client): void {
2022
echo ' [x] ', $message->content, "\n";
2123
},
2224
$queue->queue,
2325
'',
2426
false,
25-
true
27+
true,
2628
);

tutorial/4-routing/emit_log.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
use Bunny\Client;
46

57
require dirname(__DIR__, 2) . '/vendor/autoload.php';
@@ -12,11 +14,11 @@
1214
$severity = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'info';
1315
$data = implode(' ', array_slice($argv, 2));
1416
if (empty($data)) {
15-
$data = "Hello World!";
17+
$data = 'Hello World!';
1618
}
1719

1820
$channel->publish($data, [], 'direct_logs', $severity);
19-
echo " [x] Sent ",$severity,':',$data," \n";
21+
echo ' [x] Sent ',$severity,':',$data," \n";
2022

2123
$channel->close();
2224
$client->disconnect();

tutorial/4-routing/receive_logs.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types = 1);
4+
35
use Bunny\Channel;
46
use Bunny\Client;
57
use Bunny\Message;
@@ -13,7 +15,7 @@
1315
$queue = $channel->queueDeclare('', false, false, true, false);
1416

1517
$severities = array_slice($argv, 1);
16-
if (empty($severities )) {
18+
if (empty($severities)) {
1719
file_put_contents('php://stderr', "Usage: $argv[0] [info] [warning] [error]\n");
1820
$client->disconnect();
1921
exit(1);
@@ -26,11 +28,11 @@
2628
echo ' [*] Waiting for logs. To exit press CTRL+C', "\n";
2729

2830
$channel->consume(
29-
function (Message $message, Channel $channel, Client $client): void {
31+
static function (Message $message, Channel $channel, Client $client): void {
3032
echo ' [x] ', $message->routingKey, ':', $message->content, "\n";
3133
},
3234
$queue->queue,
3335
'',
3436
false,
35-
true
37+
true,
3638
);

0 commit comments

Comments
 (0)