Skip to content

Commit 9347b29

Browse files
php 8 updates
1 parent c19f9d1 commit 9347b29

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/Memgraph.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Bolt\Bolt;
44
use Bolt\connection\{Socket, StreamSocket};
5-
use Bolt\protocol\{AProtocol, Response};
5+
use Bolt\protocol\{AProtocol, Response, V4_1, V4, V3};
66

77
/**
88
* Class Memgraph - adapter for Bolt library
@@ -33,14 +33,13 @@ class Memgraph
3333
public static int $port = 7687;
3434
public static float $timeout = 15;
3535

36-
private static ?AProtocol $protocol = null;
36+
private static AProtocol|V4_1|V4|V3|null $protocol = null;
3737
private static array $statistics;
3838

3939
/**
4040
* Get connection protocol for bolt communication
41-
* @return AProtocol
4241
*/
43-
protected static function getProtocol(): AProtocol
42+
protected static function getProtocol(): AProtocol|V4_1|V4|V3
4443
{
4544
if (is_null(self::$protocol)) {
4645
try {
@@ -98,6 +97,7 @@ public static function query(string $query, array $params = [], array $extra = [
9897
$all[] = $response->getContent();
9998
}
10099
} catch (Exception $e) {
100+
self::getProtocol()->reset();
101101
self::handleException($e);
102102
return [];
103103
}
@@ -129,7 +129,7 @@ public static function query(string $query, array $params = [], array $extra = [
129129
* @param array $extra
130130
* @return mixed
131131
*/
132-
public static function queryFirstField(string $query, array $params = [], array $extra = [])
132+
public static function queryFirstField(string $query, array $params = [], array $extra = []): mixed
133133
{
134134
$data = self::query($query, $params, $extra);
135135
if (empty($data)) {
@@ -175,6 +175,7 @@ public static function begin(array $extra = []): bool
175175
}
176176
return true;
177177
} catch (Exception $e) {
178+
self::getProtocol()->reset();
178179
self::handleException($e);
179180
}
180181
return false;
@@ -197,6 +198,7 @@ public static function commit(): bool
197198
}
198199
return true;
199200
} catch (Exception $e) {
201+
self::getProtocol()->reset();
200202
self::handleException($e);
201203
}
202204
return false;
@@ -219,6 +221,7 @@ public static function rollback(): bool
219221
}
220222
return true;
221223
} catch (Exception $e) {
224+
self::getProtocol()->reset();
222225
self::handleException($e);
223226
}
224227
return false;
@@ -253,7 +256,7 @@ public static function statistic(string $key): int
253256
/**
254257
* @param Exception $e
255258
*/
256-
private static function handleException(Exception $e)
259+
private static function handleException(Exception $e): void
257260
{
258261
if (is_callable(self::$errorHandler)) {
259262
call_user_func(self::$errorHandler, $e);

tests/MemgraphTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public function testStructure(IStructure $structure)
100100
public function structureProvider(): \Generator
101101
{
102102
yield 'Duration' => [new Duration(0, 4, 3, 2)];
103-
yield 'Date' => [new Date(floor(time() / 86400))];
104-
yield 'LocalTime' => [new LocalTime(microtime(true))];
103+
yield 'Date' => [new Date(intval(floor(time() / 86400)))];
104+
yield 'LocalTime' => [new LocalTime(intval(microtime(true) * 1000))];
105105
yield 'LocalDateTime' => [new LocalDateTime(time(), 1234)];
106106
}
107107

0 commit comments

Comments
 (0)