Fix wrong method param types and add var type hints

This commit is contained in:
Sukhwinder Dhillon 2024-01-17 16:16:31 +01:00 committed by Johannes Meyer
parent 3fc16910f7
commit d879186f0e
20 changed files with 52 additions and 36 deletions

View File

@ -370,7 +370,7 @@ class ConfigController extends ActionController
$configs = $db->enumDeployedConfigs();
foreach (array($leftSum, $rightSum) as $sum) {
if (! array_key_exists($sum, $configs)) {
if ($sum && ! array_key_exists($sum, $configs)) {
$configs[$sum] = substr($sum, 0, 7);
}
}

View File

@ -275,7 +275,7 @@ class SelfServiceController extends ActionController
// PluginsUrl => framework_plugins_url
];
$username = $settings->get('self-service/icinga_service_user');
if ($username !== null && strlen($username) > 0) {
if ($username) {
$params['icinga_service_user'] = $username;
}
@ -404,7 +404,7 @@ class SelfServiceController extends ActionController
{
foreach ($keys as $key) {
$value = $settings->get("self-service/$key");
if (strlen($value)) {
if ($value) {
$params[$key] = $value;
}
}

View File

@ -55,7 +55,7 @@ class SyncCheckForm extends DirectorForm
} elseif ($sum['modify'] > 1) {
}
*/
$html = '<pre>' . print_r($sum, 1) . '</pre>';
$html = '<pre>' . print_r($sum, true) . '</pre>';
$this->addHtml($html);
} elseif ($this->rule->get('sync_state') === 'in-sync') {

View File

@ -44,14 +44,16 @@ class Zend_View_Helper_FormDataFilter extends Zend_View_Helper_FormElement
{
$info = $this->_getInfo($name, $value, $attribs);
extract($info); // id, name, value, attribs, options, listsep, disable
if (array_key_exists('columns', $attribs)) {
$this->setColumns($attribs['columns']);
unset($attribs['columns']);
}
if ($attribs) {
if (array_key_exists('columns', $attribs)) {
$this->setColumns($attribs['columns']);
unset($attribs['columns']);
}
if (array_key_exists('suggestionContext', $attribs)) {
$this->setSuggestionContext($attribs['suggestionContext']);
unset($attribs['suggestionContext']);
if (array_key_exists('suggestionContext', $attribs)) {
$this->setSuggestionContext($attribs['suggestionContext']);
unset($attribs['suggestionContext']);
}
}
// TODO: check for columns in attribs, preserve & remove them from the

View File

@ -428,7 +428,7 @@ class ObjectCommand extends Command
}
$stdin = file_get_contents('php://stdin');
if (strlen($stdin) === 0) {
if (! $stdin) {
return null;
}

View File

@ -569,7 +569,7 @@ constants
'icon_image_alt' => 'icon_image_alt',
];
if (version_compare($this->getVersion(), '2.8.0', '>=')) {
if (version_compare($this->getVersion() ?? '', '2.8.0', '>=')) {
$params['flapping_threshold_high'] = 'flapping_threshold_high';
$params['flapping_threshold_low'] = 'flapping_threshold_low';
}

View File

@ -128,6 +128,10 @@ class LegacyDeploymentApi implements DeploymentApiInterface
if (file_exists($path)) {
if (is_link($path)) {
$linkTarget = readlink($path);
if (! $linkTarget) {
throw new IcingaException('Failed to read symlink');
}
$linkTargetDir = dirname($linkTarget);
$linkTargetName = basename($linkTarget);
@ -165,7 +169,7 @@ class LegacyDeploymentApi implements DeploymentApiInterface
$this->assertDeploymentPath();
$dh = @opendir($this->deploymentPath);
if ($dh === null) {
if ($dh === false) {
throw new IcingaException('Can not list contents of %s', $this->deploymentPath);
}
@ -279,7 +283,7 @@ class LegacyDeploymentApi implements DeploymentApiInterface
$this->mkdir(dirname($fullPath), true);
$fh = @fopen($fullPath, 'w');
if ($fh === null) {
if ($fh === false) {
throw new IcingaException('Could not open file "%s" for writing.', $fullPath);
}
chmod($fullPath, $this->file_mode);
@ -334,7 +338,7 @@ class LegacyDeploymentApi implements DeploymentApiInterface
protected function listDirectoryContents($path, $depth = 0)
{
$dh = @opendir($path);
if ($dh === null) {
if ($dh === false) {
throw new IcingaException('Can not list contents of %s', $path);
}

View File

@ -104,7 +104,7 @@ class BackgroundDaemon
try {
$uuid = \bin2hex(Uuid::uuid4()->getBytes());
} catch (Exception $e) {
$uuid = 'deadc0de' . \substr(\md5(\getmypid()), 0, 24);
$uuid = 'deadc0de' . substr(md5((string) getmypid()), 0, 24);
}
}
$processDetails = new DaemonProcessDetails($uuid);

View File

@ -44,11 +44,11 @@ class ObjectPurgeHelper
// TODO: this is object-specific and to be found in the ::import() function!
unset($properties['fields']);
$object = $class::fromPlainObject($properties);
} elseif (\get_class($object) !== $class) {
} elseif (get_class($object) !== $class) {
throw new InvalidArgumentException(
'Can keep only matching objects, expected "%s", got "%s',
$class,
\get_class($keep)
get_class($object)
);
}
$key = [];

View File

@ -69,6 +69,7 @@ class ImportSourceRestApi extends ImportSourceHook
$data = $result;
foreach ($parts as $part) {
// un-escape any dots
/** @var string $part */
$part = preg_replace('~\\\\.~', '.', $part);
if (property_exists($data, $part)) {

View File

@ -127,10 +127,8 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments, ExportI
// return $value;
}
if (self::$pluginDir !== null) {
if (($pos = strpos($value, self::$pluginDir)) === 0) {
$value = substr($value, strlen(self::$pluginDir) + 1);
}
if (isset($value, self::$pluginDir) && strpos($value, self::$pluginDir) === 0) {
$value = substr($value, strlen(self::$pluginDir) + 1);
}
return $value;

View File

@ -34,7 +34,8 @@ class PropertyModifierGetHostByName extends PropertyModifierHook
}
$host = gethostbyname($value);
if (strlen(@inet_pton($host)) !== 4) {
$inAddr = inet_pton($host);
if (! $inAddr || strlen($inAddr) !== 4) {
switch ($this->getSetting('on_failure')) {
case 'null':
return null;

View File

@ -7,6 +7,7 @@ use Icinga\Exception\ProgrammingError;
use Icinga\Module\Cube\Hook\IcingaDbActionsHook;
use Icinga\Module\Cube\IcingaDb\IcingaDbCube;
use Icinga\Module\Cube\IcingaDb\IcingaDbHostStatusCube;
use ipl\Stdlib\Filter\Condition;
class IcingaDbCubeLinks extends IcingaDbActionsHook
{
@ -25,17 +26,19 @@ class IcingaDbCubeLinks extends IcingaDbActionsHook
if ($filterChain->count() === 1) {
$url = 'director/host/edit?';
$params = ['name' => $filterChain->getIterator()->current()->getValue()];
/** @var Condition $rule */
$rule = $filterChain->getIterator()->current();
/** @var string $name */
$name = $rule->getValue();
$params = ['name' => $name];
$title = t('Modify a host');
$description = sprintf(
t('This allows you to modify properties for "%s"'),
$filterChain->getIterator()->current()->getValue()
);
$description = sprintf(t('This allows you to modify properties for "%s"'), $name);
} else {
$params = null;
$urlFilter = Filter::matchAny();
/** @var Condition $filter */
foreach ($filterChain as $filter) {
$urlFilter->addFilter(
Filter::matchAny(

View File

@ -19,8 +19,9 @@ class RestApiParams
}
$exporter->enableHostServices();
}
/** @var ?string $properties */
$properties = $params->shift('properties');
if ($properties !== null && strlen($properties)) {
if ($properties) {
$exporter->filterProperties(preg_split('/\s*,\s*/', $properties, -1, PREG_SPLIT_NO_EMPTY));
}
$exporter->resolveObjects($resolved);

View File

@ -33,7 +33,9 @@ class StartupLogRenderer implements ValidHtml
// len [stage] + 1
$markReplace = ' ^';
foreach (preg_split('/\n/', $log) as $line) {
/** @var string[] $logLines */
$logLines = preg_split('/\n/', $log);
foreach ($logLines as $line) {
if (preg_match('/^\[([\d\s\:\+\-]+)\]\s/', $line, $m)) {
$time = $m[1];
// TODO: we might use new DateTime($time) and show a special "timeAgo"

View File

@ -85,8 +85,9 @@ abstract class ObjectsController extends ActionController
} elseif ($request->getActionName() === 'applyrules') {
$table->filterObjectType('apply');
}
/** @var ?string $search */
$search = $this->params->get('q');
if ($search !== null && \strlen($search) > 0) {
if ($search) {
$table->search($search);
}

View File

@ -17,7 +17,7 @@ class CsrfToken
return false;
}
list($seed, $token) = explode('|', $elementValue);
list($seed, $token) = explode('|', $token);
if (!is_numeric($seed)) {
return false;

View File

@ -69,7 +69,7 @@ class DbSelectorForm extends Form
$params = [];
}
if (array_key_exists($name, $params)) {
if (is_array($params) && array_key_exists($name, $params)) {
return $params[$name];
}

View File

@ -791,7 +791,9 @@ abstract class DirectorObjectForm extends DirectorForm
return;
}
$post = $values = $this->getRequest()->getPost();
/** @var array $post */
$post = $this->getRequest()->getPost();
$values = $post;
foreach ($post as $key => $value) {
if (preg_match('/^(.+?)_(\d+)__(MOVE_DOWN|MOVE_UP|REMOVE)$/', $key, $m)) {
@ -1519,6 +1521,7 @@ abstract class DirectorObjectForm extends DirectorForm
return [];
}
/** @var int|string $id */
$id = $object->get('id');
if (array_key_exists($id, $tpl)) {

View File

@ -205,7 +205,7 @@ class IcingaObjectInspection extends BaseHtmlElement
$this->add(Html::tag('p')->add(Html::sprintf(
'The configuration for this object has been rendered by Icinga'
. ' Director %s to %s',
DateFormatter::timeAgo(strtotime($deployment->start_time, false)),
DateFormatter::timeAgo(strtotime($deployment->start_time)),
$this->linkToSourceLocation($deployment, $source)
)));
}