From 06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 14 Nov 2023 14:47:55 +0100 Subject: Add function param/return types, fix a lot more phpstorm complaints --- .../serversetup-bwlp-ipxe/page.inc.php | 73 +++++++++++----------- 1 file changed, 35 insertions(+), 38 deletions(-) (limited to 'modules-available/serversetup-bwlp-ipxe/page.inc.php') diff --git a/modules-available/serversetup-bwlp-ipxe/page.inc.php b/modules-available/serversetup-bwlp-ipxe/page.inc.php index 8d4a366f..c9260687 100644 --- a/modules-available/serversetup-bwlp-ipxe/page.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/page.inc.php @@ -123,23 +123,23 @@ class Page_ServerSetup extends Page $addr = false; if (User::hasPermission('ipxe.menu.view')) { - Dashboard::addSubmenu('?do=serversetup&show=menu', Dictionary::translate('submenu_menu', true)); + Dashboard::addSubmenu('?do=serversetup&show=menu', Dictionary::translate('submenu_menu')); } if (User::hasPermission('ipxe.bootentry.view')) { - Dashboard::addSubmenu('?do=serversetup&show=bootentry', Dictionary::translate('submenu_bootentry', true)); + Dashboard::addSubmenu('?do=serversetup&show=bootentry', Dictionary::translate('submenu_bootentry')); } if (User::hasPermission('edit.address')) { - Dashboard::addSubmenu('?do=serversetup&show=address', Dictionary::translate('submenu_address', true)); + Dashboard::addSubmenu('?do=serversetup&show=address', Dictionary::translate('submenu_address')); $addr = true; } if (User::hasPermission('download')) { - Dashboard::addSubmenu('?do=serversetup&show=download', Dictionary::translate('submenu_download', true)); + Dashboard::addSubmenu('?do=serversetup&show=download', Dictionary::translate('submenu_download')); } if (User::hasPermission('ipxe.localboot.*')) { - Dashboard::addSubmenu('?do=serversetup&show=localboot', Dictionary::translate('submenu_localboot', true)); + Dashboard::addSubmenu('?do=serversetup&show=localboot', Dictionary::translate('submenu_localboot')); } if (User::hasPermission('ipxe.bootentry.edit')) { - Dashboard::addSubmenu('?do=serversetup&show=import', Dictionary::translate('submenu_import', true)); + Dashboard::addSubmenu('?do=serversetup&show=import', Dictionary::translate('submenu_import')); } if (Request::get('show') === false) { $subs = Dashboard::getSubmenus(); @@ -219,7 +219,6 @@ class Page_ServerSetup extends Page break; default: Util::redirect('?do=serversetup'); - break; } } @@ -231,17 +230,17 @@ class Page_ServerSetup extends Page }); $files = []; $strings = [ - 'efi' => [Dictionary::translate('dl-efi', true) => 50], - 'pcbios' => [Dictionary::translate('dl-pcbios', true) => 51], - 'usb' => [Dictionary::translate('dl-usb', true) => 80], - 'hd' => [Dictionary::translate('dl-hd', true) => 81], - 'lkrn' => [Dictionary::translate('dl-lkrn', true) => 82], - 'i386' => [Dictionary::translate('dl-i386', true) => 10], - 'x86_64' => [Dictionary::translate('dl-x86_64', true) => 11], - 'ecm' => [Dictionary::translate('dl-usbnic', true) => 60], - 'ncm' => [Dictionary::translate('dl-usbnic', true) => 61], - 'ipxe' => [Dictionary::translate('dl-pcinic', true) => 62], - 'snp' => [Dictionary::translate('dl-snp', true) => 63], + 'efi' => [Dictionary::translate('dl-efi') => 50], + 'pcbios' => [Dictionary::translate('dl-pcbios') => 51], + 'usb' => [Dictionary::translate('dl-usb') => 80], + 'hd' => [Dictionary::translate('dl-hd') => 81], + 'lkrn' => [Dictionary::translate('dl-lkrn') => 82], + 'i386' => [Dictionary::translate('dl-i386') => 10], + 'x86_64' => [Dictionary::translate('dl-x86_64') => 11], + 'ecm' => [Dictionary::translate('dl-usbnic') => 60], + 'ncm' => [Dictionary::translate('dl-usbnic') => 61], + 'ipxe' => [Dictionary::translate('dl-pcinic') => 62], + 'snp' => [Dictionary::translate('dl-snp') => 63], ]; foreach ($list as $file) { if ($file[0] === '.') @@ -267,7 +266,10 @@ class Page_ServerSetup extends Page Render::addTemplate('download', ['files' => $files]); } - private function makeSelectArray($list, $defaults) + /** + * @return array{EFI: array, PCBIOS: array} + */ + private function makeSelectArray(array $list, array $defaults): array { $ret = ['EFI' => [], 'PCBIOS' => []]; foreach (['PCBIOS', 'EFI'] as $m) { @@ -326,7 +328,7 @@ class Page_ServerSetup extends Page GROUP BY be.entryid, be.title"); if (empty($bootentryTable)) { - if (Property::getServerIp() === false || Property::getServerIp() === 'invalid') { + if (Property::getServerIp() === 'invalid') { Message::addError('no-ip-set'); Util::redirect('?do=serversetup&show=address'); } @@ -379,7 +381,7 @@ class Page_ServerSetup extends Page )); } - private function hasMenuPermission($menuid, $permission) + private function hasMenuPermission(int $menuid, string $permission): bool { $allowedEditLocations = User::getAllowedLocations($permission); $allowEdit = in_array(0, $allowedEditLocations); @@ -466,7 +468,7 @@ class Page_ServerSetup extends Page if ($k === 'id') continue; $bootentry['otherFields'][] = [ - 'key' => Dictionary::translateFileModule($bootentry['module'], 'module', 'ipxe-' . $k, true), + 'key' => Dictionary::translateFileModule($bootentry['module'], 'module', 'ipxe-' . $k), 'value' => is_bool($v) ? Util::boolToString($v) : $v, ]; } @@ -483,16 +485,16 @@ class Page_ServerSetup extends Page continue; // Naming and agnostic if ($bootentry['data']['arch'] === BootEntry::BIOS) { - $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_biosOnly', true); + $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_biosOnly'); unset($bootentry['data']['EFI']); } elseif ($bootentry['data']['arch'] === BootEntry::EFI) { - $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_efiOnly', true); + $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_efiOnly'); unset($bootentry['data']['PCBIOS']); } elseif ($bootentry['data']['arch'] === BootEntry::AGNOSTIC) { - $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archAgnostic', true); + $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archAgnostic'); unset($bootentry['data']['EFI']); } else { - $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archBoth', true); + $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archBoth'); } foreach ($bootentry['data'] as &$e) { if (isset($e['initRd'])) { @@ -537,12 +539,7 @@ class Page_ServerSetup extends Page } if ($row['module'][0] === '.') { // either script or exec entry - $json = json_decode($row['data'], true); - if (!is_array($json)) { - Message::addError('unknown-bootentry-type', $id); - Util::redirect('?do=serversetup&show=bootentry'); - } - $entry = BootEntry::fromJson($row['module'], $json); + $entry = BootEntry::fromJson($row['module'], $row['data']); if ($entry === null) { Message::addError('unknown-bootentry-type', $id); Util::redirect('?do=serversetup&show=bootentry'); @@ -599,7 +596,7 @@ class Page_ServerSetup extends Page { $status = IPxeBuilder::getVersionTaskResult(); $versions = false; - if ($status === false) { + if ($status === null) { $error = 'Taskmanager down'; } elseif (!empty($status['versions'])) { $versions = $status['versions']; @@ -801,7 +798,7 @@ class Page_ServerSetup extends Page || $defaultEntryId === null)) { // if still null, use whatever as fallback, in case user didn't select any $defaultEntryId = $newKey; } - $keepIds[] = (int)$newKey; + $keepIds[] = $newKey; if (!empty($entry['plainpass'])) { Database::exec('UPDATE serversetup_menuentry SET md5pass = :md5pass WHERE menuentryid = :id', [ 'md5pass' => IPxe::makeMd5Pass($entry['plainpass'], $newKey), @@ -894,7 +891,7 @@ class Page_ServerSetup extends Page } else { // Module hook $hook = Hook::loadSingle($type, 'ipxe-bootentry'); - if ($hook === false) { + if ($hook === null) { Message::addError('unknown-bootentry-type', $type); return; } @@ -1073,7 +1070,7 @@ class Page_ServerSetup extends Page Util::redirect('?do=serversetup&show=import'); } $menu = PxeLinux::parsePxeLinux($content, false); - if (empty($menu->sections)) { + if ($menu === null) { Message::addWarning('import-no-entries'); Util::redirect('?do=serversetup&show=import'); } @@ -1082,8 +1079,8 @@ class Page_ServerSetup extends Page IPxe::importPxeMenuEntries($menu, $foo); Util::redirect('?do=serversetup&show=bootentry'); } else { - $id = IPxe::insertMenu($menu, 'Imported Menu', false, 0, [], []); - if ($id === false) { + $id = IPxe::insertMenu($menu, 'Imported Menu', null, 0, [], []); + if ($id === null) { Message::addError('import-error'); Util::redirect('?do=serversetup&show=import'); } else { -- cgit v1.2.3-55-g7522