Support PHP 8.5 (#489)
Some checks failed
L10n Update / update (push) Has been cancelled
CI / PHP (push) Has been cancelled

PHP 8.3 -> PHP 8.4:

* Function parameters that are null by default must be declared nullable.
* The E_STRICT error level has been deprecated
* The `$escape`  parameter of  `fputcsv()` must be set explicitly

PHP 8.4 -> PHP 8.5:

* Using null as an array offset is deprecated.

Additionally the `required` attribute of the `uploaded_file` element in
`BpUploadForm` was set to true.
Previously the form could be submitted without a file causing an exception.
This commit is contained in:
Eric Lippmann 2026-01-09 13:06:55 +01:00 committed by GitHub
commit b756147764
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 35 additions and 32 deletions

View file

@ -185,7 +185,7 @@ class ProcessCommand extends Command
}
}
protected function renderProblemTree($tree, $useColors = false, $depth = 0, BpNode $parent = null)
protected function renderProblemTree($tree, $useColors = false, $depth = 0, ?BpNode $parent = null)
{
$output = '';

View file

@ -264,7 +264,7 @@ class ProcessController extends Controller
$bp->applySimulation($simulation);
}
protected function loadActionForm(BpConfig $bp, Node $node = null)
protected function loadActionForm(BpConfig $bp, ?Node $node = null)
{
$action = $this->params->get('action');
$form = null;
@ -720,7 +720,7 @@ class ProcessController extends Controller
return $tabs;
}
protected function handleFormatRequest(BpConfig $bp, BpNode $node = null)
protected function handleFormatRequest(BpConfig $bp, ?BpNode $node = null)
{
$desiredContentType = $this->getRequest()->getHeader('Accept');
if ($desiredContentType === 'application/json') {
@ -747,7 +747,7 @@ class ProcessController extends Controller
case 'csv':
$csv = fopen('php://temp', 'w');
fputcsv($csv, ['Path', 'Name', 'State', 'Since', 'In_Downtime']);
fputcsv($csv, ['Path', 'Name', 'State', 'Since', 'In_Downtime'], escape: '\\');
foreach ($node !== null ? $node->toArray(null, true) : $bp->toArray(true) as $node) {
$data = [$node['path'], $node['name']];
@ -764,7 +764,7 @@ class ProcessController extends Controller
$data[] = $node['in_downtime'];
}
fputcsv($csv, $data);
fputcsv($csv, $data, escape: '\\');
}
$response = $this->getResponse();

View file

@ -73,7 +73,7 @@ class AddNodeForm extends CompatForm
*
* @return $this
*/
public function setParentNode(BpNode $node = null): self
public function setParentNode(?BpNode $node = null): self
{
$this->parent = $node;

View file

@ -66,7 +66,7 @@ class BpConfigForm extends BpConfigBaseForm
. ' this process should be retrieved from'
),
'multiOptions' => array(
null => $this->translate('Use the configured default backend'),
'' => $this->translate('Use the configured default backend'),
) + $this->listAvailableBackends()
));
}

View file

@ -142,6 +142,7 @@ class BpUploadForm extends BpConfigBaseForm
/** @var \Zend_Form_Element_File $el */
$el = $this->getElement('uploaded_file');
$el->setValueDisabled(true);
$el->setAttrib('required', true);
$this->setSubmitLabel(
$this->translate('Next')

View file

@ -84,7 +84,7 @@ class DeleteNodeForm extends BpConfigBaseForm
* @param BpNode|null $node
* @return $this
*/
public function setParentNode(BpNode $node = null)
public function setParentNode(?BpNode $node = null)
{
$this->parentNode = $node;
return $this;

View file

@ -76,7 +76,7 @@ class EditNodeForm extends CompatForm
*
* @return $this
*/
public function setParentNode(BpNode $node = null): self
public function setParentNode(?BpNode $node = null): self
{
$this->parent = $node;

View file

@ -110,7 +110,7 @@ class MoveNodeForm extends BpConfigBaseForm
* @param BpNode|null $node
* @return $this
*/
public function setParentNode(BpNode $node = null)
public function setParentNode(?BpNode $node = null)
{
$this->parentNode = $node;
return $this;

View file

@ -127,7 +127,7 @@ class SimulationForm extends BpConfigBaseForm
protected function enumStateNames()
{
$states = array(
null => sprintf(
'' => sprintf(
$this->translate('Use current state (%s)'),
$this->translate($this->node->getStateName())
)

View file

@ -133,8 +133,9 @@ class BpConfig
/** @var bool Whether the config is faulty */
protected $isFaulty = false;
public function __construct()
public function __construct(string $name = 'dummy')
{
$this->setName($name);
}
/**

View file

@ -112,7 +112,7 @@ class Metadata
return Auth::getInstance();
}
public function canModify(Auth $auth = null)
public function canModify(?Auth $auth = null)
{
if ($auth === null) {
if (Icinga::app()->isCli()) {
@ -128,7 +128,7 @@ class Metadata
);
}
public function canRead(Auth $auth = null)
public function canRead(?Auth $auth = null)
{
if ($auth === null) {
if (Icinga::app()->isCli()) {

View file

@ -69,12 +69,12 @@ class ProcessChanges
}
/**
* @param Node $node
* @param ?Node $node
* @param $properties
*
* @return $this
*/
public function addChildrenToNode($children, Node $node = null)
public function addChildrenToNode($children, ?Node $node = null)
{
$action = new NodeAddChildrenAction($node);
$action->setChildren($children);
@ -88,7 +88,7 @@ class ProcessChanges
*
* @return $this
*/
public function createNode($nodeName, $properties, Node $parent = null)
public function createNode($nodeName, $properties, ?Node $parent = null)
{
$action = new NodeCreateAction($nodeName);
$action->setProperties($properties);

View file

@ -7,7 +7,7 @@ use Icinga\Module\Businessprocess\Monitoring\Backend\Ido\Query\HostStatusQuery;
class HostStatus extends \Icinga\Module\Monitoring\DataView\Hoststatus
{
public function __construct(ConnectionInterface $connection, array $columns = null)
public function __construct(ConnectionInterface $connection, ?array $columns = null)
{
parent::__construct($connection, $columns);

View file

@ -7,7 +7,7 @@ use Icinga\Module\Businessprocess\Monitoring\Backend\Ido\Query\ServiceStatusQuer
class ServiceStatus extends \Icinga\Module\Monitoring\DataView\Servicestatus
{
public function __construct(ConnectionInterface $connection, array $columns = null)
public function __construct(ConnectionInterface $connection, ?array $columns = null)
{
parent::__construct($connection, $columns);

View file

@ -536,12 +536,12 @@ abstract class Node
/**
* Export the node to array
*
* @param array $parent The node's parent. Used to construct the path to the node
* @param ?array $parent The node's parent. Used to construct the path to the node
* @param bool $flat If false, children will be added to the array key children, else the array will be flat
*
* @return array
*/
public function toArray(array $parent = null, $flat = false)
public function toArray(?array $parent = null, $flat = false)
{
$data = [
'name' => $this->getAlias(),

View file

@ -47,7 +47,7 @@ abstract class Renderer extends HtmlDocument
* @param BpConfig $config
* @param BpNode|null $parent
*/
public function __construct(BpConfig $config, BpNode $parent = null)
public function __construct(BpConfig $config, ?BpNode $parent = null)
{
$this->config = $config;
$this->parent = $parent;

View file

@ -112,11 +112,11 @@ class TreeRenderer extends Renderer
/**
* @param Node $node
* @param array $path
* @param BpNode $parent
* @param ?array $path
* @param ?BpNode $parent
* @return BaseHtmlElement[]
*/
public function getNodeIcons(Node $node, array $path = null, BpNode $parent = null)
public function getNodeIcons(Node $node, ?array $path = null, ?BpNode $parent = null)
{
$icons = [];
if (empty($path) && $node instanceof BpNode) {

View file

@ -8,7 +8,7 @@ use Icinga\Exception\ProgrammingError;
class FormLoader
{
public static function load($name, Module $module = null)
public static function load($name, ?Module $module = null)
{
if ($module === null) {
$basedir = Icinga::app()->getApplicationDir('forms');

View file

@ -116,7 +116,7 @@ abstract class QuickBaseForm extends Zend_Form implements ValidHtml
$nullLabel = $this->translate('- please choose -');
}
return array(null => $nullLabel) + $enum;
return array('' => $nullLabel) + $enum;
}
protected function handleOptions($options = null)
@ -140,7 +140,7 @@ abstract class QuickBaseForm extends Zend_Form implements ValidHtml
return $this;
}
protected function loadForm($name, Module $module = null)
protected function loadForm($name, ?Module $module = null)
{
if ($module === null) {
$module = $this->icingaModule;

View file

@ -130,9 +130,10 @@ abstract class QuickForm extends QuickBaseForm
)
);
$grp = array(
$this->submitButtonName,
$this->deleteButtonName
// Add display group for defined buttons only
$grp = array_filter(
[$this->submitButtonName, $this->deleteButtonName],
fn($x) => $x !== null
);
$this->addDisplayGroup($grp, 'buttons', array(
'decorators' => array(
@ -325,7 +326,7 @@ abstract class QuickForm extends QuickBaseForm
return $this;
}
public function handleRequest(Request $request = null)
public function handleRequest(?Request $request = null)
{
if ($request === null) {
$request = $this->getRequest();