From 6aea0181d37b9e5e5ff65d4ca6624c40ed20e7cc Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 26 Jul 2022 08:21:32 +0200 Subject: [PATCH] refactoring --- composer.json | 2 +- lam/lib/account.inc | 2 +- lam/lib/pdfstruct.inc | 8 ++++++-- lam/lib/security.inc | 7 +++---- lam/lib/status.inc | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index d314a6015..7c6e475d9 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "ldap-account-manager/ldap-account-manager", "description": "LDAP Account Manager", "require-dev" : { - "phpunit/phpunit" : "9.5.1", + "phpunit/phpunit" : "9.5.21", "squizlabs/php_codesniffer" : "3.4.0", "phpstan/phpstan": "^1.2" }, diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 7b600f84b..164463e04 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -1968,7 +1968,7 @@ class LAMException extends Exception { * @param Exception $cause (optional) * @param int $ldapErrorCode original LDAP error code */ - public function __construct($title, $message = null, $cause = null, $ldapErrorCode = null) { + public function __construct($title, $message = '', $cause = null, $ldapErrorCode = null) { parent::__construct($message, 0, $cause); $this->title = $title; $this->ldapErrorCode = $ldapErrorCode; diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index d94f0a720..88c921bc0 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -1338,9 +1338,13 @@ class PDFStructureWriter { $writer->setIndent(true); $writer->setIndentString("\t"); $writer->startElement('pdf'); - $writer->writeAttribute('filename', $structure->getLogo()); + if ($structure->getLogo() !== null) { + $writer->writeAttribute('filename', $structure->getLogo()); + } $writer->writeAttribute('headline', $structure->getTitle()); - $writer->writeAttribute('foldingmarks', $structure->getFoldingMarks()); + if ($structure->getFoldingMarks() !== null) { + $writer->writeAttribute('foldingmarks', $structure->getFoldingMarks()); + } foreach ($structure->getSections() as $section) { if ($section instanceof PDFTextSection) { $writer->startElement('text'); diff --git a/lam/lib/security.inc b/lam/lib/security.inc index 0eb20286f..3c6d760be 100644 --- a/lam/lib/security.inc +++ b/lam/lib/security.inc @@ -134,7 +134,9 @@ function checkClientIP() { } $allowedHosts = $cfg->allowedHosts; $url = getCallingURL(); - if ((strpos($url, '/selfService/selfService') !== false) || ((strpos($url, '/misc/ajax.php?') !== false) && strpos($url, 'selfservice=1') !== false)) { + if (($url !== null) && + ((strpos($url, '/selfService/selfService') !== false) + || ((strpos($url, '/misc/ajax.php?') !== false) && strpos($url, 'selfservice=1') !== false))) { // self service pages have separate IP list $allowedHosts = $cfg->allowedHostsSelfService; } @@ -295,9 +297,6 @@ function logNewMessage($level, $message) : void { fclose($file); } } - else { - StatusMessage('ERROR', 'Unable to write to log file!', $cfg->logDestination); - } } } diff --git a/lam/lib/status.inc b/lam/lib/status.inc index a0793f6a0..b58b3e2dc 100644 --- a/lam/lib/status.inc +++ b/lam/lib/status.inc @@ -49,7 +49,7 @@ * @param boolean $returnOutput if set to true this function will return the generated HTML code instead of printing it directly (default: false) * @return String HTML code if $returnOutput is set to true, otherwise null */ -function StatusMessage($MessageTyp,$MessageHeadline,$MessageText='',$MessageVariables = array(), $returnOutput = false) { +function StatusMessage($MessageTyp, $MessageHeadline, $MessageText = '', $MessageVariables = array(), $returnOutput = false) { /* Setting CSS-StyleSheet class depending on the $MessageTyp and rewriting $MessageTyp with a readable string. */ if ($MessageTyp == "INFO") { $class = "class=\"statusInfo lam-status-message\"";