Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phpstan: Fix deprecated function param types #2858

Merged
merged 10 commits into from
Feb 5, 2024
2 changes: 1 addition & 1 deletion application/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public function diffAction()

$configs = $db->enumDeployedConfigs();
foreach (array($leftSum, $rightSum) as $sum) {
if (! array_key_exists($sum, $configs)) {
if ($sum && ! array_key_exists($sum, $configs)) {
nilmerg marked this conversation as resolved.
Show resolved Hide resolved
$configs[$sum] = substr($sum, 0, 7);
}
}
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/ImportsourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function indexAction()
}

$this->addTitle($this->translate('Import source'))
->setAutoRefreshInterval(10)
->setAutorefreshInterval(10)
->addAddLink(
$this->translate('Add a new Import Source'),
'director/importsource/add'
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/JobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class JobsController extends ActionController
public function indexAction()
{
$this->addTitle($this->translate('Jobs'))
->setAutoRefreshInterval(10)
->setAutorefreshInterval(10)
->addAddLink($this->translate('Add a new Job'), 'director/job/add')
->tabs(new ImportTabs())->activate('jobs');

Expand Down
2 changes: 1 addition & 1 deletion application/controllers/SchemaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function loadSchema($type)
return file_get_contents(
sprintf(
'%s/schema/%s.sql',
$this->Module()->getBasedir(),
$this->Module()->getBaseDir(),
$type
)
);
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/SelfServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected function makePowerShellBoolean($value)
} else {
throw new ProgrammingError(
'Expected boolean value, got %s',
var_export($value, 1)
var_export($value, true)
);
}
}
Expand Down Expand Up @@ -275,7 +275,7 @@ protected function shipPowershellParams()
// 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;
}

Expand Down Expand Up @@ -404,7 +404,7 @@ protected function addStringSettingsToParams(Settings $settings, array $keys, ar
{
foreach ($keys as $key) {
$value = $settings->get("self-service/$key");
if (strlen($value)) {
if ($value) {
$params[$key] = $value;
}
}
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/SyncruleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SyncruleController extends ActionController
*/
public function indexAction()
{
$this->setAutoRefreshInterval(10);
$this->setAutorefreshInterval(10);
$rule = $this->requireSyncRule();
$this->tabs(new SyncRuleTabs($rule))->activate('show');
$ruleName = $rule->get('rule_name');
Expand Down Expand Up @@ -642,7 +642,7 @@ public function addpropertyAction()
*/
public function historyAction()
{
$this->setAutoRefreshInterval(30);
$this->setAutorefreshInterval(30);
$rule = $this->requireSyncRule();
$this->tabs(new SyncRuleTabs($rule))->activate('history');
$this->addTitle($this->translate('Sync history') . ': ' . $rule->get('rule_name'));
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/SyncrulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function indexAction()
}

$this->addTitle($this->translate('Sync rule'))
->setAutoRefreshInterval(10)
->setAutorefreshInterval(10)
->addAddLink(
$this->translate('Add a new Sync Rule'),
'director/syncrule/add'
Expand Down
4 changes: 2 additions & 2 deletions application/forms/IcingaTemplateChoiceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function optionallyLoad($name)
{
if ($name !== null) {
/** @var IcingaTemplateChoice $class - cheating IDE */
$class = $this->getObjectClassName();
$class = $this->getObjectClassname();
$this->setObject($class::load($name, $this->getDb()));
}

Expand Down Expand Up @@ -133,7 +133,7 @@ protected function setObjectSuccessUrl()
/** @var IcingaTemplateChoice $object */
$object = $this->object();
$this->setSuccessUrl(
'director/templatechoice/' . $object->getObjectshortTableName(),
'director/templatechoice/' . $object->getObjectShortTableName(),
$object->getUrlParams()
);
}
Expand Down
2 changes: 1 addition & 1 deletion application/forms/SyncCheckForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function onSuccess()
} 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') {
Expand Down
16 changes: 9 additions & 7 deletions application/views/helpers/FormDataFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ public function formDataFilter($name, $value = null, $attribs = null)
{
$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
Expand Down
4 changes: 2 additions & 2 deletions library/Director/Cli/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ protected function raiseLimits()
{
MemoryLimit::raiseTo('1024M');

ini_set('max_execution_time', 0);
ini_set('max_execution_time', '0');
if (version_compare(PHP_VERSION, '7.0.0') < 0) {
ini_set('zend.enable_gc', 0);
ini_set('zend.enable_gc', '0');
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion library/Director/Cli/ObjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ protected function readFromStdin()
}

$stdin = file_get_contents('php://stdin');
if (strlen($stdin) === 0) {
if (! $stdin) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Director/Core/CoreApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public function getHostObjects()
'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';
}
Expand Down
10 changes: 7 additions & 3 deletions library/Director/Core/LegacyDeploymentApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public function getActiveStageName()
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);

Expand Down Expand Up @@ -165,7 +169,7 @@ public function listPackageStages($packageName)
$this->assertDeploymentPath();

$dh = @opendir($this->deploymentPath);
if ($dh === null) {
if ($dh === false) {
throw new IcingaException('Can not list contents of %s', $this->deploymentPath);
}

Expand Down Expand Up @@ -279,7 +283,7 @@ protected function deployStage($stage, $files)
$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);
Expand Down Expand Up @@ -334,7 +338,7 @@ protected function activateStage($stage)
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);
}

Expand Down
14 changes: 6 additions & 8 deletions library/Director/Core/RestApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ public function delete($url, $body = null)
}

/**
* @return resource
* @throws RuntimeException
*/
protected function curl()
{
if ($this->curl === null) {
$this->curl = curl_init(sprintf('https://%s:%d', $this->peer, $this->port));
if (! $this->curl) {
throw new RuntimeException('CURL INIT ERROR: ' . curl_error($this->curl));
throw new RuntimeException('CURL INIT FAILED');
}
}

Expand Down Expand Up @@ -260,13 +260,11 @@ protected function processReadBuffer($offset, $pos)

public function disconnect()
{
if ($this->curl !== null) {
if (is_resource($this->curl)) {
@curl_close($this->curl);
sukhwinder33445 marked this conversation as resolved.
Show resolved Hide resolved
}

$this->curl = null;
if ($this->curl) {
@curl_close($this->curl);
}

$this->curl = null;
}

public function __destruct()
Expand Down
2 changes: 1 addition & 1 deletion library/Director/Core/RestApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function parseJsonResult($json)
throw new IcingaException('API request failed: ' . $result->status);
}
} else {
throw new IcingaException('API request failed: ' . var_export($result, 1));
throw new IcingaException('API request failed: ' . var_export($result, true));
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/Director/CustomVariable/CustomVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static function create($key, $value)
// TODO: check for specific class/stdClass/interface?
return new CustomVariableDictionary($key, $value);
} else {
throw new LogicException(sprintf('WTF (%s): %s', $key, var_export($value, 1)));
throw new LogicException(sprintf('WTF (%s): %s', $key, var_export($value, true)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/Director/CustomVariable/CustomVariableBoolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setValue($value)
if (! is_bool($value)) {
throw new ProgrammingError(
'Expected a boolean, got %s',
var_export($value, 1)
var_export($value, true)
);
}

Expand Down
2 changes: 1 addition & 1 deletion library/Director/CustomVariable/CustomVariableNull.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setValue($value)
if (! is_null($value)) {
throw new ProgrammingError(
'Null can only be null, got %s',
var_export($value, 1)
var_export($value, true)
);
}

Expand Down
2 changes: 1 addition & 1 deletion library/Director/CustomVariable/CustomVariableNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function setValue($value)
if (! is_int($value) && ! is_float($value)) {
throw new ProgrammingError(
'Expected a number, got %s',
var_export($value, 1)
var_export($value, true)
);
}

Expand Down
2 changes: 1 addition & 1 deletion library/Director/Daemon/BackgroundDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function initializeProcessDetails($systemd)
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);
Expand Down
2 changes: 1 addition & 1 deletion library/Director/Data/Db/DbDataFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function normalizeBoolean($value): ?string

throw new InvalidArgumentException(sprintf(
'Got invalid boolean: %s',
var_export($value, 1)
var_export($value, true)
));
}

Expand Down
2 changes: 1 addition & 1 deletion library/Director/Data/Db/DbObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ public function store(DbConnection $db = null)
$this->table,
$this->getLogId(),
$e->getMessage(),
var_export($this->getProperties(), 1) // TODO: Remove properties
var_export($this->getProperties(), true) // TODO: Remove properties
));
}

Expand Down
4 changes: 2 additions & 2 deletions library/Director/Data/PropertyMangler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function appendToArrayProperties(IcingaObject $object, $properties
throw new InvalidArgumentException(sprintf(
'I can only append to arrays, %s is %s',
$key,
var_export($current, 1)
var_export($current, true)
));
}

Expand Down Expand Up @@ -52,7 +52,7 @@ public static function removeProperties(IcingaObject $object, $properties)
throw new InvalidArgumentException(sprintf(
'I can only remove strings or from arrays, %s is %s',
$key,
var_export($current, 1)
var_export($current, true)
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/Director/Db/Branch/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function fromDbRow(stdClass $row)
$row->uuid = stream_get_contents($row->uuid);
}
if (strlen($row->uuid) !== 16) {
throw new RuntimeException('Valid UUID expected, got ' . var_export($row->uuid, 1));
throw new RuntimeException('Valid UUID expected, got ' . var_export($row->uuid, true));
}
$self->branchUuid = Uuid::fromBytes(Db\DbUtil::binaryResult($row->uuid));
$self->name = $row->branch_name;
Expand Down
2 changes: 1 addition & 1 deletion library/Director/Db/IcingaObjectFilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function wantId($id)
throw new InvalidArgumentException(sprintf(
'Numeric ID or IcingaObject expected, got %s',
// TODO: just type/class info?
var_export($id, 1)
var_export($id, true)
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/Director/Db/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getPendingMigrations()
public function applyPendingMigrations()
{
// Ensure we have enough time to migrate
ini_set('max_execution_time', 0);
ini_set('max_execution_time', '0');

foreach ($this->getPendingMigrations() as $migration) {
$migration->apply($this->connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function getJsonDump()
try {
JsonString::encode($object);
} catch (JsonEncodeException $singleError) {
$dump = var_export($object, 1);
$dump = var_export($object, true);
if (function_exists('iconv')) {
$dump = iconv('UTF-8', 'UTF-8//IGNORE', $dump);
}
Expand Down
4 changes: 2 additions & 2 deletions library/Director/DirectorObject/ObjectPurgeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function purge(array $keep, $class, $objectType = null)
// 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 = [];
Expand Down
4 changes: 2 additions & 2 deletions library/Director/IcingaConfig/IcingaConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ protected function generateFromDb()
$start = microtime(true);

MemoryLimit::raiseTo('1024M');
ini_set('max_execution_time', 0);
ini_set('max_execution_time', '0');
// Workaround for https://bugs.php.net/bug.php?id=68606 or similar
ini_set('zend.enable_gc', 0);
ini_set('zend.enable_gc', '0');

if (! $this->connection->isPgsql() && $this->db->quote("1\0") !== '\'1\\0\'') {
throw new RuntimeException(
Expand Down
Loading
Loading