Skip to content

Commit 54186c9

Browse files
committed
Remove unneeded str_replace()
ConnectionConfig object made this unnecessary.
1 parent 3a651d6 commit 54186c9

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/PgSqlConnection.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ public static function connect(ConnectionConfig $connectionConfig, ?Cancellation
2727
throw new \Error('ext-pgsql is not compatible with pecl-ev; use pecl-pq or a different loop extension');
2828
} // @codeCoverageIgnoreEnd
2929

30-
$connectionString = \str_replace(";", " ", $connectionConfig->getConnectionString());
31-
32-
if (!$connection = @\pg_connect($connectionString, \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW)) {
30+
if (!$connection = @\pg_connect($connectionConfig->getConnectionString(), \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW)) {
3331
return new Failure(new ConnectionException("Failed to create connection resource"));
3432
}
3533

@@ -43,13 +41,11 @@ public static function connect(ConnectionConfig $connectionConfig, ?Cancellation
4341

4442
$deferred = new Deferred;
4543

46-
$callback = function ($watcher, $resource) use ($connection, $deferred) {
44+
$callback = function ($watcher, $resource) use ($connection, $deferred): void {
4745
switch (\pg_connect_poll($connection)) {
48-
case \PGSQL_POLLING_READING:
49-
return; // Connection not ready, poll again.
50-
51-
case \PGSQL_POLLING_WRITING:
52-
return; // Still writing...
46+
case \PGSQL_POLLING_READING: // Connection not ready, poll again.
47+
case \PGSQL_POLLING_WRITING: // Still writing...
48+
return;
5349

5450
case \PGSQL_POLLING_FAILED:
5551
$deferred->fail(new ConnectionException(\pg_last_error($connection)));
@@ -66,7 +62,7 @@ public static function connect(ConnectionConfig $connectionConfig, ?Cancellation
6662

6763
$promise = $deferred->promise();
6864

69-
$token = $token ?? new NullCancellationToken();
65+
$token = $token ?? new NullCancellationToken;
7066
$id = $token->subscribe([$deferred, "fail"]);
7167

7268
$promise->onResolve(function ($exception) use ($connection, $poll, $await, $id, $token): void {

src/PqConnection.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ final class PqConnection extends Connection implements Link
2424
*/
2525
public static function connect(ConnectionConfig $connectionConfig, ?CancellationToken $token = null): Promise
2626
{
27-
$connectionString = \str_replace(";", " ", $connectionConfig->getConnectionString());
28-
2927
try {
30-
$connection = new pq\Connection($connectionString, pq\Connection::ASYNC);
28+
$connection = new pq\Connection($connectionConfig->getConnectionString(), pq\Connection::ASYNC);
3129
} catch (pq\Exception $exception) {
3230
return new Failure(new ConnectionException("Could not connect to PostgreSQL server", 0, $exception));
3331
}
@@ -37,13 +35,11 @@ public static function connect(ConnectionConfig $connectionConfig, ?Cancellation
3735

3836
$deferred = new Deferred;
3937

40-
$callback = function () use ($connection, $deferred) {
38+
$callback = function () use ($connection, $deferred): void {
4139
switch ($connection->poll()) {
42-
case pq\Connection::POLLING_READING:
43-
return; // Connection not ready, poll again.
44-
45-
case pq\Connection::POLLING_WRITING:
46-
return; // Still writing...
40+
case pq\Connection::POLLING_READING: // Connection not ready, poll again.
41+
case pq\Connection::POLLING_WRITING: // Still writing...
42+
return;
4743

4844
case pq\Connection::POLLING_FAILED:
4945
$deferred->fail(new ConnectionException($connection->errorMessage));
@@ -60,7 +56,7 @@ public static function connect(ConnectionConfig $connectionConfig, ?Cancellation
6056

6157
$promise = $deferred->promise();
6258

63-
$token = $token ?? new NullCancellationToken();
59+
$token = $token ?? new NullCancellationToken;
6460
$id = $token->subscribe([$deferred, "fail"]);
6561

6662
$promise->onResolve(function () use ($poll, $await, $id, $token): void {

0 commit comments

Comments
 (0)