Skip to content

Commit 023f088

Browse files
p123-stacktransistive
authored andcommitted
chore: Fix CS and Psalm
1 parent 395df69 commit 023f088

File tree

8 files changed

+43
-15
lines changed

8 files changed

+43
-15
lines changed

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,9 @@
7878
"platform": {
7979
"php": "8.1.17"
8080
}
81+
},
82+
"scripts": {
83+
"fix-cs": "./vendor/bin/php-cs-fixer fix",
84+
"psalm": "./vendor/bin/psalm"
8185
}
8286
}

src/Bolt/ConnectionPool.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323
use Laudis\Neo4j\Databags\ConnectionRequestData;
2424
use Laudis\Neo4j\Databags\DriverConfiguration;
2525
use Laudis\Neo4j\Databags\SessionConfiguration;
26-
2726
use Laudis\Neo4j\Exception\ConnectionPoolException;
28-
use function method_exists;
29-
use function microtime;
30-
3127
use Psr\Http\Message\UriInterface;
3228

3329
use function shuffle;
@@ -45,7 +41,7 @@ public function __construct(
4541
private readonly BoltFactory $factory,
4642
private readonly ConnectionRequestData $data,
4743
private readonly ?Neo4jLogger $logger,
48-
private readonly float $acquireConnectionTimeout
44+
private readonly float $acquireConnectionTimeout,
4945
) {
5046
}
5147

@@ -72,6 +68,9 @@ public static function create(
7268

7369
public function acquire(SessionConfiguration $config): Generator
7470
{
71+
/**
72+
* @var Generator<int, float, bool, BoltConnection>
73+
*/
7574
return (function () use ($config) {
7675
$connection = $this->reuseConnectionIfPossible($config);
7776
if ($connection !== null) {
@@ -93,7 +92,7 @@ public function acquire(SessionConfiguration $config): Generator
9392

9493
$generator->next();
9594
} else {
96-
throw new ConnectionPoolException('Connection acquire timeout reached: ' . $waitTime);
95+
throw new ConnectionPoolException('Connection acquire timeout reached: '.($waitTime ?? 0.0));
9796
}
9897
}
9998

@@ -127,7 +126,7 @@ public function getLogger(): ?Neo4jLogger
127126
return $this->logger;
128127
}
129128

130-
private function reuseConnectionIfPossible(SessionConfiguration $config): ?ConnectionInterface
129+
private function reuseConnectionIfPossible(SessionConfiguration $config): ?BoltConnection
131130
{
132131
// Ensure random connection reuse before picking one.
133132
shuffle($this->activeConnections);

src/Bolt/Messages/BoltCommitMessage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function send(): BoltCommitMessage
4040
{
4141
$this->logger?->log(LogLevel::DEBUG, 'COMMIT');
4242
$response = $this->protocol->commit()->getResponse();
43+
// TODO: This is an issue with the underlying bolt library.
44+
// The serverState should be READY after a successful commit but
45+
// it's still in TX_STREAMING if the results were not consumed
46+
//
47+
// This should be removed once it's fixed
4348
$this->protocol->serverState = ServerState::READY;
4449

4550
/** @var array{bookmark?: string} $content */

src/Bolt/Session.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ private function beginInstantTransaction(
163163
private function acquireConnection(TransactionConfiguration $config, SessionConfiguration $sessionConfig): BoltConnection
164164
{
165165
$this->getLogger()?->log(LogLevel::INFO, 'Acquiring connection', ['config' => $config, 'sessionConfig' => $sessionConfig]);
166-
$connection = $this->pool->acquire($sessionConfig);
167-
/** @var BoltConnection $connection */
168-
$connection = GeneratorHelper::getReturnFromGenerator($connection);
166+
$connectionGenerator = $this->pool->acquire($sessionConfig);
167+
/**
168+
* @var BoltConnection $connection
169+
*
170+
* @psalm-suppress UnnecessaryVarAnnotation
171+
*/
172+
$connection = GeneratorHelper::getReturnFromGenerator($connectionGenerator);
169173

170174
// We try and let the server do the timeout management.
171175
// Since the client should not run indefinitely, we just add the client side by two, just in case

src/Contracts/ConnectionPoolInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface ConnectionPoolInterface
3535
* int,
3636
* float,
3737
* bool,
38-
* Connection|null
38+
* Connection
3939
* >
4040
*/
4141
public function acquire(SessionConfiguration $config): Generator;
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Neo4j PHP Client and Driver package.
7+
*
8+
* (c) Nagels <https://nagels.tech>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
314
namespace Laudis\Neo4j\Exception;
415

5-
final class ConnectionPoolException extends \RuntimeException
6-
{
16+
use RuntimeException;
717

18+
final class ConnectionPoolException extends RuntimeException
19+
{
820
}

src/Neo4j/Neo4jConnectionPool.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ public function acquire(SessionConfiguration $config): Generator
143143
$this->data->getUri()->withHost($address)
144144
);
145145
try {
146-
/** @var BoltConnection $connection */
146+
/**
147+
* @var BoltConnection $connection
148+
*
149+
* @psalm-suppress UnnecessaryVarAnnotation
150+
*/
147151
$connection = GeneratorHelper::getReturnFromGenerator($pool->acquire($config));
148152
$table = $this->routingTable($connection, $config);
149153
} catch (ConnectException $e) {

tests/Integration/EdgeCasesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testRunALotOfStatements(): void
105105
$count = 0;
106106
foreach ($personIds as $personId) {
107107
foreach ($movieIds as $movieId) {
108-
$count++;
108+
++$count;
109109
$this->getSession()->runStatement(Statement::create(
110110
'MATCH (a), (b) WHERE id(a) = $ida AND id(b) = $idb MERGE (a) <-[r:ACTED_IN]- (b) RETURN id(r)',
111111
['ida' => $personId, 'idb' => $movieId]

0 commit comments

Comments
 (0)