Skip to content

Commit 1c307b6

Browse files
authored
Merge pull request #609 from Icinga/support-php-8.5
Support PHP 8.5
2 parents 7998ba3 + db4e52f commit 1c307b6

91 files changed

Lines changed: 617 additions & 270 deletions

File tree

Some content is hidden

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

.github/workflows/PHP.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
strategy:
1919
matrix:
20-
php-version: [ '7.4', '8.1', '8.2', '8.3', '8.4' ]
20+
php-version: [ '8.2', '8.3', '8.4', '8.5' ]
2121

2222
name: Static analysis for version ${{ matrix.php-version }}
2323

application/clicommands/CheckCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,12 @@ protected function addProblematicObjectNames($color, $objects)
350350
}
351351
}
352352

353-
protected function getStateForColor($color): string
353+
/**
354+
* @param string $color
355+
*
356+
* @return string
357+
*/
358+
protected function getStateForColor(string $color): string
354359
{
355360
$colors = [
356361
'green' => 'OK',

application/clicommands/Command.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Icinga\Cli\Command as CliCommand;
1515
use Icinga\Module\Vspheredb\Configuration;
1616
use Icinga\Module\Vspheredb\Daemon\RemoteClient;
17-
use React\EventLoop\Factory as Loop;
17+
use React\EventLoop\Loop;
1818
use React\EventLoop\LoopInterface;
1919
use React\Stream\WritableResourceStream;
2020

@@ -39,11 +39,7 @@ public function init()
3939

4040
protected function loop()
4141
{
42-
if ($this->loop === null) {
43-
$this->loop = Loop::create();
44-
}
45-
46-
return $this->loop;
42+
return Loop::get();
4743
}
4844

4945
protected function eventuallyStartMainLoop()

application/controllers/AsyncControllerHelper.php

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

33
namespace Icinga\Module\Vspheredb\Controllers;
44

5-
use Clue\React\Block;
65
use Icinga\Module\Vspheredb\Configuration;
76
use Icinga\Module\Vspheredb\Daemon\RemoteClient;
8-
use React\EventLoop\Factory as Loop;
7+
use React\EventLoop\Loop;
8+
9+
use function React\Async\await;
10+
use function React\Promise\Timer\timeout;
911

1012
trait AsyncControllerHelper
1113
{
12-
protected $loop;
13-
1414
/** @var RemoteClient */
1515
protected $remoteClient;
1616

1717
protected function syncRpcCall($method, $params = [], $timeout = 30)
1818
{
19-
return Block\await($this->remoteClient()->request($method, $params), $this->loop(), $timeout);
19+
return await(timeout($this->remoteClient()->request($method, $params), $timeout));
2020
}
2121

2222
/**
@@ -33,11 +33,6 @@ protected function remoteClient()
3333

3434
protected function loop()
3535
{
36-
// Hint: we're not running this loop right now
37-
if ($this->loop === null) {
38-
$this->loop = Loop::create();
39-
}
40-
41-
return $this->loop;
36+
return Loop::get();
4237
}
4338
}

application/controllers/ConfigurationController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ protected function mapServerConnectionsToId($connections)
127127
{
128128
$connectionsByServer = [];
129129
foreach ((array) $connections as $id => $connection) {
130-
if (isset($connectionsByServer[$connection->serverId])) {
131-
$connectionsByServer[$connection->serverId][$id] = $connection;
130+
$serverId = $connection->serverId ?? '';
131+
if (isset($connectionsByServer[$serverId])) {
132+
$connectionsByServer[$serverId][$id] = $connection;
132133
} else {
133-
$connectionsByServer[$connection->serverId] = [$id => $connection];
134+
$connectionsByServer[$serverId] = [$id => $connection];
134135
}
135136
}
136137

library/Vspheredb/Addon/SimpleBackupTool.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ abstract class SimpleBackupTool implements BackupTool
1414

1515
protected $customValues = [];
1616

17+
/**
18+
* @return string[]
19+
*/
20+
protected function getCustomValues(): array
21+
{
22+
return $this->customValues;
23+
}
24+
1725
/**
1826
* @param $annotation
1927
* @return bool
@@ -40,7 +48,7 @@ public function handle(VirtualMachine $vm)
4048
protected function parseCustomValues(CustomValues $values)
4149
{
4250
$attributes = [];
43-
foreach ($this->customValues as $name) {
51+
foreach ($this->getCustomValues() as $name) {
4452
if ($values->has($name)) {
4553
$attributes[$name] = $values->get($name);
4654
}
@@ -58,7 +66,7 @@ protected function parseCustomValues(CustomValues $values)
5866
public function wants(VirtualMachine $vm)
5967
{
6068
$values = $vm->customValues();
61-
foreach ($this->customValues as $name) {
69+
foreach ($this->getCustomValues() as $name) {
6270
if ($values->has($name)) {
6371
return true;
6472
}
@@ -141,14 +149,14 @@ public function stripAnnotation(&$annotation)
141149

142150
public function stripCustomValues(CustomValues $values)
143151
{
144-
foreach ($this->customValues as $name) {
152+
foreach ($this->getCustomValues() as $name) {
145153
$values->remove($name);
146154
}
147155
}
148156

149157
public function removeCustomValues(CustomValues $values)
150158
{
151-
foreach ($this->customValues as $name) {
159+
foreach ($this->getCustomValues() as $name) {
152160
$values->remove($name);
153161
}
154162
}

library/Vspheredb/Api/Protocol/ClientDecoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function decode($function, $response)
4949
* @see SoapClient::__doRequest()
5050
*/
5151
#[\ReturnTypeWillChange]
52-
public function __doRequest($request, $location, $action, $version, $one_way = 0)
52+
public function __doRequest($request, $location, $action, $version, $oneWay = 0, $uriParserClass = null)
5353
{
5454
// the actual result doesn't actually matter, just return the given result
5555
// this will be processed internally and will return the parsed result

library/Vspheredb/Api/Protocol/ClientEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function encode($name, $args)
4747
* @see SoapClient::__doRequest()
4848
*/
4949
#[\ReturnTypeWillChange]
50-
public function __doRequest($request, $location, $action, $version, $one_way = 0)
50+
public function __doRequest($request, $location, $action, $version, $oneWay = 0, $uriParserClass = null)
5151
{
5252
$headers = [];
5353
if ($version === SOAP_1_1) {

library/Vspheredb/CheckPluginHelper.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function run($callable)
7777
}, function (Exception $e) {
7878
$this->addProblem('UNKNOWN', $e->getMessage());
7979
$this->showOptionalTrace($e);
80-
})->always(function () {
80+
})->finally(function () {
8181
$this->shutdown();
8282
});
8383
} else {
@@ -104,10 +104,10 @@ protected function stripNonUtf8Characters($string)
104104
}
105105

106106
/**
107-
* @param null $state
108-
* @return mixed
107+
* @param int|string|null $state
108+
* @return string
109109
*/
110-
protected function getStateName($state = null)
110+
protected function getStateName(int|string|null $state = null): string
111111
{
112112
if ($state === null) {
113113
return $this->stateNameMap[$this->state];
@@ -121,7 +121,7 @@ protected function getStateName($state = null)
121121
* @param string $message
122122
* @return $this
123123
*/
124-
protected function addProblem($state, $message)
124+
protected function addProblem(int|string $state, string $message): static
125125
{
126126
$this->raiseState($state);
127127
$stateName = $this->getStateName($state);
@@ -169,7 +169,7 @@ protected function prependMessage($message)
169169
* @param int|string $state
170170
* @return $this
171171
*/
172-
protected function raiseState($state)
172+
protected function raiseState(int|string $state): static
173173
{
174174
$state = $this->wantNumericState($state);
175175
if ($this->sortingStateMap[$state] > $this->sortingStateMap[$this->state]) {
@@ -188,10 +188,10 @@ protected function getState()
188188
}
189189

190190
/**
191-
* @param $state
191+
* @param int|string $state
192192
* @return int
193193
*/
194-
protected function wantNumericState($state)
194+
protected function wantNumericState(int|string $state): int
195195
{
196196
if (is_int($state) || ctype_digit($state)) {
197197
if (array_key_exists($state, $this->stateNameMap)) {

library/Vspheredb/Daemon/ConnectionState.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function __construct(array $daemonApiConnections, $db)
3636
public function getConnectionsByVCenter(): array
3737
{
3838
$connectionsByVCenter = $this->getConfiguredServersByVCenter();
39+
/** @var ApiConnectionInfo $info */
3940
foreach ($this->daemonApiConnections as $info) {
4041
if (isset($connectionsByVCenter[$info->vCenterId])) {
4142
if (isset($connectionsByVCenter[$info->vCenterId][$info->serverId])) {
@@ -70,10 +71,14 @@ protected function getConfiguredServersByVCenter(): array
7071
])
7172
) as $server
7273
) {
73-
if (! isset($result[$server->vcenter_id])) {
74-
$result[$server->vcenter_id] = [];
74+
/** @var int|string $vCenterId */
75+
$vCenterId = $server->vcenter_id ?? '';
76+
if (! isset($result[$vCenterId])) {
77+
$result[$vCenterId] = [];
7578
}
76-
$result[$server->vcenter_id][$server->id] = new ServerConnectionInfo(
79+
/** @var int $serverId */
80+
$serverId = $server->id;
81+
$result[$vCenterId][$serverId] = new ServerConnectionInfo(
7782
$server->host,
7883
$server->enabled === 'y',
7984
true

0 commit comments

Comments
 (0)