From 4abedb1388b2d7a09d50532688d3003d4c32a3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org> Date: Mon, 2 Nov 2020 16:54:26 +0100 Subject: [PATCH] ambulance: fix(core) Fix PHPStan spotted issues issue #6114 --- include/class_objects.inc | 5 ++++- include/class_tests.inc | 22 +++++++++---------- .../management/class_EntrySortIterator.inc | 8 ++----- .../attributes/class_SetAttribute.inc | 4 ++-- setup/class_setupStepChecks.inc | 8 ------- setup/class_setupStepMigrate.inc | 4 ++-- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/include/class_objects.inc b/include/class_objects.inc index 988be1300..fc82e2627 100644 --- a/include/class_objects.inc +++ b/include/class_objects.inc @@ -348,7 +348,10 @@ class objects return $tabObject; } - static function link (string $dn, string $type, string $subaction = '', string $text = NULL, bool $icon = TRUE, bool $link = TRUE): string + /** + * @param string|array|null $text + */ + static function link (string $dn, string $type, string $subaction = '', $text = NULL, bool $icon = TRUE, bool $link = TRUE): string { global $config; diff --git a/include/class_tests.inc b/include/class_tests.inc index 60d8d3ff4..a62659773 100644 --- a/include/class_tests.inc +++ b/include/class_tests.inc @@ -310,10 +310,10 @@ class tests if (!tests::is_ipv4($ip1) || !tests::is_ipv4($ip2)) { return FALSE; } else { - $ar1 = explode(".", $ip1); + $ar1 = array_map('intval', explode('.', $ip1)); $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3]; - $ar2 = explode(".", $ip2); + $ar2 = array_map('intval', explode('.', $ip2)); $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3]; return ($var1 < $var2); } @@ -325,15 +325,15 @@ class tests * * \param string $network Name of the network * - * \param string $netmask The netmask of the IP address + * \param string $netmask The netmask of the IPv4 address * - * \param string $address The IP address + * \param string $address The IPv4 address */ public static function is_in_network ($network, $netmask, $address) { - $nw = explode('.', $network); - $nm = explode('.', $netmask); - $ad = explode('.', $address); + $nw = array_map('intval', explode('.', $network)); + $nm = array_map('intval', explode('.', $netmask)); + $ad = array_map('intval', explode('.', $address)); /* Generate inverted netmask */ $ni = []; @@ -351,12 +351,12 @@ class tests return ($first < $curr && $last > $curr); } - /* \brief Check if the specified IP address $address is inside the given network */ + /* \brief Check if the specified IPv4 address $address is inside the given network */ public static function is_in_ip_range ($from, $to, $address) { - $from = explode('.', $from); - $to = explode('.', $to); - $ad = explode('.', $address); + $from = array_map('intval', explode('.', $from)); + $to = array_map('intval', explode('.', $to)); + $ad = array_map('intval', explode('.', $address)); /* Transform to integer */ $from = $from[0] * (16777216) + $from[1] * (65536) + $from[2] * (256) + $from[3]; diff --git a/include/management/class_EntrySortIterator.inc b/include/management/class_EntrySortIterator.inc index 1420ed09f..158bc96e8 100644 --- a/include/management/class_EntrySortIterator.inc +++ b/include/management/class_EntrySortIterator.inc @@ -59,12 +59,10 @@ class EntrySortIterator implements Iterator /*! * \brief Put the array pointer to the first element - * - * \return the first element of the array */ function rewind () { - return reset($this->data); + reset($this->data); } /*! @@ -89,12 +87,10 @@ class EntrySortIterator implements Iterator /*! * \brief Get the next data element - * - * \return The next element pointed by array pointer */ function next () { - return next($this->data); + next($this->data); } /*! diff --git a/include/simpleplugin/attributes/class_SetAttribute.inc b/include/simpleplugin/attributes/class_SetAttribute.inc index 268f3a5aa..dadfc1799 100644 --- a/include/simpleplugin/attributes/class_SetAttribute.inc +++ b/include/simpleplugin/attributes/class_SetAttribute.inc @@ -634,7 +634,7 @@ class OrderedArrayAttribute extends SetAttribute if ($this->order) { if (preg_match('/^'.$id.'_up_/', $postValue)) { $key = preg_replace('/^'.$id.'_up_/', '', $postValue); - $key = preg_replace('/_[xy]$/', '', $key); + $key = (int)preg_replace('/_[xy]$/', '', $key); $tmp = $this->postValue[$key]; $this->postValue[$key] = $this->postValue[$key - 1]; @@ -643,7 +643,7 @@ class OrderedArrayAttribute extends SetAttribute } if (preg_match('/^'.$id.'_down_/', $postValue)) { $key = preg_replace('/^'.$id.'_down_/', '', $postValue); - $key = preg_replace('/_[xy]$/', '', $key); + $key = (int)preg_replace('/_[xy]$/', '', $key); $tmp = $this->postValue[$key]; $this->postValue[$key] = $this->postValue[$key + 1]; diff --git a/setup/class_setupStepChecks.inc b/setup/class_setupStepChecks.inc index 14a7f534b..616f25637 100644 --- a/setup/class_setupStepChecks.inc +++ b/setup/class_setupStepChecks.inc @@ -112,14 +112,6 @@ class setupStepChecks extends setupStep $M = TRUE; $basic_checks[] = ["NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M ]; - /* Check for installed mhash module */ - $N = msgPool::checkingFor("hash method"); - $D = _("FusionDirectory requires either 'mhash' or the 'sha1' module to make use of SSHA encryption."); - $S = msgPool::installPhpModule("mhash/sha1"); - $R = is_callable('mhash') || is_callable('sha1'); - $M = FALSE; - $basic_checks[] = ["NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M ]; - /* Check if imap module is available */ $N = msgPool::checkingFor("IMAP"); $D = _("FusionDirectory requires this module to talk to an IMAP server."); diff --git a/setup/class_setupStepMigrate.inc b/setup/class_setupStepMigrate.inc index 8ce431bdf..0fd4830b6 100644 --- a/setup/class_setupStepMigrate.inc +++ b/setup/class_setupStepMigrate.inc @@ -892,8 +892,8 @@ class setupStepMigrate extends setupStep /* Creating user */ $tabObject = objects::create('user'); - $tabObject->givenName = 'System'; - $tabObject->sn = 'Administrator'; + $tabObject->getBaseObject()->givenName = 'System'; + $tabObject->getBaseObject()->sn = 'Administrator'; $tabObject->update(); $errors = $tabObject->save(); if (!empty($errors)) { -- GitLab