Skip to content

Commit 57cfb53

Browse files
author
dax
committed
php8.4 compatibility
1 parent f07c7fa commit 57cfb53

7 files changed

Lines changed: 38 additions & 28 deletions

File tree

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private function config(string $parameter)
118118
* @throws \RouterOS\Exceptions\ConfigException
119119
* @since 1.0.0
120120
*/
121-
public function query($endpoint, array $where = null, string $operations = null, string $tag = null): ClientInterface
121+
public function query($endpoint, ?array $where = null, ?string $operations = null, ?string $tag = null): ClientInterface
122122
{
123123
// If endpoint is string then build Query object
124124
$query = ($endpoint instanceof Query)
@@ -580,7 +580,7 @@ private function isCustomOutput(): bool
580580
* @throws \RouterOS\Exceptions\ClientException
581581
* @since 1.3.0
582582
*/
583-
public function export(string $arguments = null): string
583+
public function export(?string $arguments = null): string
584584
{
585585
// Set params
586586
$sshHost = $this->config('host');

src/Interfaces/ClientInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function readAsIterator(array $options = []): ResponseIterator;
5555
*
5656
* @since 1.0.0
5757
*/
58-
public function query($endpoint, array $where = null, string $operations = null, string $tag = null): ClientInterface;
58+
public function query($endpoint, ?array $where = null, ?string $operations = null, ?string $tag = null): ClientInterface;
5959

6060
/**
6161
* Execute export command on remote host, it also will be used
@@ -66,5 +66,5 @@ public function query($endpoint, array $where = null, string $operations = null,
6666
* @return string
6767
* @since 1.3.0
6868
*/
69-
public function export(string $arguments = null): string;
69+
public function export(?string $arguments = null): string;
7070
}

src/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function getEndpoint(): ?string
228228
* @return \RouterOS\Interfaces\QueryInterface
229229
* @since 0.7
230230
*/
231-
public function setEndpoint(string $endpoint = null): QueryInterface
231+
public function setEndpoint(?string $endpoint = null): QueryInterface
232232
{
233233
$this->_endpoint = $endpoint;
234234
return $this;

src/ResponseIterator.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ public function __construct(Client $client, array $options = [])
7878
$count = count($raw);
7979
$result = [];
8080

81-
if (isset($positions[1])) {
82-
83-
foreach ($positions as $key => $position) {
84-
81+
if (isset($positions[1]))
82+
{
83+
foreach ($positions as $key => $position)
84+
{
8585
// Get length of future block
8686
$length = isset($positions[$key + 1])
8787
? $positions[$key + 1] - $position + 1
@@ -90,8 +90,9 @@ public function __construct(Client $client, array $options = [])
9090
// Convert array to simple items, save as result
9191
$result[] = array_slice($raw, $position, $length);
9292
}
93-
94-
} else {
93+
}
94+
else
95+
{
9596
$result = [$raw];
9697
}
9798

@@ -119,15 +120,18 @@ public function prev(): void
119120
*
120121
* @return mixed
121122
*/
122-
public function current()
123+
public function current(): mixed
123124
{
124-
if (isset($this->parsed[$this->current])) {
125+
if (isset($this->parsed[$this->current]))
126+
{
125127
return $this->parsed[$this->current];
126128
}
127129

128-
if ($this->valid()) {
130+
if ($this->valid())
131+
{
129132

130-
if (!isset($this->parsed[$this->current])) {
133+
if (!isset($this->parsed[$this->current]))
134+
{
131135
$value = $this->client->parseResponse($this->raw[$this->current])[0];
132136
$this->offsetSet($this->current, $value);
133137
}
@@ -143,7 +147,7 @@ public function current()
143147
*
144148
* @return mixed
145149
*/
146-
public function key()
150+
public function key(): mixed
147151
{
148152
return $this->current;
149153
}
@@ -184,9 +188,12 @@ public function rewind(): void
184188
*/
185189
public function offsetSet($offset, $value): void
186190
{
187-
if (null === $offset) {
191+
if (null === $offset)
192+
{
188193
$this->parsed[] = $value;
189-
} else {
194+
}
195+
else
196+
{
190197
$this->parsed[$offset] = $value;
191198
}
192199
}
@@ -220,15 +227,18 @@ public function offsetUnset($offset): void
220227
*
221228
* @return bool|mixed
222229
*/
223-
public function offsetGet($offset)
230+
public function offsetGet($offset): mixed
224231
{
225-
if (isset($this->parsed[$offset])) {
232+
if (isset($this->parsed[$offset]))
233+
{
226234
return $this->parsed[$offset];
227235
}
228236

229-
if (isset($this->raw[$offset]) && $this->raw[$offset] !== null) {
237+
if (isset($this->raw[$offset]) && $this->raw[$offset] !== null)
238+
{
230239
$f = $this->client->parseResponse($this->raw[$offset]);
231-
if ($f !== []) {
240+
if ($f !== [])
241+
{
232242
return $this->parsed[$offset] = $f[0];
233243
}
234244
}
@@ -253,6 +263,6 @@ public function serialize(): string
253263
*/
254264
public function unserialize($serialized): void
255265
{
256-
$this->raw = unserialize($serialized, null);
266+
$this->raw = unserialize($serialized);
257267
}
258268
}

src/ShortsTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait ShortsTrait
2424
* @return \RouterOS\Client
2525
* @since 1.0.0
2626
*/
27-
public function q($endpoint, array $where = null, string $operations = null, string $tag = null): Client
27+
public function q($endpoint, ?array $where = null, ?string $operations = null, ?string $tag = null): Client
2828
{
2929
return $this->query($endpoint, $where, $operations, $tag);
3030
}
@@ -69,7 +69,7 @@ public function ri(array $options = []): ResponseIterator
6969
* @return array
7070
* @since 1.0.0
7171
*/
72-
public function qr($endpoint, array $where = null, string $operations = null, string $tag = null, bool $parse = true, array $options = []): array
72+
public function qr($endpoint, ?array $where = null, ?string $operations = null, ?string $tag = null, bool $parse = true, array $options = []): array
7373
{
7474
return $this->query($endpoint, $where, $operations, $tag)->read($parse, $options);
7575
}
@@ -86,7 +86,7 @@ public function qr($endpoint, array $where = null, string $operations = null, st
8686
* @return \RouterOS\ResponseIterator
8787
* @since 1.0.0
8888
*/
89-
public function qri($endpoint, array $where = null, string $operations = null, string $tag = null, array $options = []): ResponseIterator
89+
public function qri($endpoint, ?array $where = null, ?string $operations = null, ?string $tag = null, array $options = []): ResponseIterator
9090
{
9191
return $this->query($endpoint, $where, $operations, $tag)->readAsIterator($options);
9292
}

src/Streams/ResourceStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function read(int $length): string
6767
*
6868
* @throws \RouterOS\Exceptions\StreamException when not possible to write bytes
6969
*/
70-
public function write(string $string, int $length = null): int
70+
public function write(string $string, ?int $length = null): int
7171
{
7272
if (null === $length) {
7373
$length = strlen($string);

src/Streams/StringStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function read(int $length): string
7070
*
7171
* @throws \InvalidArgumentException on invalid length
7272
*/
73-
public function write(string $string, int $length = null): int
73+
public function write(string $string, ?int $length = null): int
7474
{
7575
if (null === $length) {
7676
$length = strlen($string);

0 commit comments

Comments
 (0)