From 2c257cdd642301dd37cefb336af1504d54d03419 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Thu, 26 Dec 2024 03:21:24 +0100
Subject: [PATCH] Continued: - added type-hint 'array' - changed some string
 concating to sprintf() mask

---
 inc/extensions-functions.php       |  4 ++--
 inc/general-functions.php          |  5 +----
 inc/http-functions.php             | 10 +++++-----
 inc/libs/wernis_functions.php      | 22 ++++++----------------
 inc/libs/yoomedia_functions.php    |  7 ++-----
 inc/modules/guest/what-rallyes.php |  4 ++--
 inc/template-functions.php         | 19 ++++++++-----------
 inc/wrapper-functions.php          |  3 +--
 inc/xml-functions.php              |  2 +-
 9 files changed, 28 insertions(+), 48 deletions(-)

diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php
index acb65c929a..9b5990724f 100644
--- a/inc/extensions-functions.php
+++ b/inc/extensions-functions.php
@@ -1067,7 +1067,7 @@ function createNewExtensionTask ($ext_name) {
 	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId[' . gettype($taskId) . ']=' . $taskId);
 	if ((!isValidId($taskId)) && (!isExtensionInstalled($ext_name))) {
 		// Set default message if ext-foo is missing
-		$message = '{%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=' . $ext_name . '%}';
+		$message = sprintf('{%%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=%s%%}', $ext_name);
 
 		// Template file
 		$FQFN = sprintf('%s/ext/ext_%s.tpl',
@@ -1078,7 +1078,7 @@ function createNewExtensionTask ($ext_name) {
 		// Load text for task if found
 		if (isFileReadable($FQFN)) {
 			// Load extension's description template (but do not compile the code)
-			$message = '{OPEN_TEMPLATE}template,LoadTemplate=ext_' . $ext_name . '{CLOSE_TEMPLATE}';
+			$message = sprintf('{OPEN_TEMPLATE}template,LoadTemplate=ext_%s{CLOSE_TEMPLATE}', $ext_name);
 		} else {
 			// Write this in debug.log as well
 			logDebugMessage(__FUNCTION__, __LINE__, $message);
diff --git a/inc/general-functions.php b/inc/general-functions.php
index 8ede164135..e962e0c627 100644
--- a/inc/general-functions.php
+++ b/inc/general-functions.php
@@ -425,10 +425,7 @@ function translateUserStatus ($status) {
 }
 
 // "Translates" 'visible' and 'locked' to a CSS class
-function translateMenuVisibleLocked ($content, $prefix = '') {
-	// 1st parameter should be an array
-	assert(is_array($content));
-
+function translateMenuVisibleLocked (array $content, $prefix = '') {
 	// Default is 'menu_unknown'
 	$content['visible_css'] = $prefix . 'menu_unknown';
 
diff --git a/inc/http-functions.php b/inc/http-functions.php
index 0c040865ff..62bca5438c 100644
--- a/inc/http-functions.php
+++ b/inc/http-functions.php
@@ -448,7 +448,7 @@ function sendRawRequest ($host, $request, $allowOnlyHttpOkay = TRUE) {
 	// Proxy agent found or something went wrong?
 	if (!isFilledArray($response)) {
 		// No response, maybe timeout
-		$response = array('', '', '');
+		$response = ['', '', ''];
 		logDebugMessage(__FUNCTION__, __LINE__, 'Invalid empty response array, maybe timed out?');
 	} elseif ((substr(strtolower($response[0]), 0, 11) == 'proxy-agent') && (isProxyUsed() === TRUE)) {
 		// Proxy header detected, so remove two lines
@@ -460,7 +460,7 @@ function sendRawRequest ($host, $request, $allowOnlyHttpOkay = TRUE) {
 	if ((!isHttpStatusOkay($response[0])) && ($allowOnlyHttpOkay === TRUE)) {
 		// Not found / access forbidden
 		logDebugMessage(__FUNCTION__, __LINE__, 'Unexpected status code ' . $response[0] . ' detected. "200 OK" was expected.');
-		$response = array('', '', '');
+		$response = ['', '', ''];
 	} else {
 		// Check array for chuncked encoding
 		$response = unchunkHttpResponse($response);
@@ -473,13 +473,13 @@ function sendRawRequest ($host, $request, $allowOnlyHttpOkay = TRUE) {
 // Is HTTP status okay?
 function isHttpStatusOkay ($header) {
 	// Determine it
-	return in_array(strtoupper(trim($header)), array('HTTP/1.1 200 OK', 'HTTP/1.0 200 OK'));
+	return in_array(strtoupper(trim($header)), ['HTTP/1.1 200 OK', 'HTTP/1.0 200 OK']);
 }
 
 // Sets up a proxy tunnel for given hostname and through resource
 function setupProxyTunnel ($host, $proxyHost, $port, $resource) {
 	// Initialize array
-	$response = array('', '', '');
+	$response = ['', '', ''];
 
 	// Generate CONNECT request header
 	$proxyTunnel  = 'CONNECT ' . $host . ':' . $port . ' HTTP/1.0' . getConfig('HTTP_EOL');
@@ -519,7 +519,7 @@ function setupProxyTunnel ($host, $proxyHost, $port, $resource) {
 }
 
 // Check array for chuncked encoding
-function unchunkHttpResponse ($response) {
+function unchunkHttpResponse (array $response) {
 	// Default is not chunked
 	$isChunked = FALSE;
 
diff --git a/inc/libs/wernis_functions.php b/inc/libs/wernis_functions.php
index c9fe0da434..b8b3dccc6d 100644
--- a/inc/libs/wernis_functions.php
+++ b/inc/libs/wernis_functions.php
@@ -443,24 +443,21 @@ function executeWernisApiAuth ($wernisId, $wernisPassword) {
 }
 
 // Execute get.php reguest with given auth data (not all are used)
-function executeWernisApiGet ($authData, $subRequest, $fields) {
-	// It must be an array
-	assert(is_array($authData));
-
+function executeWernisApiGet (array $authData, $subRequest, $fields) {
 	// Check required array elements
 	assert(isset($authData['wernis_userid']));
 	assert(isset($authData['api_auth_key']));
 	assert(isset($authData['api_redirect_challenge']));
 
 	// Then create request array
-	$requestData = array(
+	$requestData = [
 		'sub_request' => $subRequest,
 		'fields'      => $fields,
 		't_uid'       => bigintval($authData['wernis_userid']),
 		't_md5'       => getWernisPassMd5(),
 		'auth_key'    => $authData['api_auth_key'],
 		'challenge'   => $authData['api_redirect_challenge']
-	);
+	];
 
 	// Call get.php
 	$return = sendWernisApiRequest('get.php', $requestData);
@@ -873,9 +870,8 @@ function generateWernisDecryptionKey ($publicKey) {
 }
 
 // Registers or updates Wernis registration data
-function registerUpdateWernisRegistrationCall ($args, $challenge, $status) {
+function registerUpdateWernisRegistrationCall (array $args, $challenge, $status) {
 	// Make sure the required array elements are there
-	assert(is_array($args));
 	assert(isset($args['auth_key']));
 	assert(isset($args['wernis_userid']));
 
@@ -929,10 +925,7 @@ LIMIT 1",
 //-----------------------------------------------------------------------------
 
 // Handler for auth_status=PENDING
-function doWernisAuthPending ($args) {
-	// $args must always be an array
-	assert(is_array($args));
-
+function doWernisAuthPending (array $args) {
 	// auth_key and wernis_userid must be set
 	assert(isset($args['auth_key']));
 	assert(isset($args['wernis_userid']));
@@ -952,10 +945,7 @@ function doWernisAuthPending ($args) {
 }
 
 // Handler for auth_status=ACCEPTED
-function doWernisAuthAccepted ($args) {
-	// $args must always be an array
-	assert(is_array($args));
-
+function doWernisAuthAccepted (array $args) {
 	// auth_key and wernis_userid must be set
 	assert(isset($args['auth_key']));
 	assert(isset($args['wernis_userid']));
diff --git a/inc/libs/yoomedia_functions.php b/inc/libs/yoomedia_functions.php
index 1cec650162..ba26382584 100644
--- a/inc/libs/yoomedia_functions.php
+++ b/inc/libs/yoomedia_functions.php
@@ -150,7 +150,7 @@ function YOOMEDIA_GET_PARSED_RESULT_TEXTMAILS () {
 }
 
 // Parser function for Yoo!Media API responses
-function YOOMEDIA_PARSE_RESPONSE ($response, $type) {
+function YOOMEDIA_PARSE_RESPONSE (array $response, $type) {
 	// Init result
 	$result = [];
 
@@ -382,10 +382,7 @@ function YOOMEDIA_CONVERT_MODE ($mailMode) {
 }
 
 // Extract code from response
-function YOOMEDIA_GET_ERRORCODE_FROM_RESULT ($response) {
-	// The response must be an array
-	assert(is_array($response));
-
+function YOOMEDIA_GET_ERRORCODE_FROM_RESULT (array $response) {
 	// Bad code as default
 	$code = -999;
 
diff --git a/inc/modules/guest/what-rallyes.php b/inc/modules/guest/what-rallyes.php
index 4f88889da6..99cc23fb9d 100644
--- a/inc/modules/guest/what-rallyes.php
+++ b/inc/modules/guest/what-rallyes.php
@@ -96,7 +96,7 @@ if (sqlNumRows($result) == 1) {
 	// Handle description...
 	if ((empty($content['descr'])) && (!empty($content['template']))) {
 		// Use description from template
-		$content['descr'] = '{%template,LoadTemplate=rallye_' . $content['template'] . '%}';
+		$content['descr'] = sprintf('{%%template,LoadTemplate=rallye_%s%%}', $content['template']);
 	} // END - if
 
 	// Set start and end time
@@ -105,7 +105,7 @@ if (sqlNumRows($result) == 1) {
 
 	if ($expired === TRUE) {
 		$content['prices']       = addReferralRallyeWinners('guest', $content['id']);
-		$content['top_users']    = '<div align="center" class="big">' . $content['extras'] . '</div>';
+		$content['top_users']    = sprintf('<div align="center" class="big">%s</div>', $content['extras']);
 		$content['can_win_this'] = '{--RALLYE_OUR_WINNERS_ARE--}';
 	} else {
 		$content['prices']       = addReferralRallyePrices($content['id'], 'html');
diff --git a/inc/template-functions.php b/inc/template-functions.php
index edf8be94aa..c081c43a6c 100644
--- a/inc/template-functions.php
+++ b/inc/template-functions.php
@@ -1826,10 +1826,7 @@ function sendModeMails ($mod, $modes) {
 }
 
 // Generates a 'selection box' from given array
-function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = FALSE, $useDefaultAsArray = FALSE) {
-	// options must be an array
-	assert(is_array($options));
-
+function generateSelectionBoxFromArray (array $options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = FALSE, $useDefaultAsArray = FALSE) {
 	// Default is empty
 	$addKey = '';
 
@@ -1887,9 +1884,9 @@ function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionCont
 	$OUT .= '</select>';
 
 	// Prepare output
-	$content = array(
+	$content = [
 		'selection_box' => $OUT,
-	);
+	];
 
 	// Load template and return it
 	if (empty($templateName)) {
@@ -1929,7 +1926,7 @@ function addPageHeaderFooter () {
 	$OUT = '';
 
 	// Add them all together. This is maybe to simple
-	foreach (array('__page_header', '__output', '__page_footer') as $pagePart) {
+	foreach (['__page_header', '__output', '__page_footer'] as $pagePart) {
 		// Add page part if set
 		if (isset($GLOBALS[$pagePart])) {
 			$OUT .= $GLOBALS[$pagePart];
@@ -2164,7 +2161,7 @@ function compactContent ($uncompactedContent) {
 	$compactedContent = str_replace(chr(9), '', str_replace(PHP_EOL, '', str_replace(chr(13), '', $uncompactedContent)));
 
 	// Make a space after >
-	$compactedContent = str_replace(array('>', '  '), array('> ', ' '), $compactedContent);
+	$compactedContent = str_replace(['>', '  '], ['> ', ' '], $compactedContent);
 
 	// Then regex all comments like <!-- //--> away
 	preg_match_all('/<!--[\w\W]*?(\/\/){0,1}-->/', $compactedContent, $matches);
@@ -2277,14 +2274,14 @@ function doTemplateNoYesSelectionBox ($templateName, $clear, $formField) {
 // Helper function to add extra content for guest area (module=index and others)
 function doTemplateGuestFooterExtras ($templateName, $clear) {
 	// Init filter data
-	$filterData = array(
+	$filterData = [
 		// Name of used template
 		'template' => $templateName,
 		// Target array for gathered data
 		'__data'   => [],
 		// Where the HTML output will go
 		'__output' => '',
-	);
+	];
 
 	// Run the filter chain
 	$filterData = runFilterChain('guest_footer_extras', $filterData);
@@ -2396,7 +2393,7 @@ function doTemplateDereferrerUrl ($templateName, $clear = FALSE, $url = NULL) {
 	// Is the URL not NULL and not empty?
 	if ((!is_null($url)) && (!empty($url))) {
 		// Set HTML with EL code
-		$url = '<a href="{%pipe,generateDereferrerUrl=' . $url . '%}" rel="external" target="_blank">{--ADMIN_TEST_URL--}</a>';
+		$url = sprintf('<a href="{%%pipe,generateDereferrerUrl=%s%%}" rel="external" target="_blank">{--ADMIN_TEST_URL--}</a>', $url);
 	} // END - if
 
 	// Return URL (or content) or dashes if empty
diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php
index 960c723826..3359e772da 100644
--- a/inc/wrapper-functions.php
+++ b/inc/wrapper-functions.php
@@ -3496,9 +3496,8 @@ function translateFullComma ($dotted) {
 }
 
 // Wrapper to check if the first element to be shifted is set to given value
-function shift_array (&$array, $value, $key = '0') {
+function shift_array (array &$array, $value, $key = '0') {
 	// Is the element set and value matches?
-	assert(is_array($array));
 	assert(isset($array[$key]));
 	assert($array[$key] === $value);
 
diff --git a/inc/xml-functions.php b/inc/xml-functions.php
index 7d95d59710..925e2ceab6 100644
--- a/inc/xml-functions.php
+++ b/inc/xml-functions.php
@@ -290,7 +290,7 @@ function getSqlXmlFromTable ($tableName) {
 }
 
 // "Getter" for sql part back from given array
-function getSqlPartFromXmlArray ($columns) {
+function getSqlPartFromXmlArray (array $columns) {
 	// Init SQL
 	$sql = '';
 
-- 
2.39.5