Skip to content

Commit af97e31

Browse files
committed
Public readonly properties instead of getters
1 parent 81f2f19 commit af97e31

4 files changed

Lines changed: 12 additions & 33 deletions

File tree

examples/3-listen.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
foreach ($listener as $notification) {
3535
\printf(
3636
"Received notification from PID %d on channel '%s' with payload: %s\n",
37-
$notification->getPid(),
38-
$notification->getChannel(),
39-
$notification->getPayload()
37+
$notification->pid,
38+
$notification->channel,
39+
$notification->payload,
4040
);
4141
}
4242

examples/4-multi-listen.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
use Amp\Future;
77
use Amp\Postgres\PostgresConfig;
8+
use Amp\Postgres\PostgresConnectionPool;
89
use Amp\Postgres\PostgresListener;
910
use Amp\Postgres\PostgresNotification;
10-
use Amp\Postgres\PostgresConnectionPool;
1111
use function Amp\async;
1212
use function Amp\delay;
1313

@@ -56,9 +56,9 @@
5656
foreach ($listener as $notification) {
5757
\printf(
5858
"Received notification from PID %d on channel '%s' with payload: %s\n",
59-
$notification->getPid(),
60-
$notification->getChannel(),
61-
$notification->getPayload()
59+
$notification->pid,
60+
$notification->channel,
61+
$notification->payload,
6262
);
6363
}
6464
};

src/PostgresNotification.php

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,9 @@ final class PostgresNotification
1010
* @param string $payload Message payload.
1111
*/
1212
public function __construct(
13-
private readonly string $channel,
14-
private readonly int $pid,
15-
private readonly string $payload,
13+
public readonly string $channel,
14+
public readonly int $pid,
15+
public readonly string $payload,
1616
) {
1717
}
18-
19-
/**
20-
* @return non-empty-string
21-
*/
22-
public function getChannel(): string
23-
{
24-
return $this->channel;
25-
}
26-
27-
/**
28-
* @return positive-int
29-
*/
30-
public function getPid(): int
31-
{
32-
return $this->pid;
33-
}
34-
35-
public function getPayload(): string
36-
{
37-
return $this->payload;
38-
}
3918
}

test/AbstractConnectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testListen()
5757

5858
/** @var PostgresNotification $notification */
5959
foreach ($listener as $notification) {
60-
$this->assertSame($notification->getPayload(), (string) $count++);
60+
$this->assertSame($notification->payload, (string) $count++);
6161
}
6262

6363
$this->assertSame(2, $count);
@@ -81,7 +81,7 @@ public function testNotify()
8181

8282
/** @var PostgresNotification $notification */
8383
foreach ($listener as $notification) {
84-
$this->assertSame($notification->getPayload(), (string) $count++);
84+
$this->assertSame($notification->payload, (string) $count++);
8585
}
8686

8787
$this->assertSame(2, $count);

0 commit comments

Comments
 (0)