Skip to content

Commit dfb7eff

Browse files
committed
refactor: Fix Psalm errors
1 parent 5306c17 commit dfb7eff

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

src/Bolt/BoltDriver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Laudis\Neo4j\Bolt;
1515

16+
use Bolt\error\ConnectException;
1617
use Exception;
1718

1819
use function is_string;
@@ -104,7 +105,7 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool
104105
try {
105106
GeneratorHelper::getReturnFromGenerator($this->pool->acquire($config));
106107
} catch (ConnectException $e) {
107-
$this->pool->getLogger()->log(LogLevel::WARNING, 'Could not connect to server on URI '.$this->parsedUrl->__toString(), ['error' => $e]);
108+
$this->pool->getLogger()?->log(LogLevel::WARNING, 'Could not connect to server on URI '.$this->parsedUrl->__toString(), ['error' => $e]);
108109

109110
return false;
110111
}

src/Common/DriverSetupManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function verifyConnectivity(SessionConfiguration $config, ?string $alias
147147
try {
148148
$this->getDriver($config, $alias);
149149
} catch (ConnectException $e) {
150-
$this->getLogger()->log(
150+
$this->getLogger()?->log(
151151
LogLevel::WARNING,
152152
sprintf('Could not connect to server using alias (%s)', $alias ?? '<default>'),
153153
['exception' => $e]

src/Neo4j/Neo4jDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool
107107
try {
108108
GeneratorHelper::getReturnFromGenerator($this->pool->acquire($config));
109109
} catch (ConnectException $e) {
110-
$this->pool->getLogger()->log(LogLevel::WARNING, 'Could not connect to server on URI '.$this->parsedUrl->__toString(), ['error' => $e]);
110+
$this->pool->getLogger()?->log(LogLevel::WARNING, 'Could not connect to server on URI '.$this->parsedUrl->__toString(), ['error' => $e]);
111111

112112
return false;
113113
}

tests/Integration/ClientIntegrationTest.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@
3434
use Psr\Log\LoggerInterface;
3535
use Psr\Log\LogLevel;
3636
use ReflectionClass;
37+
use RuntimeException;
3738

3839
final class ClientIntegrationTest extends EnvironmentAwareIntegrationTest
3940
{
4041
public function testDriverAuthFailureVerifyConnectivity(): void
4142
{
4243
$connection = $_ENV['CONNECTION'] ?? false;
43-
if (str_starts_with($connection, 'http')) {
44+
if (str_starts_with((string) $connection, 'http')) {
4445
$this->markTestSkipped('HTTP does not support auth failure connectivity passing');
4546
}
4647

@@ -61,14 +62,16 @@ public function testDriverAuthFailureVerifyConnectivity(): void
6162
$driver = Driver::create($uri, $conf);
6263

6364
$this->expectException(Neo4jException::class);
64-
$this->expectExceptionMessage('Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."');
65+
$this->expectExceptionMessage(
66+
'Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."'
67+
);
6568
$driver->verifyConnectivity();
6669
}
6770

6871
public function testClientAuthFailureVerifyConnectivity(): void
6972
{
7073
$connection = $_ENV['CONNECTION'] ?? false;
71-
if (str_starts_with($connection, 'http')) {
74+
if (str_starts_with((string) $connection, 'http')) {
7275
$this->markTestSkipped('HTTP does not support auth failure connectivity passing');
7376
}
7477

@@ -100,7 +103,9 @@ public function testClientAuthFailureVerifyConnectivity(): void
100103
$driver = $client->getDriver(null);
101104

102105
$this->expectException(Neo4jException::class);
103-
$this->expectExceptionMessage('Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."');
106+
$this->expectExceptionMessage(
107+
'Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."'
108+
);
104109
$driver->verifyConnectivity();
105110
}
106111

@@ -128,28 +133,37 @@ public function testAvailabilityFullImplementation(): void
128133

129134
public function testTransactionFunction(): void
130135
{
131-
$result = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x'));
136+
$result = $this->getSession()->transaction(
137+
static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x')
138+
);
132139

133140
self::assertEquals(1, $result);
134141

135-
$result = $this->getSession()->readTransaction(static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x'));
142+
$result = $this->getSession()->readTransaction(
143+
static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x')
144+
);
136145

137146
self::assertEquals(1, $result);
138147

139-
$result = $this->getSession()->writeTransaction(static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x'));
148+
$result = $this->getSession()->writeTransaction(
149+
static fn (TransactionInterface $tsx) => $tsx->run('UNWIND [1] AS x RETURN x')->first()->getAsInt('x')
150+
);
140151

141152
self::assertEquals(1, $result);
142153
}
143154

144155
public function testValidRun(): void
145156
{
146-
$response = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->run(<<<'CYPHER'
157+
$response = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->run(
158+
<<<'CYPHER'
147159
MERGE (x:TestNode {test: $test})
148160
WITH x
149161
MERGE (y:OtherTestNode {test: $otherTest})
150162
WITH x, y, {c: 'd'} AS map, [1, 2, 3] AS list
151163
RETURN x, y, x.test AS test, map, list
152-
CYPHER, ['test' => 'a', 'otherTest' => 'b']));
164+
CYPHER,
165+
['test' => 'a', 'otherTest' => 'b']
166+
));
153167

154168
self::assertEquals(1, $response->count());
155169
$map = $response->first();
@@ -164,7 +178,12 @@ public function testValidRun(): void
164178
public function testInvalidRun(): void
165179
{
166180
$this->expectException(Neo4jException::class);
167-
$this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->run('MERGE (x:Tes0342hdm21.())', ['test' => 'a', 'otherTest' => 'b']));
181+
$this->getSession()->transaction(
182+
static fn (TransactionInterface $tsx) => $tsx->run(
183+
'MERGE (x:Tes0342hdm21.())',
184+
['test' => 'a', 'otherTest' => 'b']
185+
)
186+
);
168187
}
169188

170189
public function testInvalidRunRetry(): void
@@ -183,13 +202,18 @@ public function testInvalidRunRetry(): void
183202

184203
public function testValidStatement(): void
185204
{
186-
$response = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->runStatement(Statement::create(<<<'CYPHER'
205+
$response = $this->getSession()->transaction(static fn (TransactionInterface $tsx) => $tsx->runStatement(
206+
Statement::create(
207+
<<<'CYPHER'
187208
MERGE (x:TestNode {test: $test})
188209
WITH x
189210
MERGE (y:OtherTestNode {test: $otherTest})
190211
WITH x, y, {c: 'd'} AS map, [1, 2, 3] AS list
191212
RETURN x, y, x.test AS test, map, list
192-
CYPHER, ['test' => 'a', 'otherTest' => 'b'])));
213+
CYPHER,
214+
['test' => 'a', 'otherTest' => 'b']
215+
)
216+
));
193217

194218
self::assertEquals(1, $response->count());
195219
$map = $response->first();

0 commit comments

Comments
 (0)