Skip to content

Commit fd14237

Browse files
authored
Support PHP 8.5 (#262)
PHP 8.4: - Function parameters that are null by default must be declared nullable. PHP 8.5: - Replace deprecated PDO constant PDO::MYSQL_ATTR_INIT_COMMAND. - Using null as an array offset is deprecated. Other changes: phpstan baseline: Update syntax and remove non-matching error message.
2 parents d437b06 + 831b709 commit fd14237

10 files changed

Lines changed: 404 additions & 261 deletions

File tree

library/Reporting/Database.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ private static function getDb(): RetryConnection
4343

4444
$config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ];
4545
if ($config->db === 'mysql') {
46-
$config->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
46+
// In PHP 8.5+, driver-specific constants of the PDO class are deprecated,
47+
// but the replacements are only available since php 8.4
48+
if (version_compare(PHP_VERSION, '8.4.0', '<')) {
49+
$mysqlAttrInitCommand = PDO::MYSQL_ATTR_INIT_COMMAND;
50+
} else {
51+
$mysqlAttrInitCommand = Pdo\Mysql::ATTR_INIT_COMMAND;
52+
}
53+
$config->options[$mysqlAttrInitCommand] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
4754
. ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
4855
}
4956

library/Reporting/Hook/ReportHook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract public function getName();
2626
*
2727
* @return ReportData|null
2828
*/
29-
public function getData(Timerange $timerange, array $config = null)
29+
public function getData(Timerange $timerange, ?array $config = null)
3030
{
3131
return null;
3232
}
@@ -39,7 +39,7 @@ public function getData(Timerange $timerange, array $config = null)
3939
*
4040
* @return ValidHtml|null
4141
*/
42-
public function getHtml(Timerange $timerange, array $config = null)
42+
public function getHtml(Timerange $timerange, ?array $config = null)
4343
{
4444
return null;
4545
}

library/Reporting/Reports/SystemReport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function getName()
1616
return 'System';
1717
}
1818

19-
public function getHtml(Timerange $timerange, array $config = null)
19+
public function getHtml(Timerange $timerange, ?array $config = null)
2020
{
2121
ob_start();
2222
phpinfo();

library/Reporting/Web/Forms/ReportForm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ protected function assemble(): void
155155
'required' => true,
156156
'class' => 'autosubmit',
157157
'label' => $this->translate('Timeframe'),
158-
'options' => [null => $this->translate('Please choose')] + Database::listTimeframes(),
158+
'options' => ['' => $this->translate('Please choose')] + Database::listTimeframes(),
159159
'description' => $this->translate(
160160
'Specifies the time frame in which this report is to be generated'
161161
)
162162
]);
163163

164164
$this->addElement('select', 'template', [
165165
'label' => $this->translate('Template'),
166-
'options' => [null => $this->translate('Please choose')] + Database::listTemplates(),
166+
'options' => ['' => $this->translate('Please choose')] + Database::listTemplates(),
167167
'description' => $this->translate(
168168
'Specifies the template to use when exporting this report to pdf. (Default Icinga template)'
169169
)
@@ -173,7 +173,7 @@ protected function assemble(): void
173173
'required' => true,
174174
'class' => 'autosubmit',
175175
'label' => $this->translate('Report'),
176-
'options' => [null => $this->translate('Please choose')] + $this->listReports(),
176+
'options' => ['' => $this->translate('Please choose')] + $this->listReports(),
177177
'description' => $this->translate('Specifies the type of the reportlet to be generated')
178178
]);
179179

library/Reporting/Web/Forms/ScheduleForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function assemble()
8989
$this->addElement('select', 'action', [
9090
'required' => true,
9191
'class' => 'autosubmit',
92-
'options' => array_merge([null => $this->translate('Please choose')], $this->listActions()),
92+
'options' => array_merge(['' => $this->translate('Please choose')], $this->listActions()),
9393
'label' => $this->translate('Action'),
9494
'description' => $this->translate('Specifies an action to be triggered by the scheduler')
9595
]);

library/Reporting/Web/Forms/TemplateForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ protected function addColumnSettings($name, $label)
254254
'class' => 'autosubmit',
255255
'label' => $label,
256256
'options' => [
257-
null => 'None',
257+
'' => 'None',
258258
'text' => 'Text',
259259
'image' => 'Image',
260260
'variable' => 'Variable'

library/Reporting/Web/Widget/CompatDropdown.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class CompatDropdown extends Dropdown
1111
{
12-
public function addLink($content, $url, $icon = null, array $attributes = null)
12+
public function addLink($content, $url, $icon = null, ?array $attributes = null)
1313
{
1414
$link = new ActionLink($content, $url, $icon, ['class' => 'dropdown-item']);
1515
if (! empty($attributes)) {

library/Reporting/Web/Widget/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Template extends BaseHtmlElement
2727

2828
protected $preview;
2929

30-
public static function getDataUrl(array $image = null)
30+
public static function getDataUrl(?array $image = null)
3131
{
3232
if (empty($image)) {
3333
return 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';

0 commit comments

Comments
 (0)