From f9d46d4cafef0fcb92549973303c5cb11e80c567 Mon Sep 17 00:00:00 2001 From: Tuan Pham Ngoc Date: Sun, 16 Feb 2025 14:42:41 +0700 Subject: [PATCH] Use ternary operator for libraries code --- libraries/src/Form/Field/CalendarField.php | 20 ++++++++++---------- libraries/src/Form/Form.php | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libraries/src/Form/Field/CalendarField.php b/libraries/src/Form/Field/CalendarField.php index fa1d9cd04226e..94d2caa2d104c 100644 --- a/libraries/src/Form/Field/CalendarField.php +++ b/libraries/src/Form/Field/CalendarField.php @@ -233,16 +233,16 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) $return = parent::setup($element, $value, $group); if ($return) { - $this->maxlength = (int) $this->element['maxlength'] ? (int) $this->element['maxlength'] : 45; - $this->format = (string) $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d'; - $this->filterFormat = (string) $this->element['filterformat'] ? (string) $this->element['filterformat'] : ''; - $this->filter = (string) $this->element['filter'] ? (string) $this->element['filter'] : 'USER_UTC'; - $this->todaybutton = (string) $this->element['todaybutton'] ? (string) $this->element['todaybutton'] : 'true'; - $this->weeknumbers = (string) $this->element['weeknumbers'] ? (string) $this->element['weeknumbers'] : 'true'; - $this->showtime = (string) $this->element['showtime'] ? (string) $this->element['showtime'] : 'false'; - $this->filltable = (string) $this->element['filltable'] ? (string) $this->element['filltable'] : 'true'; - $this->timeformat = (int) $this->element['timeformat'] ? (int) $this->element['timeformat'] : 24; - $this->singleheader = (string) $this->element['singleheader'] ? (string) $this->element['singleheader'] : 'false'; + $this->maxlength = (int) $this->element['maxlength'] ?: 45; + $this->format = (string) $this->element['format'] ?: '%Y-%m-%d'; + $this->filterFormat = (string) $this->element['filterformat'] ?: ''; + $this->filter = (string) $this->element['filter'] ?: 'USER_UTC'; + $this->todaybutton = (string) $this->element['todaybutton'] ?: 'true'; + $this->weeknumbers = (string) $this->element['weeknumbers'] ?: 'true'; + $this->showtime = (string) $this->element['showtime'] ?: 'false'; + $this->filltable = (string) $this->element['filltable'] ?: 'true'; + $this->timeformat = (int) $this->element['timeformat'] ?: 24; + $this->singleheader = (string) $this->element['singleheader'] ?: 'false'; $this->minyear = \strlen((string) $this->element['minyear']) ? (int) $this->element['minyear'] : null; $this->maxyear = \strlen((string) $this->element['maxyear']) ? (int) $this->element['maxyear'] : null; diff --git a/libraries/src/Form/Form.php b/libraries/src/Form/Form.php index ccc34ab7c6a54..766fc33a618fa 100644 --- a/libraries/src/Form/Form.php +++ b/libraries/src/Form/Form.php @@ -1487,7 +1487,7 @@ protected function loadField($element, $group = null, $value = null) * else the value of the 'default' attribute for the field. */ if ($value === null) { - $default = (string) ($element['default'] ? $element['default'] : $element->default); + $default = (string) ($element['default'] ?: $element->default); if (($translate = $element['translate_default']) && ((string) $translate === 'true' || (string) $translate === '1')) { $lang = Factory::getLanguage();