Skip to content

Commit e035136

Browse files
applied changes from php8
1 parent c354965 commit e035136

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+367
-726
lines changed

.github/workflows/db-test-php-7.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/no-db-test-php-7.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"license": "MIT",
99
"minimum-stability": "stable",
1010
"require": {
11-
"php": ">=7.4",
11+
"php": ">=8",
1212
"ext-mbstring": "*"
1313
},
1414
"require-dev": {

src/Bolt.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,18 @@ final class Bolt
2121
{
2222
private IPacker $packer;
2323
private IUnpacker $unpacker;
24-
private IConnection $connection;
2524
private array $versions = [];
2625
public static bool $debug = false;
2726
public ServerState $serverState;
2827

29-
/**
30-
* Bolt constructor
31-
* @param IConnection $connection
32-
* @throws Exception
33-
*/
34-
public function __construct(IConnection $connection)
28+
public function __construct(private IConnection $connection)
3529
{
36-
$this->connection = $connection;
3730
$this->setProtocolVersions(5, 4.4, 4.3);
3831
$this->setPackStreamVersion();
3932
}
4033

4134
/**
4235
* Connect via Connection, execute handshake on it, create and return protocol version class
43-
* @return AProtocol
4436
* @throws Exception
4537
*/
4638
public function build(): AProtocol
@@ -68,23 +60,14 @@ public function build(): AProtocol
6860
return new $protocolClass($this->packer, $this->unpacker, $this->connection, $this->serverState);
6961
}
7062

71-
/**
72-
* @param int|float|string ...$v
73-
* @return Bolt
74-
*/
75-
public function setProtocolVersions(...$v): Bolt
63+
public function setProtocolVersions(int|float|string ...$v): Bolt
7664
{
7765
$this->versions = array_slice($v, 0, 4);
7866
while (count($this->versions) < 4)
7967
$this->versions[] = 0;
8068
return $this;
8169
}
8270

83-
/**
84-
* @param int $version
85-
* @return Bolt
86-
* @throws Exception
87-
*/
8871
public function setPackStreamVersion(int $version = 1): Bolt
8972
{
9073
$packerClass = "\\Bolt\\packstream\\v" . $version . "\\Packer";
@@ -104,7 +87,6 @@ public function setPackStreamVersion(int $version = 1): Bolt
10487

10588
/**
10689
* @link https://www.neo4j.com/docs/bolt/current/bolt/handshake/
107-
* @return string
10890
* @throws Exception
10991
*/
11092
private function handshake(): string
@@ -126,8 +108,6 @@ private function handshake(): string
126108

127109
/**
128110
* Read and compose selected protocol version
129-
* @param string $bytes
130-
* @return string|null
131111
*/
132112
private function unpackProtocolVersion(string $bytes): ?string
133113
{
@@ -147,7 +127,6 @@ private function unpackProtocolVersion(string $bytes): ?string
147127

148128
/**
149129
* Pack requested protocol versions
150-
* @return string
151130
*/
152131
private function packProtocolVersions(): string
153132
{

src/connection/AConnection.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,26 @@
1111
*/
1212
abstract class AConnection implements IConnection
1313
{
14-
protected string $ip;
15-
protected int $port;
16-
protected float $timeout;
17-
18-
/**
19-
* @inheritDoc
20-
*/
21-
public function __construct(string $ip = '127.0.0.1', int $port = 7687, float $timeout = 15)
14+
public function __construct(
15+
protected string $ip = '127.0.0.1',
16+
protected int $port = 7687,
17+
protected float $timeout = 15
18+
)
2219
{
23-
if (filter_var($ip, FILTER_VALIDATE_URL)) {
24-
$scheme = parse_url($ip, PHP_URL_SCHEME);
20+
if (filter_var($this->ip, FILTER_VALIDATE_URL)) {
21+
$scheme = parse_url($this->ip, PHP_URL_SCHEME);
2522
if (!empty($scheme)) {
26-
$ip = str_replace($scheme . '://', '', $ip);
23+
$this->ip = str_replace($scheme . '://', '', $this->ip);
2724
}
2825
}
29-
30-
$this->ip = $ip;
31-
$this->port = $port;
32-
$this->timeout = $timeout;
3326
}
3427

3528
/**
3629
* Print buffer as HEX
3730
* @param string $str
3831
* @param string $prefix
3932
*/
40-
protected function printHex(string $str, string $prefix = 'C: ')
33+
protected function printHex(string $str, string $prefix = 'C: '): void
4134
{
4235
$str = implode(unpack('H*', $str));
4336
echo '<pre>' . $prefix;
@@ -63,7 +56,7 @@ public function getTimeout(): float
6356
return $this->timeout;
6457
}
6558

66-
public function setTimeout(float $timeout)
59+
public function setTimeout(float $timeout): void
6760
{
6861
$this->timeout = $timeout;
6962
}

src/connection/IConnection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public function __construct(string $ip = '127.0.0.1', int $port = 7687, float $t
2020

2121
public function connect(): bool;
2222

23-
public function write(string $buffer);
23+
public function write(string $buffer): void;
2424

2525
public function read(int $length = 2048): string;
2626

27-
public function disconnect();
27+
public function disconnect(): void;
2828

2929
public function getIp(): string;
3030

3131
public function getPort(): int;
3232

3333
public function getTimeout(): float;
3434

35-
public function setTimeout(float $timeout);
35+
public function setTimeout(float $timeout): void;
3636
}

src/connection/Socket.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Socket extends AConnection
1717
{
1818
/**
19-
* @var resource|object|bool
19+
* @var resource|\Socket|bool
2020
*/
2121
private $socket = false;
2222

@@ -60,7 +60,7 @@ public function connect(): bool
6060
* @param string $buffer
6161
* @throws ConnectException
6262
*/
63-
public function write(string $buffer)
63+
public function write(string $buffer): void
6464
{
6565
if ($this->socket === false) {
6666
throw new ConnectException('Not initialized socket');
@@ -107,21 +107,21 @@ public function read(int $length = 2048): string
107107
/**
108108
* Close socket connection
109109
*/
110-
public function disconnect()
110+
public function disconnect(): void
111111
{
112112
if ($this->socket !== false) {
113113
@socket_shutdown($this->socket);
114114
@socket_close($this->socket);
115115
}
116116
}
117117

118-
public function setTimeout(float $timeout)
118+
public function setTimeout(float $timeout): void
119119
{
120120
parent::setTimeout($timeout);
121121
$this->configureTimeout();
122122
}
123123

124-
private function configureTimeout()
124+
private function configureTimeout(): void
125125
{
126126
if ($this->socket === false)
127127
return;

src/connection/StreamSocket.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class StreamSocket extends AConnection
2828
* @link https://www.php.net/manual/en/context.ssl.php
2929
* @param array $options
3030
*/
31-
public function setSslContextOptions(array $options)
31+
public function setSslContextOptions(array $options): void
3232
{
3333
$this->sslContextOptions = $options;
3434
}
@@ -73,7 +73,7 @@ public function connect(): bool
7373
* @param string $buffer
7474
* @throws ConnectException
7575
*/
76-
public function write(string $buffer)
76+
public function write(string $buffer): void
7777
{
7878
if (Bolt::$debug)
7979
$this->printHex($buffer);
@@ -125,13 +125,13 @@ public function read(int $length = 2048): string
125125
/**
126126
* Close connection
127127
*/
128-
public function disconnect()
128+
public function disconnect(): void
129129
{
130130
if (is_resource($this->stream))
131131
stream_socket_shutdown($this->stream, STREAM_SHUT_RDWR);
132132
}
133133

134-
public function setTimeout(float $timeout)
134+
public function setTimeout(float $timeout): void
135135
{
136136
parent::setTimeout($timeout);
137137
$this->configureTimeout();

src/packstream/Bytes.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
*/
1515
class Bytes implements ArrayAccess, Countable
1616
{
17-
private array $bytes = [];
18-
19-
public function __construct(array $bytes = [])
17+
public function __construct(private array $bytes = [])
2018
{
21-
$this->bytes = $bytes;
2219
}
2320

2421
public function offsetExists($offset): bool
@@ -31,15 +28,15 @@ public function offsetGet($offset): ?string
3128
return $this->bytes[$offset] ?? null;
3229
}
3330

34-
public function offsetSet($offset, $value)
31+
public function offsetSet($offset, $value): void
3532
{
3633
if ($offset === null)
3734
$this->bytes[] = $value;
3835
else
3936
$this->bytes[$offset] = $value;
4037
}
4138

42-
public function offsetUnset($offset)
39+
public function offsetUnset($offset): void
4340
{
4441
unset($this->bytes[$offset]);
4542
}

src/packstream/IPacker.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
interface IPacker
1313
{
1414
/**
15-
* @param $signature
15+
* @param int $signature
1616
* @param mixed ...$params
1717
* @return iterable
1818
*/
19-
public function pack($signature, ...$params): iterable;
19+
public function pack(int $signature, mixed ...$params): iterable;
2020

2121
/**
2222
* @param array $structures [signature => classFQN]
2323
*/
24-
public function setAvailableStructures(array $structures);
24+
public function setAvailableStructures(array $structures): void;
2525
}

0 commit comments

Comments
 (0)