Skip to content

Commit 2a6ea72

Browse files
committed
fixed psalm typing warnings
1 parent 630a47f commit 2a6ea72

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

src/Bolt/BoltConnectionPool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function acquire(
5151
?UriInterface $server = null
5252
): ConnectionInterface {
5353
$connectingTo = $server ?? $uri;
54-
$key = $connectingTo->getHost().':'.$connectingTo->getPort();
54+
$key = $connectingTo->getHost().':'.($connectingTo->getPort() ?? '7687');
5555
if (!isset($this->connectionCache[$key])) {
5656
self::$connectionCache[$key] = [];
5757
}

src/Bolt/BoltUnmanagedTransaction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838
final class BoltUnmanagedTransaction implements UnmanagedTransactionInterface
3939
{
40+
/** @var FormatterInterface<T> */
4041
private FormatterInterface $formatter;
4142
/** @var ConnectionInterface<Bolt> */
4243
private ConnectionInterface $connection;

src/Common/BoltConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(
5757
$this->socket = $socket;
5858
}
5959

60-
public function getImplementation()
60+
public function getImplementation(): Bolt
6161
{
6262
return $this->bolt;
6363
}

src/Http/HttpConnection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
use Psr\Http\Client\ClientInterface;
2121
use Psr\Http\Message\UriInterface;
2222

23+
/**
24+
* @implements ConnectionInterface<ClientInterface>
25+
*/
2326
final class HttpConnection implements ConnectionInterface
2427
{
2528
private string $serverAgent;

src/Neo4j/Neo4jConnectionPool.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use Laudis\Neo4j\Enum\AccessMode;
2525
use Laudis\Neo4j\Enum\ConnectionProtocol;
2626
use Laudis\Neo4j\Enum\RoutingRoles;
27-
use Laudis\Neo4j\Types\CypherList;
2827
use Psr\Http\Message\UriInterface;
2928
use function random_int;
3029
use function str_starts_with;
@@ -86,33 +85,40 @@ private function getNextServer(RoutingTable $table, AccessMode $mode): Uri
8685
private function routingTable(ConnectionInterface $connection): RoutingTable
8786
{
8887
if ($this->table === null || $this->table->getTtl() < time()) {
88+
/** @var Bolt */
8989
$bolt = $connection->getImplementation();
9090
$protocol = $connection->getProtocol();
9191
if ($protocol->compare(ConnectionProtocol::BOLT_V43()) >= 0) {
92-
$route = $bolt->route()['rt'];
93-
['servers' => $servers, 'ttl' => $ttl ] = $route;
92+
/** @var array{rt: array{servers: list<array{addresses: list<string>, role:string}>, ttl: int}} $route */
93+
$route = $bolt->route();
94+
['servers' => $servers, 'ttl' => $ttl ] = $route['rt'];
9495
} elseif ($protocol->compare(ConnectionProtocol::BOLT_V40()) >= 0) {
9596
$bolt->run('CALL dbms.routing.getRoutingTable({context: []})');
97+
/**
98+
* @var iterable<array{addresses: list<string>, role:string}> $servers
99+
* @var int $ttl
100+
*/
96101
['servers' => $servers, 'ttl' => $ttl] = $bolt->pullAll();
97102
} else {
98103
$bolt->run('CALL dbms.cluster.overview()');
104+
/** @var list<array{addresses: list<string>, role: string}> */
99105
$response = $bolt->pullAll();
100106

101107
/** @var iterable<array{addresses: list<string>, role:string}> $servers */
102108
$servers = [];
103109
$ttl = time() + 3600;
104110
foreach ($response as $server) {
105-
/** @var CypherList<string> $addresses */
106-
$addresses = $server->get('addresses');
107-
$addresses = $addresses->filter(static fn (string $x) => str_starts_with($x, 'bolt://'));
111+
$addresses = $server['addresses'];
112+
$addresses = array_filter($addresses, static fn (string $x) => str_starts_with($x, 'bolt://'));
108113
/**
109114
* @psalm-suppress InvalidArrayAssignment
110115
*
111116
* @var array{addresses: list<string>, role:string}
112117
*/
113-
$servers[] = ['addresses' => $addresses->toArray(), 'role' => $server->get('role')];
118+
$servers[] = ['addresses' => $addresses, 'role' => $server['role']];
114119
}
115120
}
121+
116122
$this->table = new RoutingTable($servers, $ttl);
117123
}
118124

src/ParameterHelper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ public static function asList(iterable $iterable): CypherList
4747
*/
4848
public static function asMap(iterable $iterable): CypherMap
4949
{
50-
return new CypherMap($iterable);
50+
$tbr = [];
51+
foreach ($iterable as $key => $value) {
52+
$tbr[(string) $key] = $value;
53+
}
54+
return new CypherMap($tbr);
5155
}
5256

5357
/**

0 commit comments

Comments
 (0)