Commit aa873df8 authored by Wouter Wolters's avatar Wouter Wolters Committed by Benni Mack
Browse files

[TASK] Use null coalescing operator where possible

Using null coalescing operator in PHP 7 simplifies code structure.

Resolves: #83129
Releases: master
Change-Id: I449415c99ccb0ea158d3943800bc824514f7629c
Reviewed-on: https://review.typo3.org/54810


Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent a9e13401
......@@ -489,7 +489,7 @@ class ShortcutToolbarItem implements ToolbarItemInterface
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$shortcutId = (int)(isset($parsedBody['shortcutId']) ? $parsedBody['shortcutId'] : $queryParams['shortcutId']);
$shortcutId = (int)($parsedBody['shortcutId'] ?? $queryParams['shortcutId']);
$fullShortcut = $this->getShortcutById($shortcutId);
$success = false;
if ($fullShortcut['raw']['userid'] == $this->getBackendUser()->user['uid']) {
......@@ -526,7 +526,7 @@ class ShortcutToolbarItem implements ToolbarItemInterface
// Default name
$shortcutName = 'Shortcut';
$shortcutNamePrepend = '';
$url = isset($parsedBody['url']) ? $parsedBody['url'] : $queryParams['url'];
$url = $parsedBody['url'] ?? $queryParams['url'];
// Use given display name
if (!empty($parsedBody['displayName'])) {
......@@ -699,9 +699,9 @@ class ShortcutToolbarItem implements ToolbarItemInterface
$queryParams = $request->getQueryParams();
$backendUser = $this->getBackendUser();
$shortcutId = (int)(isset($parsedBody['shortcutId']) ? $parsedBody['shortcutId'] : $queryParams['shortcutId']);
$shortcutName = strip_tags(isset($parsedBody['shortcutTitle']) ? $parsedBody['shortcutTitle'] : $queryParams['shortcutTitle']);
$shortcutGroupId = (int)(isset($parsedBody['shortcutGroup']) ? $parsedBody['shortcutGroup'] : $queryParams['shortcutGroup']);
$shortcutId = (int)($parsedBody['shortcutId'] ?? $queryParams['shortcutId']);
$shortcutName = strip_tags($parsedBody['shortcutTitle'] ?? $queryParams['shortcutTitle']);
$shortcutGroupId = (int)($parsedBody['shortcutGroup'] ?? $queryParams['shortcutGroup']);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_be_shortcuts');
......@@ -745,7 +745,7 @@ class ShortcutToolbarItem implements ToolbarItemInterface
*/
protected function getShortcutGroupLabel($groupId)
{
return isset($this->shortcutGroups[$groupId]) ? $this->shortcutGroups[$groupId] : '';
return $this->shortcutGroups[$groupId] ?? '';
}
/**
......
......@@ -171,7 +171,7 @@ class ConditionMatcher extends AbstractConditionMatcher
*/
protected function getPage()
{
$pageId = isset($this->pageId) ? $this->pageId : $this->determinePageId();
$pageId = $this->pageId ?? $this->determinePageId();
return BackendUtility::getRecord('pages', $pageId);
}
......@@ -244,7 +244,7 @@ class ConditionMatcher extends AbstractConditionMatcher
*/
protected function determineRootline()
{
$pageId = isset($this->pageId) ? $this->pageId : $this->determinePageId();
$pageId = $this->pageId ?? $this->determinePageId();
return BackendUtility::BEgetRootLine($pageId, '', true);
}
......
......@@ -294,9 +294,7 @@ class RecordProvider extends AbstractProvider
}
if ($itemName === 'newWizard' && $this->table === 'tt_content') {
$tsConfig = BackendUtility::getModTSconfig($this->record['pid'], 'mod');
$moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
? $tsConfig['properties']['newContentElementWizard.']['override']
: 'new_content_element_wizard';
$moduleName = $tsConfig['properties']['newContentElementWizard.']['override'] ?? 'new_content_element_wizard';
$urlParameters = [
'id' => $this->record['pid'],
'sys_language_uid' => $this->record['sys_language_uid'],
......@@ -495,7 +493,7 @@ class RecordProvider extends AbstractProvider
protected function canBeDeleted(): bool
{
$disableDeleteTS = $this->backendUser->getTSConfig('options.disableDelete');
$disableDelete = (bool) trim(isset($disableDeleteTS['properties'][$this->table]) ? $disableDeleteTS['properties'][$this->table] : (string)$disableDeleteTS['value']);
$disableDelete = (bool) trim($disableDeleteTS['properties'][$this->table] ?? (string)$disableDeleteTS['value']);
return !$disableDelete && $this->canBeEdited();
}
......
......@@ -139,6 +139,6 @@ class AjaxLoginController
*/
protected function getBackendUser()
{
return isset($GLOBALS['BE_USER']) ? $GLOBALS['BE_USER'] : null;
return $GLOBALS['BE_USER'] ?? null;
}
}
......@@ -36,7 +36,7 @@ class ContextHelpAjaxController
*/
public function getHelpAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$params = isset($request->getParsedBody()['params']) ? $request->getParsedBody()['params'] : $request->getQueryParams()['params'];
$params = $request->getParsedBody()['params'] ?? $request->getQueryParams()['params'];
if ($params['action'] === 'getContextHelp') {
$result = $this->getContextHelp($params['table'], $params['field']);
return GeneralUtility::makeInstance(JsonResponse::class, [
......
......@@ -47,7 +47,7 @@ class ContextMenuController
$contextMenu = GeneralUtility::makeInstance(ContextMenu::class);
$params = $request->getQueryParams();
$context = isset($params['context']) ? $params['context'] : '';
$context = $params['context'] ?? '';
$items = $contextMenu->getItems($params['table'], $params['uid'], $context);
if (!is_array($items)) {
$items = [];
......
......@@ -783,9 +783,7 @@ class EditDocumentController
}
$pageTsConfig = BackendUtility::getPagesTSconfig($currentPageId);
$previewConfiguration = isset($pageTsConfig['TCEMAIN.']['preview.'][$table . '.'])
? $pageTsConfig['TCEMAIN.']['preview.'][$table . '.']
: [];
$previewConfiguration = $pageTsConfig['TCEMAIN.']['preview.'][$table . '.'] ?? [];
$recordArray = BackendUtility::getRecord($table, $recordId);
......@@ -823,13 +821,9 @@ class EditDocumentController
];
// language handling
$languageField = isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
? $GLOBALS['TCA'][$table]['ctrl']['languageField']
: '';
$languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? '';
if ($languageField && !empty($recordArray[$languageField])) {
$l18nPointer = isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'])
? $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']
: '';
$l18nPointer = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] ?? '';
if ($l18nPointer && !empty($recordArray[$l18nPointer])
&& isset($previewConfiguration['useDefaultLanguageRecord'])
&& !$previewConfiguration['useDefaultLanguageRecord']
......@@ -1873,7 +1867,7 @@ class EditDocumentController
public function getNewIconMode($table, $key = 'saveDocNew')
{
$TSconfig = $this->getBackendUser()->getTSConfig('options.' . $key);
$output = trim(isset($TSconfig['properties'][$table]) ? $TSconfig['properties'][$table] : $TSconfig['value']);
$output = trim($TSconfig['properties'][$table] ?? $TSconfig['value']);
return $output;
}
......
......@@ -246,8 +246,8 @@ class FileController
*/
public function fileExistsInFolderAction(ServerRequestInterface $request)
{
$fileName = isset($request->getParsedBody()['fileName']) ? $request->getParsedBody()['fileName'] : $request->getQueryParams()['fileName'];
$fileTarget = isset($request->getParsedBody()['fileTarget']) ? $request->getParsedBody()['fileTarget'] : $request->getQueryParams()['fileTarget'];
$fileName = $request->getParsedBody()['fileName'] ?? $request->getQueryParams()['fileName'];
$fileTarget = $request->getParsedBody()['fileTarget'] ?? $request->getQueryParams()['fileTarget'];
/** @var \TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory */
$fileFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
......
......@@ -43,7 +43,7 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
*/
public function createAction(ServerRequestInterface $request): ResponseInterface
{
$ajaxArguments = isset($request->getParsedBody()['ajax']) ? $request->getParsedBody()['ajax'] : $request->getQueryParams()['ajax'];
$ajaxArguments = $request->getParsedBody()['ajax'] ?? $request->getQueryParams()['ajax'];
$parentConfig = $this->extractSignedParentConfigFromRequest((string)$ajaxArguments['context']);
$domObjectId = $ajaxArguments[0];
......@@ -173,7 +173,7 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
*/
public function detailsAction(ServerRequestInterface $request): ResponseInterface
{
$ajaxArguments = isset($request->getParsedBody()['ajax']) ? $request->getParsedBody()['ajax'] : $request->getQueryParams()['ajax'];
$ajaxArguments = $request->getParsedBody()['ajax'] ?? $request->getQueryParams()['ajax'];
$domObjectId = $ajaxArguments[0];
$inlineFirstPid = $this->getInlineFirstPidFromDomObjectId($domObjectId);
......@@ -255,7 +255,7 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
*/
public function synchronizeLocalizeAction(ServerRequestInterface $request): ResponseInterface
{
$ajaxArguments = isset($request->getParsedBody()['ajax']) ? $request->getParsedBody()['ajax'] : $request->getQueryParams()['ajax'];
$ajaxArguments = $request->getParsedBody()['ajax'] ?? $request->getQueryParams()['ajax'];
$domObjectId = $ajaxArguments[0];
$type = $ajaxArguments[1];
$parentConfig = $this->extractSignedParentConfigFromRequest((string)$ajaxArguments['context']);
......@@ -412,7 +412,7 @@ class FormInlineAjaxController extends AbstractFormEngineAjaxController
*/
public function expandOrCollapseAction(ServerRequestInterface $request): ResponseInterface
{
$ajaxArguments = isset($request->getParsedBody()['ajax']) ? $request->getParsedBody()['ajax'] : $request->getQueryParams()['ajax'];
$ajaxArguments = $request->getParsedBody()['ajax'] ?? $request->getQueryParams()['ajax'];
$domObjectId = $ajaxArguments[0];
/** @var InlineStackProcessor $inlineStackProcessor */
......
......@@ -38,7 +38,7 @@ class LogoutController
{
$this->logout();
$redirectUrl = isset($request->getParsedBody()['redirect']) ? $request->getParsedBody()['redirect'] : $request->getQueryParams()['redirect'];
$redirectUrl = $request->getParsedBody()['redirect'] ?? $request->getQueryParams()['redirect'];
$redirectUrl = GeneralUtility::sanitizeLocalUrl($redirectUrl);
if (empty($redirectUrl)) {
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
......
......@@ -544,9 +544,7 @@ class NewRecordController
. '<ul>';
// If mod.newContentElementWizard.override is set, use that extension's wizard instead:
$tsConfig = BackendUtility::getModTSconfig($this->id, 'mod');
$moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
? $tsConfig['properties']['newContentElementWizard.']['override']
: 'new_content_element_wizard';
$moduleName = $tsConfig['properties']['newContentElementWizard.']['override'] ?? 'new_content_element_wizard';
$url = (string)$uriBuilder->buildUriFromRoute($moduleName, ['id' => $this->id, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]);
$rowContent .= '<li>' . $newLink . ' ' . BackendUtility::wrapInHelp($table, '') . '</li>'
. '<li>'
......
......@@ -152,7 +152,7 @@ class SimpleDataHandlerController
$this->cmd = $clipObj->makePasteCmdArray(
$this->CB['paste'],
$this->cmd,
isset($this->CB['update']) ? $this->CB['update'] : null
$this->CB['update'] ?? null
);
}
if ($this->CB['delete']) {
......
......@@ -36,9 +36,9 @@ class UserSettingsController
public function processAjaxRequest(ServerRequestInterface $request): ResponseInterface
{
// do the regular / main logic, depending on the action parameter
$action = isset($request->getParsedBody()['action']) ? $request->getParsedBody()['action'] : $request->getQueryParams()['action'];
$key = isset($request->getParsedBody()['key']) ? $request->getParsedBody()['key'] : $request->getQueryParams()['key'];
$value = isset($request->getParsedBody()['value']) ? $request->getParsedBody()['value'] : $request->getQueryParams()['value'];
$action = $request->getParsedBody()['action'] ?? $request->getQueryParams()['action'];
$key = $request->getParsedBody()['key'] ?? $request->getQueryParams()['key'];
$value = $request->getParsedBody()['value'] ?? $request->getQueryParams()['value'];
$content = $this->process($action, $key, $value);
return GeneralUtility::makeInstance(JsonResponse::class)->setPayload($content);
......
......@@ -157,7 +157,7 @@ class SuggestWizardController
}
// Limit the number of items in the result list
$maxItems = isset($config['maxItemsInResultList']) ? $config['maxItemsInResultList'] : 10;
$maxItems = $config['maxItemsInResultList'] ?? 10;
$maxItems = min(count($resultRows), $maxItems);
array_splice($resultRows, $maxItems);
......
......@@ -64,7 +64,7 @@ class FlexFormElementContainer extends AbstractContainer
$options = $this->data;
$options['flexFormDataStructureArray'] = $flexFormFieldArray;
$options['flexFormRowData'] = isset($flexFormRowData[$flexFormFieldName]['el']) ? $flexFormRowData[$flexFormFieldName]['el'] : [];
$options['flexFormRowData'] = $flexFormRowData[$flexFormFieldName]['el'] ?? [];
$options['flexFormFieldName'] = $flexFormFieldName;
$options['renderType'] = 'flexFormSectionContainer';
$sectionContainerResult = $this->nodeFactory->create($options)->render();
......
......@@ -243,7 +243,7 @@ abstract class AbstractFormElement extends AbstractNode
case 'int':
$baseArr = ['dec' => 'd', 'hex' => 'x', 'HEX' => 'X', 'oct' => 'o', 'bin' => 'b'];
$base = isset($formatOptions['base']) ? trim($formatOptions['base']) : '';
$format = isset($baseArr[$base]) ? $baseArr[$base] : 'd';
$format = $baseArr[$base] ?? 'd';
$itemValue = sprintf('%' . $format, $itemValue);
break;
case 'float':
......
......@@ -34,9 +34,7 @@ class UserElement extends AbstractFormElement
$parameterArray['table'] = $this->data['tableName'];
$parameterArray['field'] = $this->data['fieldName'];
$parameterArray['row'] = $this->data['databaseRow'];
$parameterArray['parameters'] = isset($parameterArray['fieldConf']['config']['parameters'])
? $parameterArray['fieldConf']['config']['parameters']
: [];
$parameterArray['parameters'] = $parameterArray['fieldConf']['config']['parameters'] ?? [];
$html = GeneralUtility::callUserFunction(
$parameterArray['fieldConf']['config']['userFunc'],
$parameterArray,
......
......@@ -1067,7 +1067,7 @@ abstract class AbstractItemProvider
$whereClauseSubParts = explode('###', $value, 2);
// @todo: Throw exception if there is no value? What happens for NEW records?
$databaseRowKey = empty($result['flexParentDatabaseRow']) ? 'databaseRow' : 'flexParentDatabaseRow';
$rowFieldValue = isset($result[$databaseRowKey][$whereClauseSubParts[0]]) ? $result[$databaseRowKey][$whereClauseSubParts[0]] : '';
$rowFieldValue = $result[$databaseRowKey][$whereClauseSubParts[0]] ?? '';
if (is_array($rowFieldValue)) {
// If a select or group field is used here, it may have been processed already and
// is now an array. Use first selected value in this case.
......
......@@ -50,9 +50,7 @@ class TcaRecordTitle implements FormDataProviderInterface
'row' => $result['databaseRow'],
'title' => '',
'isOnSymmetricSide' => $result['isOnSymmetricSide'],
'options' => isset($result['processedTca']['ctrl']['formattedLabel_userFunc_options'])
? $result['processedTca']['ctrl']['formattedLabel_userFunc_options']
: [],
'options' => $result['processedTca']['ctrl']['formattedLabel_userFunc_options'] ?? [],
'parent' => [
'uid' => $result['databaseRow']['uid'],
'config' => $result['inlineParentConfig']
......@@ -76,9 +74,7 @@ class TcaRecordTitle implements FormDataProviderInterface
'table' => $result['tableName'],
'row' => $result['databaseRow'],
'title' => '',
'options' => isset($result['processedTca']['ctrl']['label_userFunc_options'])
? $result['processedTca']['ctrl']['label_userFunc_options']
: [],
'options' => $result['processedTca']['ctrl']['label_userFunc_options'] ?? [],
];
$null = null;
GeneralUtility::callUserFunction($result['processedTca']['ctrl']['label_userFunc'], $parameters, $null);
......
......@@ -144,7 +144,7 @@ class NodeFactory
}
$type = $data['renderType'];
$className = isset($this->nodeTypes[$type]) ? $this->nodeTypes[$type] : $this->nodeTypes['unknown'];
$className = $this->nodeTypes[$type] ?? $this->nodeTypes['unknown'];
if (!empty($this->nodeResolver[$type])) {
// Resolver with highest priority is called first. If it returns with a new class name,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment