From 068f8680dd0e0d2f9f1d9b8e69a86cd726348166 Mon Sep 17 00:00:00 2001 From: Ralf Baussenwein <14016098+rabauss@users.noreply.github.com> Date: Tue, 21 Sep 2021 18:01:36 +0200 Subject: [PATCH] Fix warnings for undefined array keys (#230) * Fix warnings for undefined array key in config * Fix missing translation on cache warmup * Fix missing array key checks * Remove support for php 5.4 * Apply suggestions from code review Co-authored-by: Fritz Michael Gschwantner * Check for index re-queueConfirmation instead loading language file * CS * Use coalescing operator * Remove String class * Revert "Remove String class" This reverts commit adea03520be380a04d27ba8588afb0fc2553de32. Co-authored-by: Fritz Michael Gschwantner --- classes/tl_form.php | 6 +++--- composer.json | 2 +- config/config.php | 4 ++-- dca/tl_nc_queue.php | 2 +- library/NotificationCenter/AutoSuggester.php | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/classes/tl_form.php b/classes/tl_form.php index ab233be1..c280d163 100644 --- a/classes/tl_form.php +++ b/classes/tl_form.php @@ -82,10 +82,10 @@ public function generateTokens(array $arrData, array $arrForm, array $arrFiles, foreach ($arrData as $k => $v) { \Haste\Util\StringUtil::flatten($v, 'form_'.$k, $arrTokens, $delimiter); - $arrTokens['formlabel_'.$k] = isset($arrLabels[$k]) ? $arrLabels[$k] : ucfirst($k); - $arrTokens['raw_data'] .= (isset($arrLabels[$k]) ? $arrLabels[$k] : ucfirst($k)) . ': ' . (is_array($v) ? implode(', ', $v) : $v) . "\n"; + $arrTokens['formlabel_'.$k] = $arrLabels[$k] ?? ucfirst($k); + $arrTokens['raw_data'] .= ($arrLabels[$k] ?? ucfirst($k)) . ': ' . (is_array($v) ? implode(', ', $v) : $v) . "\n"; if (is_array($v) || strlen($v)) { - $arrTokens['raw_data_filled'] .= (isset($arrLabels[$k]) ? $arrLabels[$k] : ucfirst($k)) . ': ' . (is_array($v) ? implode(', ', $v) : $v) . "\n"; + $arrTokens['raw_data_filled'] .= ($arrLabels[$k] ?? ucfirst($k)) . ': ' . (is_array($v) ? implode(', ', $v) : $v) . "\n"; } } diff --git a/composer.json b/composer.json index 0de0bf56..b016e188 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "forum": "https://community.contao.org" }, "require":{ - "php":"^5.4 || ^7.0 || ^8.0", + "php":"^7.0 || ^8.0", "contao/core-bundle":"~3.2 || ~4.1", "contao-community-alliance/composer-plugin":"~2.4 || ~3.0", "codefog/contao-haste":"^4.14.1", diff --git a/config/config.php b/config/config.php index 1d58834e..461a3778 100644 --- a/config/config.php +++ b/config/config.php @@ -92,7 +92,7 @@ * Notification Center Gateways */ $GLOBALS['NOTIFICATION_CENTER']['GATEWAY'] = array_merge( - (array) $GLOBALS['NOTIFICATION_CENTER']['GATEWAY'], + (array) ($GLOBALS['NOTIFICATION_CENTER']['GATEWAY'] ?? []), array( 'queue' => 'NotificationCenter\Gateway\Queue', 'email' => 'NotificationCenter\Gateway\Email', @@ -105,7 +105,7 @@ * Notification Center Notification Types */ $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'] = array_merge_recursive( - (array) $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'], + (array) ($GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE'] ?? []), array( 'contao' => array( 'core_form' => array( diff --git a/dca/tl_nc_queue.php b/dca/tl_nc_queue.php index 20566328..a2dc4086 100644 --- a/dca/tl_nc_queue.php +++ b/dca/tl_nc_queue.php @@ -58,7 +58,7 @@ 'label' => &$GLOBALS['TL_LANG']['tl_nc_queue']['re-queue'], 'href' => 'key=re-queue', 'icon' => 'system/modules/notification_center/assets/re-queue.png', - 'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['tl_nc_queue']['re-queueConfirmation'] . '\'))return false;Backend.getScrollOffset()"', + 'attributes' => 'onclick="if(!confirm(\'' . ($GLOBALS['TL_LANG']['tl_nc_queue']['re-queueConfirmation'] ?? null) . '\'))return false;Backend.getScrollOffset()"', 'button_callback' => array('NotificationCenter\tl_nc_queue', 'reQueueButton') ), 'delete' => array diff --git a/library/NotificationCenter/AutoSuggester.php b/library/NotificationCenter/AutoSuggester.php index a1c196c6..87c72abe 100644 --- a/library/NotificationCenter/AutoSuggester.php +++ b/library/NotificationCenter/AutoSuggester.php @@ -42,7 +42,7 @@ public static function load($dc) static::$strType = static::$objNotification->type; foreach ($GLOBALS['TL_DCA'][static::$strTable]['fields'] as $field => $arrConfig) { - if ('nc_tokens' === $arrConfig['eval']['rgxp']) { + if ('nc_tokens' === $arrConfig['eval']['rgxp'] ?? null) { $GLOBALS['TL_DCA'][static::$strTable]['fields'][$field]['wizard'][] = array('NotificationCenter\AutoSuggester', 'init'); } } @@ -69,7 +69,7 @@ public function init(\DataContainer $dc) $arrParsedTokens = array(); foreach ($arrTokens as $strToken) { - $content = $GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN'][static::$strType][$strToken] ?: ''; + $content = $GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN'][static::$strType][$strToken] ?? ''; if (0 === strpos($strToken, 'template_')) { $content = sprintf($GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['template'], 'notification_'.substr($strToken, 9));