summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/arrayutil.inc.php12
-rw-r--r--inc/crypto.inc.php2
-rw-r--r--inc/dashboard.inc.php2
-rw-r--r--inc/database.inc.php4
-rw-r--r--inc/dictionary.inc.php4
-rw-r--r--inc/download.inc.php2
-rw-r--r--inc/errorhandler.inc.php4
-rw-r--r--inc/event.inc.php2
-rw-r--r--inc/eventlog.inc.php2
-rw-r--r--inc/fileutil.inc.php2
-rw-r--r--inc/hook.inc.php4
-rw-r--r--inc/iputil.inc.php2
-rw-r--r--inc/mailer.inc.php2
-rw-r--r--inc/message.inc.php3
-rw-r--r--inc/module.inc.php2
-rw-r--r--inc/paginate.inc.php2
-rw-r--r--inc/permission.inc.php2
-rw-r--r--inc/property.inc.php2
-rw-r--r--inc/render.inc.php5
-rw-r--r--inc/request.inc.php2
-rw-r--r--inc/session.inc.php4
-rw-r--r--inc/taskmanager.inc.php2
-rw-r--r--inc/taskmanagercallback.inc.php2
-rw-r--r--inc/trigger.inc.php2
-rw-r--r--inc/user.inc.php2
-rw-r--r--inc/util.inc.php32
-rw-r--r--modules-available/dozmod/pages/runtimeconfig.inc.php16
-rw-r--r--modules-available/exams/baseconfig/getconfig.inc.php4
-rw-r--r--modules-available/exams/inc/exams.inc.php2
-rw-r--r--modules-available/locationinfo/inc/icalparser.inc.php5
-rw-r--r--modules-available/locationinfo/page.inc.php2
-rw-r--r--modules-available/locations/inc/locationutil.inc.php11
-rw-r--r--modules-available/minilinux/inc/minilinux.inc.php4
-rw-r--r--modules-available/roomplanner/page.inc.php18
-rw-r--r--modules-available/statistics/inc/statistics.inc.php4
-rw-r--r--modules-available/statistics/inc/statisticshooks.inc.php9
-rw-r--r--modules-available/statistics/pages/list.inc.php4
-rw-r--r--modules-available/statistics/pages/machine.inc.php8
-rw-r--r--modules-available/statistics/pages/summary.inc.php6
-rw-r--r--modules-available/sysconfig/addmodule_adauth.inc.php12
-rw-r--r--modules-available/sysconfig/inc/configmodule/branding.inc.php3
-rw-r--r--modules-available/sysconfig/inc/configmodule/customodule.inc.php3
-rw-r--r--modules-available/sysconfig/page.inc.php2
-rw-r--r--modules-available/systemstatus/page.inc.php6
-rw-r--r--modules-available/translation/page.inc.php10
45 files changed, 147 insertions, 88 deletions
diff --git a/inc/arrayutil.inc.php b/inc/arrayutil.inc.php
index 7aded4db..3d93d7d5 100644
--- a/inc/arrayutil.inc.php
+++ b/inc/arrayutil.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class ArrayUtil
{
@@ -68,4 +70,14 @@ class ArrayUtil
return true;
}
+ /**
+ * Force each element of given array to be of type $type.
+ */
+ public static function forceType(array &$array, string $type): void
+ {
+ foreach ($array as &$elem) {
+ settype($elem, $type);
+ }
+ }
+
} \ No newline at end of file
diff --git a/inc/crypto.inc.php b/inc/crypto.inc.php
index c82a5d82..acefcf67 100644
--- a/inc/crypto.inc.php
+++ b/inc/crypto.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Crypto
{
diff --git a/inc/dashboard.inc.php b/inc/dashboard.inc.php
index 716776d3..449fe7c0 100644
--- a/inc/dashboard.inc.php
+++ b/inc/dashboard.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Dashboard
{
diff --git a/inc/database.inc.php b/inc/database.inc.php
index 7805b508..83720baa 100644
--- a/inc/database.inc.php
+++ b/inc/database.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Handle communication with the database
* This is a very thin layer between you and PDO.
@@ -163,7 +165,7 @@ class Database
*/
public static function lastInsertId(): int
{
- return self::$dbh->lastInsertId();
+ return (int)self::$dbh->lastInsertId();
}
/**
diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php
index ee613d0b..3a2f9c2b 100644
--- a/inc/dictionary.inc.php
+++ b/inc/dictionary.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Dictionary
{
@@ -100,6 +102,8 @@ class Dictionary
if ($lang === null)
$lang = LANG;
$path = Util::safePath("modules/{$module}/lang/{$lang}/{$file}.json");
+ if ($path === null)
+ ErrorHandler::traceError("Invalid path");
if (isset(self::$stringCache[$path]))
return self::$stringCache[$path];
if (!file_exists($path))
diff --git a/inc/download.inc.php b/inc/download.inc.php
index 49ebbfbc..578992a6 100644
--- a/inc/download.inc.php
+++ b/inc/download.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Download
{
diff --git a/inc/errorhandler.inc.php b/inc/errorhandler.inc.php
index 8e49353c..ce969966 100644
--- a/inc/errorhandler.inc.php
+++ b/inc/errorhandler.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
use JetBrains\PhpStorm\NoReturn;
class ErrorHandler
@@ -146,6 +148,6 @@ SADFACE;
}
$arg = 'Array(' . count($arg) . ')';
}
- return $arg;
+ return (string)$arg;
}
} \ No newline at end of file
diff --git a/inc/event.inc.php b/inc/event.inc.php
index db5bf1f1..4d02b580 100644
--- a/inc/event.inc.php
+++ b/inc/event.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Class with static functions that are called when a specific event
* took place, like the server has been booted, or the interface address
diff --git a/inc/eventlog.inc.php b/inc/eventlog.inc.php
index 93ca5c5c..99585abd 100644
--- a/inc/eventlog.inc.php
+++ b/inc/eventlog.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Class to add entries to the event log. Technically this class belongs to the
* eventlog module, but since it is used in so many places, this helper resides
diff --git a/inc/fileutil.inc.php b/inc/fileutil.inc.php
index 86a5ebc5..e986b2de 100644
--- a/inc/fileutil.inc.php
+++ b/inc/fileutil.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class FileUtil
{
diff --git a/inc/hook.inc.php b/inc/hook.inc.php
index abeac68e..f7ca617d 100644
--- a/inc/hook.inc.php
+++ b/inc/hook.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Generic helper for getting and executing hooks.
*/
@@ -73,7 +75,7 @@ class Hook
try {
return (include $this->file);
} catch (Exception $e) {
- error_log($e);
+ error_log($e->getMessage());
return false;
}
}
diff --git a/inc/iputil.inc.php b/inc/iputil.inc.php
index ecd8c198..caac7349 100644
--- a/inc/iputil.inc.php
+++ b/inc/iputil.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class IpUtil
{
diff --git a/inc/mailer.inc.php b/inc/mailer.inc.php
index b2fb7741..bfdcd320 100644
--- a/inc/mailer.inc.php
+++ b/inc/mailer.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Mailer
{
diff --git a/inc/message.inc.php b/inc/message.inc.php
index 482e4ba4..a26369f5 100644
--- a/inc/message.inc.php
+++ b/inc/message.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Message
{
private static $list = array();
@@ -62,6 +64,7 @@ class Message
default:
$icon = '';
}
+ ArrayUtil::forceType($params, 'string');
self::$list[] = array(
'type' => $type,
'icon' => $icon,
diff --git a/inc/module.inc.php b/inc/module.inc.php
index 115c9e9a..b072c4a2 100644
--- a/inc/module.inc.php
+++ b/inc/module.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Module
{
/*
diff --git a/inc/paginate.inc.php b/inc/paginate.inc.php
index b9a1ed78..7757228a 100644
--- a/inc/paginate.inc.php
+++ b/inc/paginate.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Paginate
{
private $query;
diff --git a/inc/permission.inc.php b/inc/permission.inc.php
index 798f9350..f346f1da 100644
--- a/inc/permission.inc.php
+++ b/inc/permission.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
class Permission
{
private static $permissions = array(
diff --git a/inc/property.inc.php b/inc/property.inc.php
index 5efcfe3a..dc1e4719 100644
--- a/inc/property.inc.php
+++ b/inc/property.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Get or set simple key-value-pairs, backed by the database
* to make them persistent.
diff --git a/inc/render.inc.php b/inc/render.inc.php
index 68a0cd19..a636382e 100644
--- a/inc/render.inc.php
+++ b/inc/render.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
require_once('inc/util.inc.php');
require_once('Mustache/Autoloader.php');
@@ -187,7 +189,8 @@ class Render
* Parse template with given params and return; do not add to body
* @param string $template name of template, relative to templates/, without .html extension
* @param array $params tags to render into template
- * @param string $module name of module to load template from; defaults to currently active module
+ * @param ?string $module name of module to load template from; defaults to currently active module
+ * @param ?string $lang override language if not null
* @return string Rendered template
*/
public static function parse(string $template, array $params = [], ?string $module = null, ?string $lang = null): string
diff --git a/inc/request.inc.php b/inc/request.inc.php
index c499a9d9..cd782d99 100644
--- a/inc/request.inc.php
+++ b/inc/request.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Wrapper for getting fields from the request (GET, POST, ...)
*/
diff --git a/inc/session.inc.php b/inc/session.inc.php
index 622eb320..ccb878cd 100644
--- a/inc/session.inc.php
+++ b/inc/session.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
require_once('config.php');
class Session
@@ -141,7 +143,7 @@ class Session
}
// Refresh cookie if appropriate
self::setupSessionAccounting(Request::isGet() && $row['dateline'] + 86400 < $now + CONFIG_SESSION_TIMEOUT);
- self::$userId = $row['userid'];
+ self::$userId = (int)$row['userid'];
self::$data = @json_decode($row['data'], true);
if (!is_array(self::$data)) {
self::$data = [];
diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php
index 6c9d63c2..d9396901 100644
--- a/inc/taskmanager.inc.php
+++ b/inc/taskmanager.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Interface to the external task manager.
*/
diff --git a/inc/taskmanagercallback.inc.php b/inc/taskmanagercallback.inc.php
index 321475ac..01301be4 100644
--- a/inc/taskmanagercallback.inc.php
+++ b/inc/taskmanagercallback.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Contains all callbacks for detached taskmanager tasks.
*/
diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php
index 4776855c..d0d5d365 100644
--- a/inc/trigger.inc.php
+++ b/inc/trigger.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* This is one giant class containing various functions that will generate
* required config files, daemon instances and more, mostly through the Taskmanager.
diff --git a/inc/user.inc.php b/inc/user.inc.php
index 4d278e1b..01b4d210 100644
--- a/inc/user.inc.php
+++ b/inc/user.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
use JetBrains\PhpStorm\NoReturn;
require_once('inc/session.inc.php');
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 0c402a6a..a5ccdc77 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
use JetBrains\PhpStorm\NoReturn;
class Util
@@ -98,7 +100,7 @@ class Util
* @param int $shift how many units to skip, i.e. if you pass in KiB or MiB
* @return string human-readable string representing the given file size
*/
- public static function readableFileSize(float $bytes, int $decimals = -1, int $shift = 0): string
+ public static function readableFileSize($bytes, int $decimals = -1, int $shift = 0): string
{
// round doesn't reliably work for large floats, pick workaround depending on OS
if (PHP_INT_SIZE === 4) {
@@ -113,10 +115,10 @@ class Util
} else {
$bytes /= 1024 ** $factor;
if ($decimals === -1) {
- $decimals = 2 - floor(strlen((int)$bytes) - 1);
+ $decimals = 2 - strlen((string)floor($bytes)) - 1;
}
}
- return Dictionary::number($bytes, $decimals) . "\xe2\x80\x89" . ($sz[$factor + $shift] ?? '#>PiB#');
+ return Dictionary::number((float)$bytes, $decimals) . "\xe2\x80\x89" . ($sz[$factor + $shift] ?? '#>PiB#');
}
public static function sanitizeFilename(string $name): string
@@ -131,25 +133,24 @@ class Util
*
* @param string $path path to check for safety
* @param string $prefix required prefix of $path
- * @return false|string
*/
- public static function safePath(string $path, string $prefix = ''): string
+ public static function safePath(string $path, string $prefix = ''): ?string
{
if (empty($path))
- return false;
+ return null;
$path = trim($path);
if ($path[0] == '/' || preg_match('/[\x00-\x19?*]/', $path))
- return false;
+ return null;
if (strpos($path, '..') !== false)
- return false;
+ return null;
if (substr($path, 0, 2) !== './')
$path = "./$path";
- if (empty($prefix))
- return $path;
- if (substr($prefix, 0, 2) !== './')
- $prefix = "./$prefix";
- if (substr($path, 0, strlen($prefix)) !== $prefix)
- return false;
+ if (!empty($prefix)) {
+ if (substr($prefix, 0, 2) !== './')
+ $prefix = "./$prefix";
+ if (substr($path, 0, strlen($prefix)) !== $prefix)
+ return null;
+ }
return $path;
}
@@ -381,7 +382,6 @@ class Util
*/
public static function formatDuration(int $seconds, bool $showSecs = true): string
{
- settype($seconds, 'int');
static $UNITS = ['y' => 31536000, 'mon' => 2592000, 'd' => 86400];
$parts = [];
$prev = false;
@@ -397,7 +397,7 @@ class Util
$prev = true;
}
}
- $parts[] = gmdate($showSecs ? 'H:i:s' : 'H:i', $seconds);
+ $parts[] = gmdate($showSecs ? 'H:i:s' : 'H:i', (int)$seconds);
return implode(' ', $parts);
}
diff --git a/modules-available/dozmod/pages/runtimeconfig.inc.php b/modules-available/dozmod/pages/runtimeconfig.inc.php
index 5f441980..f5790e82 100644
--- a/modules-available/dozmod/pages/runtimeconfig.inc.php
+++ b/modules-available/dozmod/pages/runtimeconfig.inc.php
@@ -85,29 +85,29 @@ class SubPage
$runtimeConf = json_decode($runtimeConf['value'], true);
/* convert some value to corresponding "selected" texts */
- if ($runtimeConf['defaultLecturePermissions']['edit']) {
+ if ($runtimeConf['defaultLecturePermissions']['edit'] ?? false) {
$runtimeConf['defaultLecturePermissions']['edit'] = 'checked';
}
- if ($runtimeConf['defaultLecturePermissions']['admin']) {
+ if ($runtimeConf['defaultLecturePermissions']['admin'] ?? false) {
$runtimeConf['defaultLecturePermissions']['admin'] = 'checked';
}
- if ($runtimeConf['defaultImagePermissions']['edit']) {
+ if ($runtimeConf['defaultImagePermissions']['edit'] ?? false) {
$runtimeConf['defaultImagePermissions']['edit'] = 'checked';
}
- if ($runtimeConf['defaultImagePermissions']['admin']) {
+ if ($runtimeConf['defaultImagePermissions']['admin'] ?? false) {
$runtimeConf['defaultImagePermissions']['admin'] = 'checked';
}
- if ($runtimeConf['defaultImagePermissions']['link']) {
+ if ($runtimeConf['defaultImagePermissions']['link'] ?? false) {
$runtimeConf['defaultImagePermissions']['link'] = 'checked';
}
- if ($runtimeConf['defaultImagePermissions']['download']) {
+ if ($runtimeConf['defaultImagePermissions']['download'] ?? false) {
$runtimeConf['defaultImagePermissions']['download'] = 'checked';
}
- if ($runtimeConf['allowLoginByDefault']) {
+ if ($runtimeConf['allowLoginByDefault'] ?? false) {
$runtimeConf['allowLoginByDefault'] = 'checked';
}
- if ($runtimeConf['allowStudentDownload']) {
+ if ($runtimeConf['allowStudentDownload'] ?? false) {
$runtimeConf['allowStudentDownload'] = 'checked';
}
if (isset($runtimeConf['serverSideCopy'])) {
diff --git a/modules-available/exams/baseconfig/getconfig.inc.php b/modules-available/exams/baseconfig/getconfig.inc.php
index 748149ad..7e4a70df 100644
--- a/modules-available/exams/baseconfig/getconfig.inc.php
+++ b/modules-available/exams/baseconfig/getconfig.inc.php
@@ -18,10 +18,10 @@ if ($uuid !== null) {
}
if (Exams::isInExamMode($locationIds, $lectureId, $autoLogin)) {
ConfigHolder::add('SLX_EXAM', 'yes', 10000);
- if (strlen($lectureId) > 0) {
+ if (!empty($lectureId)) {
ConfigHolder::add('SLX_EXAM_START', $lectureId, 10000);
}
- if (strlen($autoLogin) > 0) {
+ if (!empty($autoLogin)) {
ConfigHolder::add('SLX_AUTOLOGIN', $autoLogin, 10000);
}
ConfigHolder::add('SLX_SYSTEMD_TARGET', 'exam-mode', 10000);
diff --git a/modules-available/exams/inc/exams.inc.php b/modules-available/exams/inc/exams.inc.php
index 86dc6d89..2a54c262 100644
--- a/modules-available/exams/inc/exams.inc.php
+++ b/modules-available/exams/inc/exams.inc.php
@@ -7,7 +7,7 @@ class Exams
* @param int[] $locationIds of location ids. must be an associative array.
* @return bool true iff for any of the given location ids an exam is scheduled.
**/
- public static function isInExamMode(array $locationIds, &$lectureId = false, &$autoLogin = false): bool
+ public static function isInExamMode(array $locationIds, ?string &$lectureId = null, ?string &$autoLogin = null): bool
{
if (empty($locationIds)) {
$locationIds[] = 0;
diff --git a/modules-available/locationinfo/inc/icalparser.inc.php b/modules-available/locationinfo/inc/icalparser.inc.php
index c6d94a12..eacb67b1 100644
--- a/modules-available/locationinfo/inc/icalparser.inc.php
+++ b/modules-available/locationinfo/inc/icalparser.inc.php
@@ -1903,12 +1903,9 @@ class ICalParser
/**
* Parses a duration and applies it to a date
*
- * @param string $date
- * @param DateInterval $duration
- * @param string $format
* @return integer|DateTime
*/
- protected function parseDuration(string $date, DateInterval $duration, string $format = self::UNIX_FORMAT)
+ protected function parseDuration(string $date, DateInterval $duration, ?string $format = self::UNIX_FORMAT)
{
$dateTime = date_create($date);
$dateTime->modify("{$duration->y} year");
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index ecc47f2e..63a02ba2 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -1084,7 +1084,7 @@ class Page_LocationInfo extends Page
'language' => $config['language'],
);
- die(Render::parse('frontend-summary', $data, $module = null, $config['language']));
+ die(Render::parse('frontend-summary', $data, null, $config['language']));
}
http_response_code(500);
diff --git a/modules-available/locations/inc/locationutil.inc.php b/modules-available/locations/inc/locationutil.inc.php
index 17608203..91117445 100644
--- a/modules-available/locations/inc/locationutil.inc.php
+++ b/modules-available/locations/inc/locationutil.inc.php
@@ -169,7 +169,7 @@ class LocationUtil
return ($net1['startaddr'] <= $net2['endaddr'] && $net1['endaddr'] >= $net2['startaddr']);
}
- public static function rangeToLongVerbose(int $start, int $end): ?array
+ public static function rangeToLongVerbose(string $start, string $end): ?array
{
$result = self::rangeToLong($start, $end);
list($startLong, $endLong) = $result;
@@ -188,16 +188,11 @@ class LocationUtil
return $result;
}
- public static function rangeToLong(int $start, int $end): array
+ /** @return array{0: int, 1: int} */
+ public static function rangeToLong(string $start, string $end): array
{
$startLong = ip2long($start);
$endLong = ip2long($end);
- if ($startLong !== false) {
- $startLong = sprintf("%u", $startLong);
- }
- if ($endLong !== false) {
- $endLong = sprintf("%u", $endLong);
- }
return array($startLong, $endLong);
}
diff --git a/modules-available/minilinux/inc/minilinux.inc.php b/modules-available/minilinux/inc/minilinux.inc.php
index 9c1b9011..88c50995 100644
--- a/modules-available/minilinux/inc/minilinux.inc.php
+++ b/modules-available/minilinux/inc/minilinux.inc.php
@@ -355,11 +355,11 @@ class MiniLinux
self::setInstalledState($versionid, $task['statusCode'] === 'TASK_FINISHED');
}
- public static function setInstalledState($versionid, int $installed)
+ public static function setInstalledState($versionid, bool $installed): void
{
Database::exec('UPDATE minilinux_version SET installed = :installed WHERE versionid = :versionid', [
'versionid' => $versionid,
- 'installed' => $installed,
+ 'installed' => (int)$installed,
]);
if ($installed) {
$res = Database::queryFirst('SELECT Count(*) AS cnt FROM minilinux_version WHERE installed <> 0');
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index 53e8bf0b..6708cd8a 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -4,14 +4,14 @@ class Page_Roomplanner extends Page
{
/**
- * @var int locationid of location we're editing
+ * @var ?int locationid of location we're editing, or null if unknown/not set
*/
- private $locationid = false;
+ private $locationid = null;
/**
* @var array location data from location table
*/
- private $location = false;
+ private $location = null;
/**
* @var string action to perform
@@ -25,8 +25,8 @@ class Page_Roomplanner extends Page
private function loadRequestedLocation()
{
- $this->locationid = Request::get('locationid', false, 'integer');
- if ($this->locationid !== false) {
+ $this->locationid = Request::get('locationid', null, 'integer');
+ if ($this->locationid !== null) {
$locs = Location::getLocationsAssoc();
if (isset($locs[$this->locationid])) {
$this->location = $locs[$this->locationid];
@@ -46,11 +46,11 @@ class Page_Roomplanner extends Page
$this->action = Request::any('action', 'show', 'string');
$this->loadRequestedLocation();
- if ($this->locationid === false) {
+ if ($this->locationid === null) {
Message::addError('need-locationid');
Util::redirect('?do=locations');
}
- if ($this->location === false) {
+ if ($this->location === null) {
Message::addError('locations.invalid-location-id', $this->locationid);
Util::redirect('?do=locations');
}
@@ -204,10 +204,10 @@ class Page_Roomplanner extends Page
} elseif ($this->action === 'save') {
// Save roomplan - give feedback if it failed so the window can stay open
$this->loadRequestedLocation();
- if ($this->locationid === false) {
+ if ($this->locationid === null) {
die('Missing locationid in save data');
}
- if ($this->location === false) {
+ if ($this->location === null) {
die('Location with id ' . $this->locationid . ' does not exist.');
}
$this->handleSaveRequest(true);
diff --git a/modules-available/statistics/inc/statistics.inc.php b/modules-available/statistics/inc/statistics.inc.php
index 2a9ca3c9..c12f5be4 100644
--- a/modules-available/statistics/inc/statistics.inc.php
+++ b/modules-available/statistics/inc/statistics.inc.php
@@ -46,11 +46,11 @@ class Statistics
* @param string $sort something like 'lastseen ASC' - not sanitized, don't pass user input!
* @return Machine[] list of matches
*/
- public static function getMachinesByIp(string $ip, int $returnData, bool $sort = false): array
+ public static function getMachinesByIp(string $ip, int $returnData, string $sort = null): array
{
$fields = self::initFields($returnData);
- if ($sort === false) {
+ if ($sort === null) {
$sort = '';
} else {
$sort = "ORDER BY $sort";
diff --git a/modules-available/statistics/inc/statisticshooks.inc.php b/modules-available/statistics/inc/statisticshooks.inc.php
index b17cf4a9..405ed5f7 100644
--- a/modules-available/statistics/inc/statisticshooks.inc.php
+++ b/modules-available/statistics/inc/statisticshooks.inc.php
@@ -13,7 +13,11 @@ class StatisticsHooks
['machineuuid' => $machineuuid]);
}
- public static function getBaseconfigName(string $machineuuid): string
+ /**
+ * Hook for baseconfig.
+ * @return false|string Client name, or false if invalid
+ */
+ public static function getBaseconfigName(string $machineuuid)
{
self::getRow($machineuuid);
if (self::$row === false)
@@ -21,6 +25,9 @@ class StatisticsHooks
return self::$row['hostname'] ?: self::$row['clientip'];
}
+ /**
+ * Hook for baseconfig.
+ */
public static function baseconfigLocationResolver(string $machineuuid): int
{
self::getRow($machineuuid);
diff --git a/modules-available/statistics/pages/list.inc.php b/modules-available/statistics/pages/list.inc.php
index b318cc68..facffdd0 100644
--- a/modules-available/statistics/pages/list.inc.php
+++ b/modules-available/statistics/pages/list.inc.php
@@ -89,9 +89,9 @@ class SubPage
$row['subnet'] = "$octets[0].$octets[1].$octets[2]";
$row['lastoctet'] = $octets[3];
}
- $row['ramclass'] = StatisticsStyling::ramColorClass($row['mbram']);
+ $row['ramclass'] = StatisticsStyling::ramColorClass((int)$row['mbram']);
$row['kvmclass'] = StatisticsStyling::kvmColorClass($row['kvmstate']);
- $row['hddclass'] = StatisticsStyling::hddColorClass($row['gbtmp']);
+ $row['hddclass'] = StatisticsStyling::hddColorClass((int)$row['gbtmp']);
if (empty($row['hostname'])) {
$row['hostname'] = $row['clientip'];
}
diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php
index 24bf7c1e..fe82797d 100644
--- a/modules-available/statistics/pages/machine.inc.php
+++ b/modules-available/statistics/pages/machine.inc.php
@@ -219,9 +219,9 @@ class SubPage
$client['live_cpuidle'] = 100 - $client['live_cpuload'];
}
$client['live_cputemppercent'] = max(0, min(100, 110 - $client['live_cputemp']));
- $client['ramclass'] = StatisticsStyling::ramColorClass($client['mbram']);
+ $client['ramclass'] = StatisticsStyling::ramColorClass((int)$client['mbram']);
$client['kvmclass'] = StatisticsStyling::kvmColorClass($client['kvmstate']);
- $client['hddclass'] = StatisticsStyling::hddColorClass($client['gbtmp']);
+ $client['hddclass'] = StatisticsStyling::hddColorClass((int)$client['gbtmp']);
// Format HDD data to strings
foreach ($hdds['hdds'] as &$hdd) {
$hdd['smart_status_failed'] = !($client['smart_status//passed'] ?? 1);
@@ -405,8 +405,8 @@ class SubPage
}
if (count($spans['rows']) > 10) {
$spans['hasrows2'] = true;
- $spans['rows2'] = array_slice($spans['rows'], ceil(count($spans['rows']) / 2));
- $spans['rows'] = array_slice($spans['rows'], 0, ceil(count($spans['rows']) / 2));
+ $spans['rows2'] = array_slice($spans['rows'], (int)ceil(count($spans['rows']) / 2));
+ $spans['rows'] = array_slice($spans['rows'], 0, (int)ceil(count($spans['rows']) / 2));
}
$spans['isclient'] = $client['isclient'];
Render::addTemplate('machine-usage', $spans);
diff --git a/modules-available/statistics/pages/summary.inc.php b/modules-available/statistics/pages/summary.inc.php
index d0538b38..e9c25456 100644
--- a/modules-available/statistics/pages/summary.inc.php
+++ b/modules-available/statistics/pages/summary.inc.php
@@ -129,7 +129,7 @@ class SubPage
['data' => $points1, 'label' => 'Online', 'borderColor' => '#8f3'],
['data' => $points2, 'label' => 'In use', 'borderColor' => '#e76'],
]]);
- $data['markings'] = json_encode($lectures, true);
+ $data['markings'] = json_encode($lectures);
}
if (Module::get('runmode') !== false) {
$res = Database::queryFirst('SELECT Count(*) AS cnt FROM machine m INNER JOIN runmode r USING (machineuuid)'
@@ -287,9 +287,9 @@ class SubPage
$row['firstseen'] = Util::prettyTime($row['firstseen']);
$row['gbram'] = round(round($row['mbram'] / 500) / 2, 1); // Trial and error until we got "expected" rounding..
$row['gbtmp'] = round($row['id44mb'] / 1024);
- $row['ramclass'] = StatisticsStyling::ramColorClass($row['mbram']);
+ $row['ramclass'] = StatisticsStyling::ramColorClass((int)$row['mbram']);
$row['kvmclass'] = StatisticsStyling::kvmColorClass($row['kvmstate']);
- $row['hddclass'] = StatisticsStyling::hddColorClass($row['gbtmp']);
+ $row['hddclass'] = StatisticsStyling::hddColorClass((int)$row['gbtmp']);
$row['kvmicon'] = $row['kvmstate'] === 'ENABLED' ? '✓' : '✗';
if (++$count > 5) {
$row['collapse'] = 'collapse';
diff --git a/modules-available/sysconfig/addmodule_adauth.inc.php b/modules-available/sysconfig/addmodule_adauth.inc.php
index 2a695ab0..42187171 100644
--- a/modules-available/sysconfig/addmodule_adauth.inc.php
+++ b/modules-available/sysconfig/addmodule_adauth.inc.php
@@ -130,7 +130,7 @@ class AdAuth_SelfSearch extends AddModule_Base
protected function preprocessInternal()
{
- $server = $binddn = $port = null;
+ $server = $binddn = null;
$searchbase = Request::post('searchbase', '');
$bindpw = Request::post('bindpw');
$ssl = Request::post('ssl', 'off') === 'on';
@@ -139,14 +139,8 @@ class AdAuth_SelfSearch extends AddModule_Base
AddModule_Base::setStep('AdAuth_Start'); // Continues with AdAuth_Start for render()
return;
}
- foreach (['server', 'binddn', 'port'] as $var) {
- $$var = Request::post($var, null);
- if (empty($$var)) {
- Message::addError('main.parameter-empty', $var);
- AddModule_Base::setStep('AdAuth_Start'); // Continues with AdAuth_Start for render()
- return;
- }
- }
+ $server = Request::post('server', Request::REQUIRED, 'string');
+ $binddn = Request::post('binddn', Request::REQUIRED, 'string');
$this->originalBindDn = '';
// Fix bindDN if short name given
//
diff --git a/modules-available/sysconfig/inc/configmodule/branding.inc.php b/modules-available/sysconfig/inc/configmodule/branding.inc.php
index 84f79b44..7013e3ae 100644
--- a/modules-available/sysconfig/inc/configmodule/branding.inc.php
+++ b/modules-available/sysconfig/inc/configmodule/branding.inc.php
@@ -14,7 +14,8 @@ class ConfigModule_Branding extends ConfigModule
const MODID = 'Branding';
const VERSION = 1;
-
+
+ /** @var false|string */
private $tmpFile = false;
protected function generateInternal(string $tgz, ?string $parent)
diff --git a/modules-available/sysconfig/inc/configmodule/customodule.inc.php b/modules-available/sysconfig/inc/configmodule/customodule.inc.php
index b5c10104..0b8e38d2 100644
--- a/modules-available/sysconfig/inc/configmodule/customodule.inc.php
+++ b/modules-available/sysconfig/inc/configmodule/customodule.inc.php
@@ -13,7 +13,8 @@ class ConfigModule_CustomModule extends ConfigModule
{
const MODID = 'CustomModule';
const VERSION = 2;
-
+
+ /** @var false|string */
private $tmpFile = false;
protected function generateInternal(string $tgz, ?string $parent)
diff --git a/modules-available/sysconfig/page.inc.php b/modules-available/sysconfig/page.inc.php
index 41c4a2db..b11f399e 100644
--- a/modules-available/sysconfig/page.inc.php
+++ b/modules-available/sysconfig/page.inc.php
@@ -406,7 +406,7 @@ class Page_SysConfig extends Page
Message::addError('config-invalid', $moduleid);
Util::redirect('?do=sysconfig');
}
- $ret = $module->generate(false, 250);
+ $ret = $module->generate(false, null, 500);
if ($ret === true)
Message::addSuccess('module-rebuilt', $module->title());
elseif ($ret === false)
diff --git a/modules-available/systemstatus/page.inc.php b/modules-available/systemstatus/page.inc.php
index dbad2871..92cea5ab 100644
--- a/modules-available/systemstatus/page.inc.php
+++ b/modules-available/systemstatus/page.inc.php
@@ -520,9 +520,9 @@ class Page_SystemStatus extends Page
$g = (100 - $usedPercent) * (60 / 30);
$b = 0;
}
- $r = dechex(round($r * 2.55));
- $g = dechex(round($g * 2.55));
- $b = dechex(round($b * 2.55));
+ $r = dechex((int)round($r * 2.55));
+ $g = dechex((int)round($g * 2.55));
+ $b = dechex((int)round($b * 2.55));
return sprintf("%02s%02s%02s", $r, $g, $b);
}
diff --git a/modules-available/translation/page.inc.php b/modules-available/translation/page.inc.php
index 578e27dc..4563b8e5 100644
--- a/modules-available/translation/page.inc.php
+++ b/modules-available/translation/page.inc.php
@@ -429,7 +429,7 @@ class Page_Translation extends Page
*/
private function loadUsedTemplateTags(Module $module = null): array
{
- if ($module === false) {
+ if ($module === null) {
$module = $this->module;
}
$tags = array();
@@ -459,7 +459,7 @@ class Page_Translation extends Page
*/
private function loadUsedMessageTags(Module $module = null): array
{
- if ($module === false) {
+ if ($module === null) {
$module = $this->module;
}
$allFiles = $this->getAllFiles('modules', '.php');
@@ -491,7 +491,7 @@ class Page_Translation extends Page
*/
private function loadUsedModuleTags(Module $module = null): array
{
- if ($module === false) {
+ if ($module === null) {
$module = $this->module;
}
$tags = $this->loadTagsFromPhp('/Dictionary\s*::\s*translate\s*\(\s*[\'"](?<tag>[^\'"\.]*)[\'"]\s*[\),]/i',
@@ -519,7 +519,7 @@ class Page_Translation extends Page
$want = array();
foreach (Module::getAll() as $module) {
$cat = $module->getCategory();
- if (substr($cat, 0, $skip) === $match) {
+ if ($cat !== null && substr($cat, 0, $skip) === $match) {
$want[substr($cat, $skip)] = true;
}
}
@@ -585,7 +585,7 @@ class Page_Translation extends Page
*/
private function getModuleTranslationStatus(string $lang, string $file, bool $fallback, array $tags, Module $module = null): array
{
- if ($module === false) {
+ if ($module === null) {
$module = $this->module;
}
if ($fallback) {