From d0cdf7fa94ec8ffac88a7c8e077bac6ced7e5468 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 15 Jul 2025 17:54:48 +0200 Subject: [PATCH] refactoring --- lam/lib/html.inc | 7 +++---- lam/lib/modules.inc | 6 +++--- lam/lib/security.inc | 2 +- lam/lib/selfService.inc | 2 +- lam/templates/tests/schemaTest.php | 11 ++++++----- lam/templates/tools/importexport.php | 9 ++++++--- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lam/lib/html.inc b/lam/lib/html.inc index f1820416b..a6626b7a0 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -3338,12 +3338,11 @@ class htmlDiv extends htmlElement { /** * Constructor. * - * @param String $id unique ID + * @param string|null $id unique ID * @param htmlElement $content inner content - * @param array $classes CSS classes - * @param string[] $cssClasses CSS classes + * @param string[]|null $cssClasses CSS classes */ - function __construct($id, $content, $cssClasses = null) { + function __construct(?string $id, htmlElement $content, ?array $cssClasses = null) { if ($id !== null) { $this->id = htmlspecialchars($id); } diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 7a53d5182..8a09e9f2f 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -281,10 +281,10 @@ function check_module_conflicts($selected, $deps) { * Returns an array with all available user module names * * @param string $scope account type (user, group, host) - * @param boolean $mustSupportAdminInterface module must support LAM admin interface (default: false) - * @return array list of possible modules + * @param bool $mustSupportAdminInterface module must support LAM admin interface (default: false) + * @return string[] list of possible modules */ -function getAvailableModules($scope, $mustSupportAdminInterface = false) { +function getAvailableModules($scope, bool $mustSupportAdminInterface = false): array { $dirname = substr(__FILE__, 0, strlen(__FILE__) - 12) . "/modules"; $dir = dir($dirname); $return = []; diff --git a/lam/lib/security.inc b/lam/lib/security.inc index bf878c644..be9e41477 100644 --- a/lam/lib/security.inc +++ b/lam/lib/security.inc @@ -661,7 +661,7 @@ function validateSecurityToken() { * * @param htmlTable|htmlGroup|htmlResponsiveRow $container table */ -function addSecurityTokenToMetaHTML(&$container) { +function addSecurityTokenToMetaHTML($container) { $token = new htmlHiddenInput(getSecurityTokenName(), $_SESSION[getSecurityTokenName()]); if ($container instanceof htmlResponsiveRow) { $container->add($token); diff --git a/lam/lib/selfService.inc b/lam/lib/selfService.inc index 4d0e6e4c5..92e6a1713 100644 --- a/lam/lib/selfService.inc +++ b/lam/lib/selfService.inc @@ -125,7 +125,7 @@ function getSelfServiceOptions($scope, $fields, $attributes, $passwordChangeOnly * Checks if all input values are correct and returns the LDAP commands which should be executed. * * @param string $scope account type - * @param string $fields input fields (array( => array(, , ...))) + * @param array $fields input fields (array( => array(, , ...))) * @param array $attributes LDAP attributes * @param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable * @param array $readOnlyFields list of read-only fields diff --git a/lam/templates/tests/schemaTest.php b/lam/templates/tests/schemaTest.php index a24eb629c..2e35fa61e 100644 --- a/lam/templates/tests/schemaTest.php +++ b/lam/templates/tests/schemaTest.php @@ -11,7 +11,7 @@ use function \LAM\SCHEMA\get_cached_schema; /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2007 - 2023 Roland Gruber + Copyright (C) 2007 - 2025 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -76,10 +76,10 @@ else { $typeManager = new \LAM\TYPES\TypeManager(); $types = $typeManager->getConfiguredTypes(); foreach ($types as $type) { - $modules = $_SESSION['config']->get_AccountModules($type->getId()); + $moduleNames = $_SESSION['config']->get_AccountModules($type->getId()); $container->add(new htmlSubTitle($type->getAlias()), 12); - for ($m = 0; $m < count($modules); $m++) { - $error = checkSchemaForModule($modules[$m], $type->getScope(), $type->getId()); + foreach ($moduleNames as $moduleName) { + $error = checkSchemaForModule($moduleName, $type->getScope(), $type->getId()); $message = _("No problems found."); $icon = '../../graphics/pass.svg'; if ($error != null) { @@ -87,7 +87,8 @@ else { $message = $error; } // module name - $container->add(new htmlOutputText(getModuleAlias($modules[$m], $type->getScope())), 10, 3); + $aliasName = getModuleAlias($moduleName, $type->getScope()) ?? ''; + $container->add(new htmlOutputText($aliasName), 10, 3); // icon $container->add(new htmlImage($icon), 2); // text diff --git a/lam/templates/tools/importexport.php b/lam/templates/tools/importexport.php index 47d1fb84c..c28af38fd 100644 --- a/lam/templates/tools/importexport.php +++ b/lam/templates/tools/importexport.php @@ -160,7 +160,7 @@ function printImportTabContent(): void { $container->add($sourceRadio, 12); $container->addVerticalSpacer('1rem'); $container->add(new htmlResponsiveInputFileUpload('file', _('File'), '750'), 12); - $container->add(new htmlResponsiveInputTextarea('text', '', '60', '20', _('LDIF data'), '750'), 12); + $container->add(new htmlResponsiveInputTextarea('text', '', 60, 20, _('LDIF data'), '750'), 12); $container->add(new htmlResponsiveInputCheckbox('noStop', false, _('Don\'t stop on errors')), 12); $container->addVerticalSpacer('3rem'); @@ -200,7 +200,7 @@ function printImportTabProcessing(): void { $button = new htmlButton('submitImportCancel', _('Cancel')); $container->add($button, 12, 12, 12, 'text-center'); - $newImportButton = new htmlLink(_('New import'), null); + $newImportButton = new htmlLink(_('New import'), ''); $container->add($newImportButton, 12, 12, 12, 'text-center hidden newimport'); $container->addVerticalSpacer('3rem'); @@ -241,6 +241,9 @@ function checkImportData(): void { throw new LAMException(_('You must either upload a file or provide an import in the text box.')); } $lines = preg_split("/\n|\r\n|\r/", $ldif); + if ($lines === false) { + throw new LAMException(_('You must either upload a file or provide an import in the text box.')); + } $importer = new Importer(); $tasks = $importer->getTasks($lines); $_SESSION[Importer::SESSION_KEY_TASKS] = $tasks; @@ -395,7 +398,7 @@ function printExportTabProcessing(): void { $button = new htmlButton('submitExportCancel', _('Cancel')); $container->add($button, 12, 12, 12, 'text-center'); - $newExportButton = new htmlLink(_('New export'), null); + $newExportButton = new htmlLink(_('New export'), ''); $container->add($newExportButton, 12, 12, 12, 'text-center hidden newexport'); $container->addVerticalSpacer('3rem');