Change implicit nullable type declaration to explicit

Since PHP 8.4 implicitly nullable parameter types are deprecated.

Normalize scoped PHPDoc for nullable-parameter updates: use `?Type` instead of
`Type|null` and remove column alignment.

Co-authored-by: "Eric Lippmann <eric.lippmann@icinga.com>"
This commit is contained in:
Bastian Lederer 2025-12-01 13:56:21 +01:00 committed by Eric Lippmann
parent 15a3a6d72c
commit 8622514fcd
24 changed files with 78 additions and 78 deletions

View file

@ -787,7 +787,7 @@ class MigrateCommand extends Command
return $config;
}
private function createBackupIni(string $path, Config $config = null): void
private function createBackupIni(string $path, ?Config $config = null): void
{
$counter = 0;
while (true) {

View file

@ -676,13 +676,13 @@ class RedisConfigForm extends ConfigForm
* Wraps the given IPL validator class into a callback validator
* for usage as the only validator of the element given by name.
*
* @param string $cls IPL validator class FQN
* @param string $element Form element name
* @param Closure $additionalValidator
* @param string $cls IPL validator class FQN
* @param string $element Form element name
* @param ?Closure $additionalValidator
*
* @return array Callback validator
* @return array Callback validator
*/
private function wrapIplValidator(string $cls, string $element, Closure $additionalValidator = null): array
private function wrapIplValidator(string $cls, string $element, ?Closure $additionalValidator = null): array
{
return [
'Callback',

View file

@ -118,11 +118,11 @@ class ProcessCheckResultCommand extends ObjectsCommand
/**
* Set the performance data of the host or service check result
*
* @param string|null $performanceData
* @param ?string $performanceData
*
* @return $this
* @return $this
*/
public function setPerformanceData(string $performanceData = null): self
public function setPerformanceData(?string $performanceData = null): self
{
$this->performanceData = $performanceData;

View file

@ -301,13 +301,13 @@ class ApiCommandTransport implements CommandTransportInterface
* Send the Icinga command over the Icinga 2 API
*
* @param IcingaCommand|IcingaApiCommand $command
* @param int|null $now
* @param ?int $now
*
* @throws CommandTransportException
*
* @return mixed
*/
public function send(IcingaCommand|IcingaApiCommand $command, int $now = null)
public function send(IcingaCommand|IcingaApiCommand $command, ?int $now = null)
{
if ($command instanceof IcingaCommand) {
$command = $this->renderer->render($command);

View file

@ -94,14 +94,14 @@ class CommandTransport implements CommandTransportInterface
*
* This will try one configured transport after another until the command has been successfully sent.
*
* @param IcingaCommand $command The command to send
* @param int|null $now Timestamp of the command or null for now
* @param IcingaCommand $command The command to send
* @param ?int $now Timestamp of the command or null for now
*
* @throws CommandTransportException If sending the Icinga command failed
* @return mixed
*
* @return mixed
* @throws CommandTransportException If sending the Icinga command failed
*/
public function send(IcingaCommand $command, int $now = null)
public function send(IcingaCommand $command, ?int $now = null)
{
$errors = [];
$results = [];

View file

@ -15,10 +15,10 @@ interface CommandTransportInterface
/**
* Send an Icinga command over the Icinga command transport
*
* @param IcingaCommand $command The command to send
* @param int|null $now Timestamp of the command or null for now
* @param IcingaCommand $command The command to send
* @param ?int $now Timestamp of the command or null for now
*
* @throws CommandTransportException If sending the Icinga command failed
* @throws CommandTransportException If sending the Icinga command failed
*/
public function send(IcingaCommand $command, int $now = null);
public function send(IcingaCommand $command, ?int $now = null);
}

View file

@ -47,13 +47,13 @@ class HostStates
/**
* Get the textual representation of the passed host state
*
* @param int|null $state
* @param ?int $state
*
* @return string
*
* @throws \InvalidArgumentException If the given host state is invalid, i.e. not known
*/
public static function text(int $state = null): string
public static function text(?int $state = null): string
{
switch (true) {
case $state === self::UP:
@ -78,13 +78,13 @@ class HostStates
/**
* Get the translated textual representation of the passed host state
*
* @param int|null $state
* @param ?int $state
*
* @return string
*
* @throws \InvalidArgumentException If the given host state is invalid, i.e. not known
*/
public static function translated(int $state = null): string
public static function translated(?int $state = null): string
{
switch (true) {
case $state === self::UP:

View file

@ -173,11 +173,11 @@ class IcingaRedis
/**
* Get the last icinga heartbeat from redis
*
* @param Redis|null $redis
* @param ?Redis $redis
*
* @return float|int|null
*/
public static function getLastIcingaHeartbeat(Redis $redis = null)
public static function getLastIcingaHeartbeat(?Redis $redis = null)
{
if ($redis === null) {
$redis = Backend::getRedis()->getConnection();
@ -201,12 +201,12 @@ class IcingaRedis
/**
* Get the primary redis instance
*
* @param Config|null $moduleConfig
* @param Config|null $redisConfig
* @param ?Config $moduleConfig
* @param ?Config $redisConfig
*
* @return Redis
*/
public static function getPrimaryRedis(Config $moduleConfig = null, Config $redisConfig = null): Redis
public static function getPrimaryRedis(?Config $moduleConfig = null, ?Config $redisConfig = null): Redis
{
if ($moduleConfig === null) {
$moduleConfig = Config::module('icingadb');
@ -235,12 +235,12 @@ class IcingaRedis
/**
* Get the secondary redis instance if exists
*
* @param Config|null $moduleConfig
* @param Config|null $redisConfig
* @param ?Config $moduleConfig
* @param ?Config $redisConfig
*
* @return ?Redis
*/
public static function getSecondaryRedis(Config $moduleConfig = null, Config $redisConfig = null)
public static function getSecondaryRedis(?Config $moduleConfig = null, ?Config $redisConfig = null)
{
if ($moduleConfig === null) {
$moduleConfig = Config::module('icingadb');

View file

@ -57,13 +57,13 @@ class ServiceStates
/**
* Get the textual representation of the passed service state
*
* @param int|null $state
* @param ?int $state
*
* @return string
*
* @throws \InvalidArgumentException If the given service state is invalid, i.e. not known
*/
public static function text(int $state = null): string
public static function text(?int $state = null): string
{
switch (true) {
case $state === self::OK:
@ -94,13 +94,13 @@ class ServiceStates
/**
* Get the translated textual representation of the passed service state
*
* @param int|null $state
* @param ?int $state
*
* @return string
*
* @throws \InvalidArgumentException If the given service state is invalid, i.e. not known
*/
public static function translated(int $state = null): string
public static function translated(?int $state = null): string
{
switch (true) {
case $state === self::OK:

View file

@ -118,7 +118,7 @@ abstract class StateBadges extends BaseHtmlElement
*
* @return Link
*/
protected function createLink($content, Filter\Rule $filter = null): Link
protected function createLink($content, ?Filter\Rule $filter = null): Link
{
$url = clone $this->getUrl();

View file

@ -84,7 +84,7 @@ class UrlMigrator
return $url;
}
public static function transformParams(Url $url, string $transformerName = null): array
public static function transformParams(Url $url, ?string $transformerName = null): array
{
$transformer = new self();
@ -153,11 +153,11 @@ class UrlMigrator
* Transform the given legacy filter
*
* @param Filter\Rule $filter
* @param string|null $queryTransformer
* @param ?string $queryTransformer
*
* @return Filter\Rule|false
*/
public static function transformFilter(Filter\Rule $filter, string $queryTransformer = null)
public static function transformFilter(Filter\Rule $filter, ?string $queryTransformer = null)
{
$transformer = new self();

View file

@ -115,11 +115,11 @@ class PivotTable
/**
* Set the filter to apply on the query for the x-axis
*
* @param Filter\Rule $filter
* @param ?Filter\Rule $filter
*
* @return $this
* @return $this
*/
public function setXAxisFilter(Filter\Rule $filter = null): self
public function setXAxisFilter(?Filter\Rule $filter = null): self
{
$this->xAxisFilter = $filter;
return $this;
@ -128,11 +128,11 @@ class PivotTable
/**
* Set the filter to apply on the query for the y-axis
*
* @param Filter\Rule $filter
* @param ?Filter\Rule $filter
*
* @return $this
* @return $this
*/
public function setYAxisFilter(Filter\Rule $filter = null): self
public function setYAxisFilter(?Filter\Rule $filter = null): self
{
$this->yAxisFilter = $filter;
return $this;
@ -203,13 +203,13 @@ class PivotTable
/**
* Return the value for the given request parameter
*
* @param string $axis The axis for which to return the parameter ('x' or 'y')
* @param string $param The parameter name to return
* @param int $default The default value to return
* @param string $axis The axis for which to return the parameter ('x' or 'y')
* @param string $param The parameter name to return
* @param ?int $default The default value to return
*
* @return int
* @return int
*/
protected function getPaginationParameter(string $axis, string $param, int $default = null): int
protected function getPaginationParameter(string $axis, string $param, ?int $default = null): int
{
/** @var Web $app */
$app = Icinga::app();
@ -326,12 +326,12 @@ class PivotTable
*
* $limit and $page are taken from the current request if not given.
*
* @param int $limit The maximum amount of entries to fetch
* @param int $page The page to set as current one
* @param ?int $limit The maximum amount of entries to fetch
* @param ?int $page The page to set as current one
*
* @return Paginatable
* @return Paginatable
*/
public function paginateXAxis(int $limit = null, int $page = null): Paginatable
public function paginateXAxis(?int $limit = null, ?int $page = null): Paginatable
{
if ($limit === null || $page === null) {
if ($limit === null) {
@ -358,12 +358,12 @@ class PivotTable
*
* $limit and $page are taken from the current request if not given.
*
* @param int $limit The maximum amount of entries to fetch
* @param int $page The page to set as current one
* @param ?int $limit The maximum amount of entries to fetch
* @param ?int $page The page to set as current one
*
* @return Paginatable
* @return Paginatable
*/
public function paginateYAxis(int $limit = null, int $page = null): Paginatable
public function paginateYAxis(?int $limit = null, ?int $page = null): Paginatable
{
if ($limit === null || $page === null) {
if ($limit === null) {

View file

@ -14,7 +14,7 @@ use function ipl\I18n\t;
trait TotalSlaReportUtils
{
public function getHtml(Timerange $timerange, array $config = null)
public function getHtml(Timerange $timerange, ?array $config = null)
{
$data = $this->getData($timerange, $config);
$count = $data->count();

View file

@ -86,7 +86,7 @@ class UnreachableParent extends DependencyNode
]));
}
public static function on(Connection $db, Model $root = null): Query
public static function on(Connection $db, ?Model $root = null): Query
{
if ($root === null) {
throw new InvalidArgumentException('Root node must not be null');

View file

@ -45,7 +45,7 @@ class HostSlaReport extends SlaReport
->setValues([(float) $row->sla]);
}
protected function fetchSla(Timerange $timerange, Rule $filter = null)
protected function fetchSla(Timerange $timerange, ?Rule $filter = null)
{
$sla = Host::on($this->getDb())
->columns([

View file

@ -45,7 +45,7 @@ class ServiceSlaReport extends SlaReport
->setValues([(float) $row->sla]);
}
protected function fetchSla(Timerange $timerange, Rule $filter = null)
protected function fetchSla(Timerange $timerange, ?Rule $filter = null)
{
$sla = Service::on($this->getDb())
->columns([

View file

@ -56,13 +56,13 @@ abstract class SlaReport extends ReportHook
* Fetch SLA according to specified time range and filter
*
* @param Timerange $timerange
* @param Rule|null $filter
* @param ?Rule $filter
*
* @return iterable
*/
abstract protected function fetchSla(Timerange $timerange, Rule $filter = null);
abstract protected function fetchSla(Timerange $timerange, ?Rule $filter = null);
protected function fetchReportData(Timerange $timerange, array $config = null)
protected function fetchReportData(Timerange $timerange, ?array $config = null)
{
$rd = $this->createReportData();
$rows = [];
@ -214,12 +214,12 @@ abstract class SlaReport extends ReportHook
]);
}
public function getData(Timerange $timerange, array $config = null)
public function getData(Timerange $timerange, ?array $config = null)
{
return $this->fetchReportData($timerange, $config);
}
public function getHtml(Timerange $timerange, array $config = null)
public function getHtml(Timerange $timerange, ?array $config = null)
{
$data = $this->getData($timerange, $config);

View file

@ -21,7 +21,7 @@ class Sni extends SniHook
/**
* @inheritDoc
*/
public function getHosts(Filter $filter = null): Generator
public function getHosts(?Filter $filter = null): Generator
{
$this->getDb()->ping();

View file

@ -135,11 +135,11 @@ class PerfDataSet implements IteratorAggregate
* Return all characters between the current parser position and the given character
*
* @param string $stopChar The character on which to stop
* @param string $backtrackOn The character on which to backtrack
* @param ?string $backtrackOn The character on which to backtrack
*
* @return string
*/
protected function readUntil(string $stopChar, string $backtrackOn = null): string
protected function readUntil(string $stopChar, ?string $backtrackOn = null): string
{
$start = $this->parserPos;
$breakCharEncounteredAt = null;

View file

@ -319,11 +319,11 @@ class Controller extends CompatController
/**
* Require permission to access the given route
*
* @param string $name If NULL, the current controller name is used
* @param ?string $name If NULL, the current controller name is used
*
* @throws SecurityException
*/
public function assertRouteAccess(string $name = null)
public function assertRouteAccess(?string $name = null)
{
if (! $name) {
$name = $this->getRequest()->getControllerName();
@ -451,7 +451,7 @@ class Controller extends CompatController
return parent::addContent($content);
}
public function filter(Query $query, Filter\Rule $filter = null): self
public function filter(Query $query, ?Filter\Rule $filter = null): self
{
if ($this->format !== 'sql' || $this->hasPermission('config/authentication/roles/show')) {
$this->applyRestrictions($query);

View file

@ -115,7 +115,7 @@ abstract class ProblemsBadge extends NavigationItemRenderer
return $this->title;
}
public function render(NavigationItem $item = null): string
public function render(?NavigationItem $item = null): string
{
if ($item === null) {
$item = $this->getItem();

View file

@ -52,7 +52,7 @@ class CustomVarTable extends BaseHtmlElement
* @param iterable $data
* @param ?Model $object
*/
public function __construct($data, Model $object = null)
public function __construct($data, ?Model $object = null)
{
$this->data = $data;
$this->object = $object;

View file

@ -28,7 +28,7 @@ class ShowMore extends BaseHtmlElement
/** @var ?string */
protected $label;
public function __construct(ResultSet $resultSet, Url $url, string $label = null)
public function __construct(ResultSet $resultSet, Url $url, ?string $label = null)
{
$this->label = $label;
$this->resultSet = $resultSet;

View file

@ -84,7 +84,7 @@ class StateBadgesTest extends TestCase
return 0;
}
public function generateLink($content, Filter\Rule $filter = null): Link
public function generateLink($content, ?Filter\Rule $filter = null): Link
{
return parent::createLink($content, $filter);
}