Skip to content

Commit

Permalink
Fix warnings for undefined array keys (#230)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Check for index re-queueConfirmation instead loading language file

* CS

* Use coalescing operator

* Remove String class

* Revert "Remove String class"

This reverts commit adea035.

Co-authored-by: Fritz Michael Gschwantner <[email protected]>
  • Loading branch information
rabauss and fritzmg authored Sep 21, 2021
1 parent ba54a80 commit 068f868
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions classes/tl_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion dca/tl_nc_queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions library/NotificationCenter/AutoSuggester.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand All @@ -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));
Expand Down

0 comments on commit 068f868

Please sign in to comment.