From 85d0df50edd202e5b8adce556e02cf4e4bed07a7 Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Thu, 16 Dec 2021 17:55:44 +0100 Subject: [PATCH] [TASK] Modernize ViewHelper classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch makes the bulk of ViewHelper classes more strict and applies some general love. Some ViewHelpers have been left, those will see bigger refactorings soon. All affected classes are final, the changes are (hopefully) non-breaking. * declare(strict_types=1) if missing. * Use self:: instead of static:: since all VH's are final, so there is not point in using late static binding. * Return and argument type hints where possible and reduction of methods doc annotations which are covered by PHP method signatures. * Add types to some class properties. * Protect some detail methods that were apparently public by accident. This is not considered breaking. * Avoid extbase LocalizationUtility::translate() in favor of core LanguageService. * Avoid static class state, especially with TSFE. * Minor comment fixes. Change-Id: I4e3b9d01ea92802e47d05a10f4243196120b8510 Resolves: #96400 Related: #96368 Releases: main Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72741 Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Classes/ViewHelpers/IsArrayViewHelper.php | 15 +-- .../ViewHelpers/SubModuleRenderViewHelper.php | 18 +--- .../ViewHelpers/ArrayBrowserViewHelper.php | 17 +-- .../Classes/ViewHelpers/AvatarViewHelper.php | 14 +-- .../ViewHelpers/LanguageColumnViewHelper.php | 2 +- .../ViewHelpers/Link/EditRecordViewHelper.php | 7 +- .../ViewHelpers/Link/NewRecordViewHelper.php | 9 +- .../ViewHelpers/Mfa/IfHasStateViewHelper.php | 1 - .../ViewHelpers/ModuleLinkViewHelper.php | 11 +- .../ViewHelpers/ThumbnailViewHelper.php | 11 +- .../ViewHelpers/Uri/EditRecordViewHelper.php | 11 +- .../ViewHelpers/Uri/NewRecordViewHelper.php | 13 +-- .../ViewHelpers/Be/PagePathViewHelper.php | 23 ++-- .../ViewHelpers/FormatDetailsViewHelper.php | 24 ++--- .../ViewHelpers/UsernameViewHelper.php | 24 ++--- .../ViewHelpers/WorkspaceTitleViewHelper.php | 50 ++++----- .../ViewHelpers/ArrayElementViewHelper.php | 16 ++- .../Display/TableAccessViewHelper.php | 5 +- .../ViewHelpers/PermissionsViewHelper.php | 44 ++++---- .../SpriteIconForRecordViewHelper.php | 27 ++--- .../ViewHelpers/SwitchUserViewHelper.php | 27 +++-- .../Form/TypoScriptConstantsViewHelper.php | 62 ++--------- .../ViewHelpers/IconForRecordViewHelper.php | 18 +--- .../ViewHelpers/IconForResourceViewHelper.php | 13 +-- .../Classes/ViewHelpers/IconViewHelper.php | 18 ++-- .../ViewHelpers/NormalizedUrlViewHelper.php | 20 ++-- .../ViewHelpers/Be/TriggerViewHelper.php | 11 +- .../ViewHelpers/ConstraintsViewHelper.php | 11 +- .../DownloadExtensionViewHelper.php | 100 ++++++------------ .../InstallationStateCssClassViewHelper.php | 19 ++-- .../ProcessAvailableActionsViewHelper.php | 23 ++-- .../ViewHelpers/ReloadSqlDataViewHelper.php | 26 +++-- .../ViewHelpers/RemoveExtensionViewHelper.php | 26 +++-- ...leExtensionInstallationStateViewHelper.php | 28 ++--- .../ViewHelpers/Typo3DependencyViewHelper.php | 18 +--- .../Partials/List/TerShowVersionsTable.html | 2 +- .../Private/Partials/List/TerTable.html | 2 +- .../ViewHelpers/Asset/CssViewHelper.php | 13 +-- .../ViewHelpers/Asset/ScriptViewHelper.php | 13 +-- .../ViewHelpers/Be/InfoboxViewHelper.php | 18 +--- .../Classes/ViewHelpers/Be/LinkViewHelper.php | 20 +--- .../Menus/ActionMenuItemGroupViewHelper.php | 28 ++--- .../ViewHelpers/Be/PageInfoViewHelper.php | 27 ++--- .../ViewHelpers/Be/PagePathViewHelper.php | 36 ++----- .../Be/Security/IfAuthenticatedViewHelper.php | 5 +- .../Be/Security/IfHasRoleViewHelper.php | 10 +- .../ViewHelpers/Be/TableListViewHelper.php | 54 ++++------ .../Classes/ViewHelpers/Be/UriViewHelper.php | 17 +-- .../Classes/ViewHelpers/CObjectViewHelper.php | 48 +++------ .../ViewHelpers/Debug/RenderViewHelper.php | 27 ++--- .../Classes/ViewHelpers/DebugViewHelper.php | 28 ++--- .../ViewHelpers/Form/ButtonViewHelper.php | 16 +-- .../ViewHelpers/Form/CheckboxViewHelper.php | 15 +-- .../ViewHelpers/Form/HiddenViewHelper.php | 16 +-- .../ViewHelpers/Form/PasswordViewHelper.php | 14 +-- .../ViewHelpers/Form/RadioViewHelper.php | 14 +-- .../Form/Select/OptgroupViewHelper.php | 12 +-- .../Form/Select/OptionViewHelper.php | 16 +-- .../ViewHelpers/Form/SelectViewHelper.php | 51 ++++----- .../ViewHelpers/Form/SubmitViewHelper.php | 14 +-- .../ViewHelpers/Form/TextareaViewHelper.php | 16 +-- .../ViewHelpers/Form/TextfieldViewHelper.php | 20 ++-- .../ViewHelpers/Form/UploadViewHelper.php | 14 +-- .../Form/ValidationResultsViewHelper.php | 12 +-- .../Format/AbstractEncodingViewHelper.php | 8 +- .../ViewHelpers/Format/CaseViewHelper.php | 18 ++-- .../ViewHelpers/Format/CropViewHelper.php | 20 +--- .../ViewHelpers/Format/CurrencyViewHelper.php | 20 +--- .../ViewHelpers/Format/DateViewHelper.php | 14 +-- .../ViewHelpers/Format/HtmlViewHelper.php | 45 +++----- .../Format/HtmlentitiesDecodeViewHelper.php | 14 +-- .../Format/HtmlentitiesViewHelper.php | 10 +- .../ViewHelpers/Format/JsonViewHelper.php | 16 +-- .../ViewHelpers/Format/Nl2brViewHelper.php | 21 +--- .../ViewHelpers/Format/NumberViewHelper.php | 23 ++-- .../ViewHelpers/Format/PaddingViewHelper.php | 20 ++-- .../Format/StripTagsViewHelper.php | 28 ++--- .../Format/UrlencodeViewHelper.php | 16 +-- .../Classes/ViewHelpers/ImageViewHelper.php | 19 ++-- .../ViewHelpers/Link/EmailViewHelper.php | 12 +-- .../ViewHelpers/Link/ExternalViewHelper.php | 12 +-- .../ViewHelpers/Link/TypolinkViewHelper.php | 30 ++---- .../Classes/ViewHelpers/MediaViewHelper.php | 28 +++-- .../Classes/ViewHelpers/RenderViewHelper.php | 4 +- .../ViewHelpers/Sanitize/HtmlViewHelper.php | 23 ++-- .../Security/IfAuthenticatedViewHelper.php | 10 +- .../Security/IfHasRoleViewHelper.php | 13 +-- .../ViewHelpers/Transform/HtmlViewHelper.php | 25 +---- .../ViewHelpers/Uri/ExternalViewHelper.php | 19 +--- .../ViewHelpers/Uri/ImageViewHelper.php | 20 +--- .../ViewHelpers/Uri/TypolinkViewHelper.php | 25 ++--- .../Link/ClickEnlargeViewHelper.php | 30 ++---- .../Be/MaximumFileSizeViewHelper.php | 9 +- .../RenderContentElementPreviewViewHelper.php | 16 +-- .../ViewHelpers/Form/DatePickerViewHelper.php | 28 +---- .../ViewHelpers/Form/TimePickerViewHelper.php | 37 +------ .../Form/UploadedResourceViewHelper.php | 35 +----- .../Classes/ViewHelpers/FormViewHelper.php | 12 +-- ...ColumnClassAutoConfigurationViewHelper.php | 20 +--- .../RenderAllFormValuesViewHelper.php | 14 +-- .../ViewHelpers/RenderFormValueViewHelper.php | 50 +++------ .../RenderRenderableViewHelper.php | 17 +-- .../Classes/ViewHelpers/RenderViewHelper.php | 19 +--- .../TranslateElementErrorViewHelper.php | 17 +-- .../TranslateElementPropertyViewHelper.php | 12 +-- .../ViewHelpers/Format/DateTimeViewHelper.php | 15 +-- .../Format/FlagValueViewHelper.php | 16 +-- .../Format/GroupListViewHelper.php | 18 +--- .../PageBrowsingResultsViewHelper.php | 18 ++-- .../ViewHelpers/PageBrowsingViewHelper.php | 19 ++-- .../ViewHelpers/Format/NoSpaceViewHelper.php | 11 +- .../Format/PhpErrorCodeViewHelper.php | 22 ++-- .../Classes/ViewHelpers/PhpInfoViewHelper.php | 44 +++----- .../ViewHelpers/Uri/ActionViewHelper.php | 16 +-- .../ViewHelpers/TargetPageIdViewHelper.php | 6 +- 115 files changed, 707 insertions(+), 1647 deletions(-) diff --git a/typo3/sysext/adminpanel/Classes/ViewHelpers/IsArrayViewHelper.php b/typo3/sysext/adminpanel/Classes/ViewHelpers/IsArrayViewHelper.php index cd857bcef591..fc9705acaf43 100644 --- a/typo3/sysext/adminpanel/Classes/ViewHelpers/IsArrayViewHelper.php +++ b/typo3/sysext/adminpanel/Classes/ViewHelpers/IsArrayViewHelper.php @@ -27,22 +27,13 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; */ final class IsArrayViewHelper extends AbstractViewHelper { - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('value', 'mixed', 'The variable being checked', true); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return bool - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ): bool { + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): bool + { return is_array($arguments['value']); } } diff --git a/typo3/sysext/adminpanel/Classes/ViewHelpers/SubModuleRenderViewHelper.php b/typo3/sysext/adminpanel/Classes/ViewHelpers/SubModuleRenderViewHelper.php index 57b725ed2c69..fc10839de1ef 100644 --- a/typo3/sysext/adminpanel/Classes/ViewHelpers/SubModuleRenderViewHelper.php +++ b/typo3/sysext/adminpanel/Classes/ViewHelpers/SubModuleRenderViewHelper.php @@ -33,9 +33,6 @@ final class SubModuleRenderViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initializes the arguments - */ public function initializeArguments(): void { $this->registerArgument( @@ -49,19 +46,12 @@ final class SubModuleRenderViewHelper extends AbstractViewHelper /** * Resolve user name from backend user id. - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string Username or an empty string if there is no user with that UID */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ): string { + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string + { + /** @var ContentProviderInterface $module */ $module = $arguments['module']; - /** @var \TYPO3\CMS\Adminpanel\ModuleApi\ModuleDataStorageCollection $data */ + /** @var ModuleDataStorageCollection $data */ $data = $arguments['data']; $moduleData = $data->contains($module) ? $data->offsetGet($module) : new ModuleData(); return $module->getContent($moduleData); diff --git a/typo3/sysext/backend/Classes/ViewHelpers/ArrayBrowserViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/ArrayBrowserViewHelper.php index 7d83c10bc7f4..7af8d1bae8c7 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/ArrayBrowserViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/ArrayBrowserViewHelper.php @@ -25,6 +25,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** * Renders a given array as tree + * * @internal */ final class ArrayBrowserViewHelper extends AbstractViewHelper @@ -38,29 +39,19 @@ final class ArrayBrowserViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { - $this->registerArgument('data', 'array', 'Array which should be rendered'); + $this->registerArgument('data', 'array', 'Array which should be rendered', false, []); } /** * Render unordered list for pages - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class); $arrayBrowser->dontLinkVar = true; $arrayBrowser->expAll = true; - return $arrayBrowser->tree($arguments['data'], ''); } } diff --git a/typo3/sysext/backend/Classes/ViewHelpers/AvatarViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/AvatarViewHelper.php index f6a3cdd5cd59..749ac5172e2b 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/AvatarViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/AvatarViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -71,10 +73,7 @@ final class AvatarViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('backendUser', 'int', 'uid of the backend user', false, 0); $this->registerArgument('size', 'int', 'width and height of the image', false, 32); @@ -83,13 +82,8 @@ final class AvatarViewHelper extends AbstractViewHelper /** * Resolve user avatar from a given backend user id. - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { if ($arguments['backendUser'] > 0) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users'); diff --git a/typo3/sysext/backend/Classes/ViewHelpers/LanguageColumnViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/LanguageColumnViewHelper.php index b38f0c6eaca6..480e436af994 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/LanguageColumnViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/LanguageColumnViewHelper.php @@ -23,7 +23,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; final class LanguageColumnViewHelper extends AbstractViewHelper { - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('languageColumn', LanguageColumn::class, 'Language column object which is context for column', true); $this->registerArgument('columnNumber', 'int', 'Number (colPos) of column within LanguageColumn to be returned', true); diff --git a/typo3/sysext/backend/Classes/ViewHelpers/Link/EditRecordViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/Link/EditRecordViewHelper.php index 2a8a1a58c87f..466a24d59feb 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/Link/EditRecordViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/Link/EditRecordViewHelper.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Backend\ViewHelpers\Link; +use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; @@ -64,7 +65,7 @@ final class EditRecordViewHelper extends AbstractTagBasedViewHelper */ protected $tagName = 'a'; - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerUniversalTagAttributes(); @@ -75,8 +76,8 @@ final class EditRecordViewHelper extends AbstractTagBasedViewHelper } /** - * @return string - * @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException + * @throws \InvalidArgumentException + * @throws RouteNotFoundException */ public function render(): string { diff --git a/typo3/sysext/backend/Classes/ViewHelpers/Link/NewRecordViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/Link/NewRecordViewHelper.php index 5325c4203432..b39f30f64ea9 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/Link/NewRecordViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/Link/NewRecordViewHelper.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Backend\ViewHelpers\Link; +use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; @@ -100,7 +101,7 @@ final class NewRecordViewHelper extends AbstractTagBasedViewHelper */ protected $tagName = 'a'; - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerUniversalTagAttributes(); @@ -112,8 +113,8 @@ final class NewRecordViewHelper extends AbstractTagBasedViewHelper } /** - * @return string - * @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException + * @throws \InvalidArgumentException + * @throws RouteNotFoundException */ public function render(): string { @@ -133,7 +134,7 @@ final class NewRecordViewHelper extends AbstractTagBasedViewHelper 'returnUrl' => $this->arguments['returnUrl'], ]; - if (is_array($this->arguments['defaultValues']) && $this->arguments['defaultValues'] !== []) { + if ($this->arguments['defaultValues']) { $params['defVals'] = $this->arguments['defaultValues']; } diff --git a/typo3/sysext/backend/Classes/ViewHelpers/Mfa/IfHasStateViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/Mfa/IfHasStateViewHelper.php index 1def15e173b0..86366d6ec05d 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/Mfa/IfHasStateViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/Mfa/IfHasStateViewHelper.php @@ -40,7 +40,6 @@ final class IfHasStateViewHelper extends AbstractConditionViewHelper { $stateMethod = 'is' . ucfirst($arguments['state']); $provider = $arguments['provider']; - $propertyManager = MfaProviderPropertyManager::create($provider, $GLOBALS['BE_USER']); return is_callable([$provider, $stateMethod]) && $provider->{$stateMethod}($propertyManager); } diff --git a/typo3/sysext/backend/Classes/ViewHelpers/ModuleLinkViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/ModuleLinkViewHelper.php index 6e0c1aad921f..67e6db828f3a 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/ModuleLinkViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/ModuleLinkViewHelper.php @@ -46,10 +46,7 @@ final class ModuleLinkViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('route', 'string', 'The route to link to', true); $this->registerArgument('arguments', 'array', 'Additional link arguments', false, []); @@ -59,11 +56,6 @@ final class ModuleLinkViewHelper extends AbstractViewHelper /** * Render module link with arguments - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { @@ -75,7 +67,6 @@ final class ModuleLinkViewHelper extends AbstractViewHelper if ($arguments['currentUrlParameterName'] !== null) { $parameters[$arguments['currentUrlParameterName']] = $renderingContext->getRequest()->getAttribute('normalizedParams')->getRequestUri(); } - return (string)$uriBuilder->buildUriFromRoute($arguments['route'], $parameters); } } diff --git a/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php index 272d5b2a3b8f..3a1a89fffc54 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -74,10 +76,7 @@ final class ThumbnailViewHelper extends AbstractTagBasedViewHelper $this->imageService = GeneralUtility::makeInstance(ImageService::class); } - /** - * Initialize arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerUniversalTagAttributes(); @@ -107,9 +106,9 @@ final class ThumbnailViewHelper extends AbstractTagBasedViewHelper } /** - * @return string Rendered tag + * @throws Exception */ - public function render() + public function render(): string { if (($this->arguments['src'] === '' && $this->arguments['image'] === null) || ($this->arguments['src'] !== '' && $this->arguments['image'] !== null)) { throw new Exception('You must either specify a string src or a File object.', 1533290762); diff --git a/typo3/sysext/backend/Classes/ViewHelpers/Uri/EditRecordViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/Uri/EditRecordViewHelper.php index c8e44cec5f13..5eb754d1de1b 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/Uri/EditRecordViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/Uri/EditRecordViewHelper.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Backend\ViewHelpers\Uri; +use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; @@ -50,7 +51,7 @@ final class EditRecordViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('uid', 'int', 'uid of record to be edited, 0 for creation', true); $this->registerArgument('table', 'string', 'target database table', true); @@ -59,12 +60,8 @@ final class EditRecordViewHelper extends AbstractViewHelper } /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - * @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException + * @throws \InvalidArgumentException + * @throws RouteNotFoundException */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { diff --git a/typo3/sysext/backend/Classes/ViewHelpers/Uri/NewRecordViewHelper.php b/typo3/sysext/backend/Classes/ViewHelpers/Uri/NewRecordViewHelper.php index 0197bf685402..27dcda999f4d 100644 --- a/typo3/sysext/backend/Classes/ViewHelpers/Uri/NewRecordViewHelper.php +++ b/typo3/sysext/backend/Classes/ViewHelpers/Uri/NewRecordViewHelper.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Backend\ViewHelpers\Uri; +use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; @@ -73,7 +74,7 @@ final class NewRecordViewHelper extends AbstractTagBasedViewHelper { use CompileWithRenderStatic; - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('uid', 'int', 'uid < 0 will insert the record after the given uid', false); $this->registerArgument('pid', 'int', 'the page id where the record will be created', false); @@ -83,12 +84,8 @@ final class NewRecordViewHelper extends AbstractTagBasedViewHelper } /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - * @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException + * @throws \InvalidArgumentException + * @throws RouteNotFoundException */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { @@ -108,7 +105,7 @@ final class NewRecordViewHelper extends AbstractTagBasedViewHelper 'returnUrl' => $arguments['returnUrl'], ]; - if (is_array($arguments['defaultValues']) && $arguments['defaultValues'] !== []) { + if ($arguments['defaultValues']) { $params['defVals'] = $arguments['defaultValues']; } diff --git a/typo3/sysext/belog/Classes/ViewHelpers/Be/PagePathViewHelper.php b/typo3/sysext/belog/Classes/ViewHelpers/Be/PagePathViewHelper.php index 7c02562ce194..f4f9d53c013a 100644 --- a/typo3/sysext/belog/Classes/ViewHelpers/Be/PagePathViewHelper.php +++ b/typo3/sysext/belog/Classes/ViewHelpers/Be/PagePathViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -21,14 +23,12 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; /** * Get page path string from page id + * * @internal */ final class PagePathViewHelper extends AbstractBackendViewHelper { - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('pid', 'int', 'Pid of the page', true); @@ -37,26 +37,17 @@ final class PagePathViewHelper extends AbstractBackendViewHelper /** * Resolve page id to page path string (with automatic cropping to maximum given length). - * - * @return string Page path string */ - public function render() + public function render(): string { - return static::renderStatic( + return self::renderStatic( $this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext ); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { return BackendUtility::getRecordPath($arguments['pid'], '', $arguments['titleLimit']); } diff --git a/typo3/sysext/belog/Classes/ViewHelpers/FormatDetailsViewHelper.php b/typo3/sysext/belog/Classes/ViewHelpers/FormatDetailsViewHelper.php index 28bfa4c6fbbb..3a8322518fc3 100644 --- a/typo3/sysext/belog/Classes/ViewHelpers/FormatDetailsViewHelper.php +++ b/typo3/sysext/belog/Classes/ViewHelpers/FormatDetailsViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -23,16 +25,14 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** * Create detail string from log entry + * * @internal */ final class FormatDetailsViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('logEntry', LogEntry::class, '', true); } @@ -45,14 +45,8 @@ final class FormatDetailsViewHelper extends AbstractViewHelper * with the substitutions. * Furthermore, possible files in logData are stripped to their basename if * the action logged was a file action - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string Formatted details */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { /** @var LogEntry $logEntry */ $logEntry = $arguments['logEntry']; @@ -67,17 +61,13 @@ final class FormatDetailsViewHelper extends AbstractViewHelper $detailString = vsprintf($detailString, $substitutes); } // Remove possible pending other %s - $detailString = str_replace('%s', '', $detailString); - return $detailString; + return str_replace('%s', '', $detailString); } /** * Strips path from array of file names - * - * @param array $files - * @return array */ - protected static function stripPathFromFilenames(array $files = []) + protected static function stripPathFromFilenames(array $files = []): array { foreach ($files as $key => $file) { $files[$key] = PathUtility::basename($file); diff --git a/typo3/sysext/belog/Classes/ViewHelpers/UsernameViewHelper.php b/typo3/sysext/belog/Classes/ViewHelpers/UsernameViewHelper.php index c0b7e50b8a7a..971c89585a45 100644 --- a/typo3/sysext/belog/Classes/ViewHelpers/UsernameViewHelper.php +++ b/typo3/sysext/belog/Classes/ViewHelpers/UsernameViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -22,6 +24,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** * Get username from backend user id + * * @internal */ final class UsernameViewHelper extends AbstractViewHelper @@ -38,29 +41,22 @@ final class UsernameViewHelper extends AbstractViewHelper /** * Initializes the arguments */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('uid', 'int', 'Uid of the user', true); } /** - * Resolve user name from backend user id. - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string Username or an empty string if there is no user with that UID + * Resolve user name from backend user id. Can return empty string if there is no user with that UID. */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $uid = $arguments['uid']; - if (isset(static::$usernameRuntimeCache[$uid])) { - return static::$usernameRuntimeCache[$uid]; + if (isset(self::$usernameRuntimeCache[$uid])) { + return self::$usernameRuntimeCache[$uid]; } - $user = BackendUtility::getRecord('be_users', $uid); - static::$usernameRuntimeCache[$uid] = $user['username'] ?? ''; - return static::$usernameRuntimeCache[$uid]; + self::$usernameRuntimeCache[$uid] = $user['username'] ?? ''; + return self::$usernameRuntimeCache[$uid]; } } diff --git a/typo3/sysext/belog/Classes/ViewHelpers/WorkspaceTitleViewHelper.php b/typo3/sysext/belog/Classes/ViewHelpers/WorkspaceTitleViewHelper.php index f4756ebae25b..eaf29d26c95f 100644 --- a/typo3/sysext/belog/Classes/ViewHelpers/WorkspaceTitleViewHelper.php +++ b/typo3/sysext/belog/Classes/ViewHelpers/WorkspaceTitleViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -16,15 +18,15 @@ namespace TYPO3\CMS\Belog\ViewHelpers; use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; -use TYPO3\CMS\Extbase\Utility\LocalizationUtility; -use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** * Get workspace title from workspace id + * * @internal */ final class WorkspaceTitleViewHelper extends AbstractViewHelper @@ -33,52 +35,40 @@ final class WorkspaceTitleViewHelper extends AbstractViewHelper /** * First level cache of workspace titles - * - * @var array */ - protected static $workspaceTitleRuntimeCache = []; + protected static array $workspaceTitleRuntimeCache = []; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('uid', 'int', 'UID of the workspace', true); } /** - * Resolve workspace title from UID. - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext + * Return resolved workspace title or empty string if it can not be resolved. * - * @return string workspace title or UID * @throws \InvalidArgumentException */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { - if (!$renderingContext instanceof RenderingContext) { - throw new \InvalidArgumentException('The given rendering context is not of type "TYPO3\CMS\Fluid\Core\Rendering\RenderingContext"', 1468363946); - } - $uid = $arguments['uid']; - if (isset(static::$workspaceTitleRuntimeCache[$uid])) { - return static::$workspaceTitleRuntimeCache[$uid]; + if (isset(self::$workspaceTitleRuntimeCache[$uid])) { + return self::$workspaceTitleRuntimeCache[$uid]; } - if ($uid === 0) { - static::$workspaceTitleRuntimeCache[$uid] = LocalizationUtility::translate( - 'live', - $renderingContext->getRequest()->getControllerExtensionName() - ); + self::$workspaceTitleRuntimeCache[$uid] = htmlspecialchars(self::getLanguageService()->sL( + 'LLL:EXT:belog/Resources/Private/Language/locallang.xlf:live' + )); } elseif (!ExtensionManagementUtility::isLoaded('workspaces')) { - static::$workspaceTitleRuntimeCache[$uid] = ''; + self::$workspaceTitleRuntimeCache[$uid] = ''; } else { $workspace = BackendUtility::getRecord('sys_workspace', $uid); - static::$workspaceTitleRuntimeCache[$uid] = $workspace['title'] ?? ''; + self::$workspaceTitleRuntimeCache[$uid] = $workspace['title'] ?? ''; } + return self::$workspaceTitleRuntimeCache[$uid]; + } - return static::$workspaceTitleRuntimeCache[$uid]; + protected static function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; } } diff --git a/typo3/sysext/beuser/Classes/ViewHelpers/ArrayElementViewHelper.php b/typo3/sysext/beuser/Classes/ViewHelpers/ArrayElementViewHelper.php index 9de7420eab2a..7b3864d52a15 100644 --- a/typo3/sysext/beuser/Classes/ViewHelpers/ArrayElementViewHelper.php +++ b/typo3/sysext/beuser/Classes/ViewHelpers/ArrayElementViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -22,16 +24,14 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** * Get a value from an array by given key. + * * @internal */ final class ArrayElementViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('array', 'array', 'Array to search in', true); $this->registerArgument('key', 'string', 'Key to return its value', true); @@ -41,19 +41,15 @@ final class ArrayElementViewHelper extends AbstractViewHelper /** * Return array element by key. Accessed values must be scalar (string, int, float or double) * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext * @throws Exception - * @return string */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $array = $arguments['array']; $key = $arguments['key']; $subKey = $arguments['subKey']; $result = ''; - if (is_array($array) && isset($array[$key])) { + if (isset($array[$key])) { $result = $array[$key]; if (is_array($result) && $subKey && isset($result[$subKey])) { $result = $result[$subKey]; diff --git a/typo3/sysext/beuser/Classes/ViewHelpers/Display/TableAccessViewHelper.php b/typo3/sysext/beuser/Classes/ViewHelpers/Display/TableAccessViewHelper.php index c88c0477ac4e..979241a7ff63 100644 --- a/typo3/sysext/beuser/Classes/ViewHelpers/Display/TableAccessViewHelper.php +++ b/typo3/sysext/beuser/Classes/ViewHelpers/Display/TableAccessViewHelper.php @@ -20,6 +20,9 @@ namespace TYPO3\CMS\Beuser\ViewHelpers\Display; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper; +/** + * @internal + */ final class TableAccessViewHelper extends AbstractConditionViewHelper { public function initializeArguments(): void @@ -30,7 +33,7 @@ final class TableAccessViewHelper extends AbstractConditionViewHelper $this->registerArgument('modify', 'array', 'List of allowed tables to modify', false, []); } - public static function verdict(array $arguments, RenderingContextInterface $renderingContext) + public static function verdict(array $arguments, RenderingContextInterface $renderingContext): bool { $table = $arguments['table']; return array_key_exists($table, (array)$arguments['select']) || array_key_exists($table, (array)$arguments['modify']); diff --git a/typo3/sysext/beuser/Classes/ViewHelpers/PermissionsViewHelper.php b/typo3/sysext/beuser/Classes/ViewHelpers/PermissionsViewHelper.php index 090f5e40a584..ec20c780d180 100644 --- a/typo3/sysext/beuser/Classes/ViewHelpers/PermissionsViewHelper.php +++ b/typo3/sysext/beuser/Classes/ViewHelpers/PermissionsViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -15,7 +17,7 @@ namespace TYPO3\CMS\Beuser\ViewHelpers; -use TYPO3\CMS\Extbase\Utility\LocalizationUtility; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; @@ -25,6 +27,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; * * Most of that could be done in fluid directly, but this ViewHelper * is much better performance wise. + * * @internal */ final class PermissionsViewHelper extends AbstractViewHelper @@ -38,40 +41,24 @@ final class PermissionsViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * @var array Cached labels for a single permission mask like "Delete page" - */ - protected static $permissionLabels = []; + protected static array $cachePermissionLabels = []; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('permission', 'int', 'Current permission', true); $this->registerArgument('scope', 'string', '"user" / "group" / "everybody"', true); $this->registerArgument('pageId', 'int', '', true); } - /** - * Return permissions. - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $masks = [1, 16, 2, 4, 8]; - if (empty(static::$permissionLabels)) { + if (empty(self::$cachePermissionLabels)) { foreach ($masks as $mask) { - static::$permissionLabels[$mask] = LocalizationUtility::translate( + self::$cachePermissionLabels[$mask] = htmlspecialchars(self::getLanguageService()->sL( 'LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $mask, - 'be_user' - ); + )); } } @@ -85,13 +72,13 @@ final class PermissionsViewHelper extends AbstractViewHelper $mode = 'add'; } - $label = static::$permissionLabels[$mask]; + $label = self::$cachePermissionLabels[$mask]; $icon .= '<button' . ' aria-label="' . htmlspecialchars($label) . ', ' . htmlspecialchars($mode) . ', ' . htmlspecialchars($arguments['scope']) . '"' . ' title="' . htmlspecialchars($label) . '"' . ' data-bs-toggle="tooltip"' - . ' data-page="' . htmlspecialchars($arguments['pageId']) . '"' - . ' data-permissions="' . htmlspecialchars($arguments['permission']) . '"' + . ' data-page="' . htmlspecialchars((string)$arguments['pageId']) . '"' + . ' data-permissions="' . htmlspecialchars((string)$arguments['permission']) . '"' . ' data-who="' . htmlspecialchars($arguments['scope']) . '"' . ' data-bits="' . htmlspecialchars((string)$mask) . '"' . ' data-mode="' . htmlspecialchars($mode) . '"' @@ -100,4 +87,9 @@ final class PermissionsViewHelper extends AbstractViewHelper return '<span id="' . htmlspecialchars($arguments['pageId'] . '_' . $arguments['scope']) . '">' . $icon . '</span>'; } + + protected static function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } } diff --git a/typo3/sysext/beuser/Classes/ViewHelpers/SpriteIconForRecordViewHelper.php b/typo3/sysext/beuser/Classes/ViewHelpers/SpriteIconForRecordViewHelper.php index 55cef6b1a4aa..c0ed366b07a9 100644 --- a/typo3/sysext/beuser/Classes/ViewHelpers/SpriteIconForRecordViewHelper.php +++ b/typo3/sysext/beuser/Classes/ViewHelpers/SpriteIconForRecordViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -23,6 +25,7 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; /** * Views sprite icon for a record (object) + * * @internal */ final class SpriteIconForRecordViewHelper extends AbstractBackendViewHelper @@ -34,10 +37,7 @@ final class SpriteIconForRecordViewHelper extends AbstractBackendViewHelper */ protected $escapeOutput = false; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('table', 'string', '', true); @@ -46,29 +46,18 @@ final class SpriteIconForRecordViewHelper extends AbstractBackendViewHelper /** * Displays spriteIcon for database table and object - * - * @return string - * @see IconFactory::getIconForRecord() */ - public function render() + public function render(): string { - return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); + return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - * @throws \Exception - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $object = $arguments['object']; $table = $arguments['table']; - if (!is_object($object) || !method_exists($object, 'getUid')) { + if (!method_exists($object, 'getUid')) { return ''; } $row = [ diff --git a/typo3/sysext/beuser/Classes/ViewHelpers/SwitchUserViewHelper.php b/typo3/sysext/beuser/Classes/ViewHelpers/SwitchUserViewHelper.php index efd0afa4b6ff..279fb7b86e7a 100644 --- a/typo3/sysext/beuser/Classes/ViewHelpers/SwitchUserViewHelper.php +++ b/typo3/sysext/beuser/Classes/ViewHelpers/SwitchUserViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -19,14 +21,15 @@ use TYPO3\CMS\Beuser\Domain\Model\BackendUser; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** - * Displays 'SwitchUser' button to change current backend user to target backend user + * Displays 'SwitchUser' button to change current backend user to target backend user. + * * @internal */ final class SwitchUserViewHelper extends AbstractViewHelper @@ -40,24 +43,15 @@ final class SwitchUserViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true); } /** * Render link with sprite icon to change current backend user to target - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $targetUser = $arguments['backendUser']; $currentUser = self::getBackendUserAuthentication(); @@ -73,7 +67,7 @@ final class SwitchUserViewHelper extends AbstractViewHelper return ' <typo3-backend-switch-user targetUser="' . htmlspecialchars((string)$targetUser->getUid()) . '"> - <button type="button" class="btn btn-default" title="' . htmlspecialchars(LocalizationUtility::translate('switchBackMode', 'beuser') ?? '') . '">' + <button type="button" class="btn btn-default" title="' . htmlspecialchars(self::getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:switchBackMode')) . '">' . $iconFactory->getIcon('actions-system-backend-user-switch', Icon::SIZE_SMALL)->render() . '</button> </typo3-switch-user-button>'; @@ -83,4 +77,9 @@ final class SwitchUserViewHelper extends AbstractViewHelper { return $GLOBALS['BE_USER']; } + + protected static function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } } diff --git a/typo3/sysext/core/Classes/ViewHelpers/Form/TypoScriptConstantsViewHelper.php b/typo3/sysext/core/Classes/ViewHelpers/Form/TypoScriptConstantsViewHelper.php index 89ea8a36356e..f9556412ee55 100644 --- a/typo3/sysext/core/Classes/ViewHelpers/Form/TypoScriptConstantsViewHelper.php +++ b/typo3/sysext/core/Classes/ViewHelpers/Form/TypoScriptConstantsViewHelper.php @@ -32,10 +32,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder; */ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper { - /** - * @var array - */ - public $viewHelperMapping = [ + protected array $viewHelperMapping = [ 'int' => 'renderIntegerField', 'int+' => 'renderPositiveIntegerField', 'integer' => 'renderIntegerField', @@ -56,10 +53,7 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper */ public $tagName = 'input'; - /** - * Initialize arguments of this ViewHelper - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('name', 'string', 'Name of input tag'); @@ -76,17 +70,12 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Create a fresh instance of $this->tag each time this VH is called. */ - public function initialize() + public function initialize(): void { $this->setTagBuilder(new TagBuilder($this->tagName)); parent::initialize(); } - /** - * Render - * - * @return string the rendered tag - */ public function render(): string { /** @var array $configuration */ @@ -96,15 +85,11 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper } else { $input = $this->{$this->viewHelperMapping['default']}($configuration); } - return $input; } /** * Render field of type color picker - * - * @param array $configuration - * @return string */ protected function renderColorPicker(array $configuration): string { @@ -135,9 +120,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render field of type "offset" - * - * @param array $configuration - * @return string */ protected function renderOffsetField(array $configuration): string { @@ -154,9 +136,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render field of type "wrap" - * - * @param array $configuration - * @return string */ protected function renderWrapField(array $configuration): string { @@ -173,9 +152,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render field of type "option" - * - * @param array $configuration - * @return string */ protected function renderOptionSelect(array $configuration): string { @@ -199,9 +175,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render field of type "int+" - * - * @param array $configuration - * @return string */ protected function renderPositiveIntegerField(array $configuration): string { @@ -219,9 +192,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render field of type "integer" - * - * @param array $configuration - * @return string */ protected function renderIntegerField(array $configuration): string { @@ -238,9 +208,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render field of type "text" - * - * @param array $configuration - * @return string */ protected function renderTextField(array $configuration): string { @@ -257,9 +224,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render field of type "small text" - * - * @param array $configuration - * @return string */ protected function renderSmallTextField(array $configuration): string { @@ -268,11 +232,8 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render field of type "checkbox" - * - * @param array $configuration - * @return string */ - public function renderCheckbox(array $configuration): string + protected function renderCheckbox(array $configuration): string { $this->tag->addAttribute('type', 'checkbox'); $this->tag->addAttribute('class', 'form-check-input'); @@ -288,9 +249,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render field of type "userFunc" - * - * @param array $configuration - * @return string */ protected function renderUserFunction(array $configuration): string { @@ -305,9 +263,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Get Field Name - * - * @param array $configuration - * @return string */ protected function getFieldName(array $configuration): string { @@ -316,9 +271,6 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper /** * Render a hidden field for empty values - * - * @param array $configuration - * @return string */ protected function renderHiddenFieldForEmptyValue(array $configuration): string { @@ -342,17 +294,15 @@ final class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper } /** - * @return LanguageService|null Returns null if we are in the install tool standalone mode + * @return LanguageService|null Null if we are in the install tool standalone mode @todo: still valid? */ - protected function getLanguageService() + protected function getLanguageService(): ?LanguageService { return $GLOBALS['LANG']; } /** * Build and add id-attribute from $configuration - * - * @param array $configuration */ protected function addIdAttribute(array $configuration): void { diff --git a/typo3/sysext/core/Classes/ViewHelpers/IconForRecordViewHelper.php b/typo3/sysext/core/Classes/ViewHelpers/IconForRecordViewHelper.php index 8a651df6c2b4..f99b36623512 100644 --- a/typo3/sysext/core/Classes/ViewHelpers/IconForRecordViewHelper.php +++ b/typo3/sysext/core/Classes/ViewHelpers/IconForRecordViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -51,30 +53,20 @@ final class IconForRecordViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('table', 'string', 'the table for the record icon', true); $this->registerArgument('row', 'array', 'the record row', true); $this->registerArgument('size', 'string', 'the icon size', false, Icon::SIZE_SMALL); - $this->registerArgument('alternativeMarkupIdentifier', 'string', 'alternative markup identifier', false, null); + $this->registerArgument('alternativeMarkupIdentifier', 'string', 'alternative markup identifier', false); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $table = $arguments['table']; $size = $arguments['size']; $row = $arguments['row']; $alternativeMarkupIdentifier = $arguments['alternativeMarkupIdentifier']; - /** @var IconFactory $iconFactory */ $iconFactory = GeneralUtility::makeInstance(IconFactory::class); return $iconFactory->getIconForRecord($table, $row, $size)->render($alternativeMarkupIdentifier); } diff --git a/typo3/sysext/core/Classes/ViewHelpers/IconForResourceViewHelper.php b/typo3/sysext/core/Classes/ViewHelpers/IconForResourceViewHelper.php index 79d382e8d5cb..79f0417ddec1 100644 --- a/typo3/sysext/core/Classes/ViewHelpers/IconForResourceViewHelper.php +++ b/typo3/sysext/core/Classes/ViewHelpers/IconForResourceViewHelper.php @@ -54,24 +54,15 @@ final class IconForResourceViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('resource', ResourceInterface::class, 'Resource', true); $this->registerArgument('size', 'string', 'The icon size', false, Icon::SIZE_SMALL); $this->registerArgument('overlay', 'string', 'Overlay identifier', false, null); $this->registerArgument('options', 'array', 'An associative array with additional options', false, []); - $this->registerArgument('alternativeMarkupIdentifier', 'string', 'Alternative markup identifier', false, null); + $this->registerArgument('alternativeMarkupIdentifier', 'string', 'Alternative markup identifier', false); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $resource = $arguments['resource']; diff --git a/typo3/sysext/core/Classes/ViewHelpers/IconViewHelper.php b/typo3/sysext/core/Classes/ViewHelpers/IconViewHelper.php index 619a5c71e245..ea1527ba9baf 100644 --- a/typo3/sysext/core/Classes/ViewHelpers/IconViewHelper.php +++ b/typo3/sysext/core/Classes/ViewHelpers/IconViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -64,27 +66,19 @@ final class IconViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('identifier', 'string', 'Identifier of the icon as registered in the Icon Registry.', true); $this->registerArgument('size', 'string', 'Desired size of the icon. All values of the Icons.sizes enum are allowed, these are: "small", "default", "large" and "overlay".', false, Icon::SIZE_SMALL); - $this->registerArgument('overlay', 'string', 'Identifier of an overlay icon as registered in the Icon Registry.', false, null); + $this->registerArgument('overlay', 'string', 'Identifier of an overlay icon as registered in the Icon Registry.', false); $this->registerArgument('state', 'string', 'Sets the state of the icon. All values of the Icons.states enum are allowed, these are: "default" and "disabled".', false, IconState::STATE_DEFAULT); - $this->registerArgument('alternativeMarkupIdentifier', 'string', 'Alternative icon identifier. Takes precedence over the identifier if supported by the IconProvider.', false, null); + $this->registerArgument('alternativeMarkupIdentifier', 'string', 'Alternative icon identifier. Takes precedence over the identifier if supported by the IconProvider.', false); } /** * Prints icon html for $identifier key - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $identifier = $arguments['identifier']; $size = $arguments['size']; diff --git a/typo3/sysext/core/Classes/ViewHelpers/NormalizedUrlViewHelper.php b/typo3/sysext/core/Classes/ViewHelpers/NormalizedUrlViewHelper.php index 203318150e36..dcdd6aadde2c 100644 --- a/typo3/sysext/core/Classes/ViewHelpers/NormalizedUrlViewHelper.php +++ b/typo3/sysext/core/Classes/ViewHelpers/NormalizedUrlViewHelper.php @@ -44,35 +44,27 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderS * Output:: * * /typo3/sysext/core/Resources/Public/Images/typo3_black.svg + * * @internal */ final class NormalizedUrlViewHelper extends AbstractViewHelper { use CompileWithContentArgumentAndRenderStatic; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('pathOrUrl', 'string', 'Absolute path to file using EXT: syntax or URL.'); } /** - * Ouputs what is given as URL or extension relative path as absolute URL - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string + * Output what is given as URL or extension relative path as absolute URL */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { - $pathOrUrl = $renderChildrenClosure(); + $pathOrUrl = $arguments['pathOrUrl'] ?? $renderChildrenClosure(); if (PathUtility::hasProtocolAndScheme($pathOrUrl)) { return $pathOrUrl; } - - return GeneralUtility::locationHeaderUrl(PathUtility::getPublicResourceWebPath($pathOrUrl)); + return GeneralUtility::locationHeaderUrl(PathUtility::getPublicResourceWebPath((string)$pathOrUrl)); } } diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/Be/TriggerViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/Be/TriggerViewHelper.php index a4fc806e8e35..cdeb65349ac9 100644 --- a/typo3/sysext/extensionmanager/Classes/ViewHelpers/Be/TriggerViewHelper.php +++ b/typo3/sysext/extensionmanager/Classes/ViewHelpers/Be/TriggerViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -40,10 +42,7 @@ final class TriggerViewHelper extends AbstractBackendViewHelper */ protected $escapeOutput = false; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('triggers', 'array', 'Defined triggers to be forwarded to client (e.g. refreshing backend widgets)', false, []); @@ -52,10 +51,8 @@ final class TriggerViewHelper extends AbstractBackendViewHelper /** * Loads some JS inline code based on a list of triggers. This is used to reload the main * menu when modules are loaded/unloaded. - * - * @return string This ViewHelper does not return any content */ - public function render() + public function render(): string { $html = ''; // Handle triggers diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/ConstraintsViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/ConstraintsViewHelper.php index 7bf131320241..a11b15c8d331 100644 --- a/typo3/sysext/extensionmanager/Classes/ViewHelpers/ConstraintsViewHelper.php +++ b/typo3/sysext/extensionmanager/Classes/ViewHelpers/ConstraintsViewHelper.php @@ -35,20 +35,15 @@ final class ConstraintsViewHelper extends AbstractViewHelper $this->registerArgument('extension', Extension::class, 'extension to process', true); } - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ): array { + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): array + { $groupedConstraints = []; - foreach ($arguments['extension']->getDependencies() as $dependency) { $groupedConstraints[$dependency->getType()][self::getTransformedIdentifier($dependency->getIdentifier())] = [ 'version' => self::getVersionString($dependency->getLowestVersion(), $dependency->getHighestVersion()), 'versionCompatible' => self::isVersionCompatible($dependency), ]; } - return $groupedConstraints; } @@ -62,7 +57,6 @@ final class ConstraintsViewHelper extends AbstractViewHelper protected static function getVersionString(string $lowestVersion, string $highestVersion): string { $version = ''; - if ($lowestVersion !== '') { $version .= '(' . $lowestVersion; if ($highestVersion !== '') { @@ -70,7 +64,6 @@ final class ConstraintsViewHelper extends AbstractViewHelper } $version .= ')'; } - return $version; } diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/DownloadExtensionViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/DownloadExtensionViewHelper.php index d6d1e6a086f0..23ee6ac69d81 100644 --- a/typo3/sysext/extensionmanager/Classes/ViewHelpers/DownloadExtensionViewHelper.php +++ b/typo3/sysext/extensionmanager/Classes/ViewHelpers/DownloadExtensionViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -16,15 +18,16 @@ namespace TYPO3\CMS\Extensionmanager\ViewHelpers; use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; use TYPO3\CMS\Extbase\Service\ExtensionService; -use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3\CMS\Extensionmanager\Domain\Model\Extension; use TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper; /** - * ViewHelper + * Render a link to download an extension. + * * @internal */ final class DownloadExtensionViewHelper extends AbstractFormViewHelper @@ -34,40 +37,21 @@ final class DownloadExtensionViewHelper extends AbstractFormViewHelper */ protected $tagName = 'form'; - /** - * @var \TYPO3\CMS\Extbase\Service\ExtensionService - */ - protected $extensionService; + protected ExtensionService $extensionService; - /** - * @param \TYPO3\CMS\Extbase\Service\ExtensionService $extensionService - */ - public function injectExtensionService(ExtensionService $extensionService) + public function injectExtensionService(ExtensionService $extensionService): void { $this->extensionService = $extensionService; } - /** - * Initialize arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('extension', Extension::class, '', true); - $this->registerTagAttribute('enctype', 'string', 'MIME type with which the form is submitted'); - $this->registerTagAttribute('method', 'string', 'Transfer type (GET or POST)'); - $this->registerTagAttribute('name', 'string', 'Name of form'); - $this->registerTagAttribute('onreset', 'string', 'JavaScript: On reset of the form'); - $this->registerTagAttribute('onsubmit', 'string', 'JavaScript: On submit of the form'); $this->registerUniversalTagAttributes(); } - /** - * Renders a download link - * - * @return string the rendered a tag - */ - public function render() + public function render(): string { /** @var Extension $extension */ $extension = $this->arguments['extension']; @@ -79,12 +63,11 @@ final class DownloadExtensionViewHelper extends AbstractFormViewHelper foreach ($installPaths as $installPathType => $installPath) { /** @var string $installPathType */ $pathSelector .= '<li> - <input type="radio" id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '" name="' . htmlspecialchars($this->getFieldNamePrefix()) . '[downloadPath]" class="downloadPath" value="' . htmlspecialchars($installPathType) . '" ' . ($installPathType === 'Local' ? 'checked="checked"' : '') . ' /> - <label for="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '">' . htmlspecialchars($installPathType) . '</label> - </li>'; + <input type="radio" id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '" name="' . htmlspecialchars($this->getDefaultFieldNamePrefix()) . '[downloadPath]" class="downloadPath" value="' . htmlspecialchars($installPathType) . '" ' . ($installPathType === 'Local' ? 'checked="checked"' : '') . ' /> + <label for="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '">' . htmlspecialchars($installPathType) . '</label> + </li>'; } $pathSelector .= '</ul>'; - /** @var UriBuilder $uriBuilder */ $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $uriBuilder->setRequest($this->renderingContext->getRequest()); $action = 'checkDependencies'; @@ -97,57 +80,36 @@ final class DownloadExtensionViewHelper extends AbstractFormViewHelper $automaticInstallation = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation'); $labelKeySuffix = $automaticInstallation ? '' : '.downloadOnly'; + $titleAndValue = $this->getLanguageService()->sL( + 'LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.downloadViewHelper.submit' . $labelKeySuffix + ); $label = ' - <div class="btn-group"> - <button - title="' . LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '" - type="submit" - class="btn btn-default" - value="' . LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '" - > - <span class="t3-icon fa fa-cloud-download"></span> - </button> - </div>'; + <div class="btn-group"> + <button + title="' . htmlspecialchars($titleAndValue) . '" + type="submit" + class="btn btn-default" + value="' . htmlspecialchars($titleAndValue) . '" + > + <span class="t3-icon fa fa-cloud-download"></span> + </button> + </div>'; $this->tag->setContent($label . $pathSelector); - $this->tag->addAttribute('class', 'download'); + $this->tag->addAttribute('class', $this->arguments['class']); return '<div id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadFromTer" class="downloadFromTer">' . $this->tag->render() . '</div>'; } /** - * Get the field name prefix - * - * @return string + * Retrieves the field name prefix for this form */ - protected function getFieldNamePrefix() + protected function getDefaultFieldNamePrefix(): string { - if ($this->hasArgument('fieldNamePrefix')) { - return $this->arguments['fieldNamePrefix']; - } - return $this->getDefaultFieldNamePrefix(); + return $this->extensionService->getPluginNamespace('Extensionmanager', 'tools_ExtensionmanagerExtensionmanager'); } - /** - * Retrieves the default field name prefix for this form - * - * @return string default field name prefix - */ - protected function getDefaultFieldNamePrefix() + protected function getLanguageService(): LanguageService { - $request = $this->renderingContext->getRequest(); - if ($this->hasArgument('extensionName')) { - $extensionName = $this->arguments['extensionName']; - } else { - $extensionName = $request->getControllerExtensionName(); - } - if ($this->hasArgument('pluginName')) { - $pluginName = $this->arguments['pluginName']; - } else { - $pluginName = $request->getPluginName(); - } - if ($extensionName !== null && $pluginName != null) { - return $this->extensionService->getPluginNamespace($extensionName, $pluginName); - } - return ''; + return $GLOBALS['LANG']; } } diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/InstallationStateCssClassViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/InstallationStateCssClassViewHelper.php index e19bbf0184ed..762c5c582e1d 100644 --- a/typo3/sysext/extensionmanager/Classes/ViewHelpers/InstallationStateCssClassViewHelper.php +++ b/typo3/sysext/extensionmanager/Classes/ViewHelpers/InstallationStateCssClassViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -20,18 +22,15 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** - * Returns a string meant to be used as css class stating whether an extension is - * available or installed + * Returns a string meant to be used as css class stating whether an extension is available or installed. + * * @internal */ final class InstallationStateCssClassViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('needle', 'string', '', true); $this->registerArgument('haystack', 'array', '', true); @@ -42,14 +41,8 @@ final class InstallationStateCssClassViewHelper extends AbstractViewHelper * 'installed' => if an extension is installed * 'available' => if an extension is available in the system * '' (empty string) => if neither installed nor available - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string the rendered a tag */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $needle = $arguments['needle']; $haystack = $arguments['haystack']; diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/ProcessAvailableActionsViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/ProcessAvailableActionsViewHelper.php index 8f157adf68bf..abe37df6fa42 100644 --- a/typo3/sysext/extensionmanager/Classes/ViewHelpers/ProcessAvailableActionsViewHelper.php +++ b/typo3/sysext/extensionmanager/Classes/ViewHelpers/ProcessAvailableActionsViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -20,39 +22,30 @@ use TYPO3\CMS\Extensionmanager\Event\AvailableActionsForExtensionEvent; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; /** - * ViewHelper to let 3rd-party extensions process the list of available - * actions for a given extension. + * ViewHelper to let 3rd-party extensions process the list of available actions for a given extension. + * * @internal */ final class ProcessAvailableActionsViewHelper extends AbstractTagBasedViewHelper { - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; + protected EventDispatcherInterface $eventDispatcher; - public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher) + public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher): void { $this->eventDispatcher = $eventDispatcher; } - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('extension', 'array', '', true); } - /** - * Processes the list of actions. - * - * @return string the rendered list of actions - */ - public function render() + public function render(): string { $html = $this->renderChildren(); $actions = preg_split('#\\n\\s*#s', trim($html)); $actions = is_array($actions) ? $actions : []; - $event = new AvailableActionsForExtensionEvent($this->arguments['extension']['key'], $this->arguments['extension'], $actions); $this->eventDispatcher->dispatch($event); return implode(' ', $event->getActions()); diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/ReloadSqlDataViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/ReloadSqlDataViewHelper.php index 13bf760bdfd6..fbe3f4f00465 100644 --- a/typo3/sysext/extensionmanager/Classes/ViewHelpers/ReloadSqlDataViewHelper.php +++ b/typo3/sysext/extensionmanager/Classes/ViewHelpers/ReloadSqlDataViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -17,15 +19,16 @@ namespace TYPO3\CMS\Extensionmanager\ViewHelpers; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Registry; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\PathUtility; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; -use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; /** - * ViewHelper for update script link + * Renders a link to re-import the static SQL data of an extension. + * * @internal */ final class ReloadSqlDataViewHelper extends AbstractTagBasedViewHelper @@ -44,12 +47,7 @@ final class ReloadSqlDataViewHelper extends AbstractTagBasedViewHelper $this->registerArgument('extension', 'array', 'Extension key', true); } - /** - * Renders a link to re-import the static SQL data of an extension - * - * @return string The rendered a tag - */ - public function render() + public function render(): string { $extension = $this->arguments['extension']; $iconFactory = GeneralUtility::makeInstance(IconFactory::class); @@ -60,7 +58,7 @@ final class ReloadSqlDataViewHelper extends AbstractTagBasedViewHelper } $registry = GeneralUtility::makeInstance(Registry::class); - $oldMd5Hash = $registry->get(static::$registryNamespace, PathUtility::stripPathSitePrefix($staticSqlDataFile)); + $oldMd5Hash = $registry->get(self::$registryNamespace, PathUtility::stripPathSitePrefix($staticSqlDataFile)); $md5HashIsEqual = true; // We used to only store "1" in the database when data was imported @@ -78,7 +76,6 @@ final class ReloadSqlDataViewHelper extends AbstractTagBasedViewHelper $languageKey = 'extensionList.databaseImport'; } - /** @var UriBuilder $uriBuilder */ $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $uriBuilder->setRequest($this->renderingContext->getRequest()); $uriBuilder->reset(); @@ -88,9 +85,16 @@ final class ReloadSqlDataViewHelper extends AbstractTagBasedViewHelper 'Action' ); $this->tag->addAttribute('href', $uri); - $this->tag->addAttribute('title', LocalizationUtility::translate($languageKey, 'extensionmanager')); + $this->tag->addAttribute('title', htmlspecialchars($this->getLanguageService()->sL( + 'LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:' . $languageKey + ))); $this->tag->setContent($iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render()); return $this->tag->render(); } + + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } } diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/RemoveExtensionViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/RemoveExtensionViewHelper.php index d6ce241b3541..9d6bd8550666 100644 --- a/typo3/sysext/extensionmanager/Classes/ViewHelpers/RemoveExtensionViewHelper.php +++ b/typo3/sysext/extensionmanager/Classes/ViewHelpers/RemoveExtensionViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -17,15 +19,16 @@ namespace TYPO3\CMS\Extensionmanager\ViewHelpers; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; -use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3\CMS\Extensionmanager\Domain\Model\Extension; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; /** - * ViewHelper for displaying a remove extension link + * ViewHelper for displaying a remove extension link. + * * @internal */ final class RemoveExtensionViewHelper extends AbstractTagBasedViewHelper @@ -35,19 +38,14 @@ final class RemoveExtensionViewHelper extends AbstractTagBasedViewHelper */ protected $tagName = 'a'; - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerUniversalTagAttributes(); $this->registerArgument('extension', 'array', '', true); } - /** - * Renders an install link - * - * @return string the rendered a tag - */ - public function render() + public function render(): string { $extension = $this->arguments['extension']; $iconFactory = GeneralUtility::makeInstance(IconFactory::class); @@ -60,7 +58,6 @@ final class RemoveExtensionViewHelper extends AbstractTagBasedViewHelper ) { return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>'; } - /** @var UriBuilder $uriBuilder */ $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $uriBuilder->setRequest($this->renderingContext->getRequest()); $uriBuilder->reset(); @@ -72,8 +69,15 @@ final class RemoveExtensionViewHelper extends AbstractTagBasedViewHelper ); $this->tag->addAttribute('href', $uri); $this->tag->addAttribute('class', $this->arguments['class']); - $this->tag->addAttribute('title', LocalizationUtility::translate('extensionList.remove', 'extensionmanager')); + $this->tag->addAttribute('title', htmlspecialchars($this->getLanguageService()->sL( + 'LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.remove' + ))); $this->tag->setContent($iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render()); return $this->tag->render(); } + + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } } diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/ToggleExtensionInstallationStateViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/ToggleExtensionInstallationStateViewHelper.php index 98cc6eb69b22..880e553bbcb3 100644 --- a/typo3/sysext/extensionmanager/Classes/ViewHelpers/ToggleExtensionInstallationStateViewHelper.php +++ b/typo3/sysext/extensionmanager/Classes/ViewHelpers/ToggleExtensionInstallationStateViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -18,14 +20,15 @@ namespace TYPO3\CMS\Extensionmanager\ViewHelpers; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; +use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Package\PackageManager; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; -use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; /** - * Display a deactivate / activate link + * Render deactivate / activate extension link. + * * @internal */ final class ToggleExtensionInstallationStateViewHelper extends AbstractTagBasedViewHelper @@ -35,22 +38,14 @@ final class ToggleExtensionInstallationStateViewHelper extends AbstractTagBasedV */ protected $tagName = 'a'; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerUniversalTagAttributes(); $this->registerArgument('extension', 'array', '', true); } - /** - * Renders an install link - * - * @return string the rendered a tag - */ - public function render() + public function render(): string { if (Environment::isComposerMode()) { return ''; @@ -76,11 +71,18 @@ final class ToggleExtensionInstallationStateViewHelper extends AbstractTagBasedV ); $this->tag->addAttribute('href', $uri); $label = $extension['installed'] ? 'deactivate' : 'activate'; - $this->tag->addAttribute('title', LocalizationUtility::translate('extensionList.' . $label, 'extensionmanager')); + $this->tag->addAttribute('title', htmlspecialchars($this->getLanguageService()->sL( + 'LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:extensionList.' . $label + ))); $icon = $extension['installed'] ? 'uninstall' : 'install'; $this->tag->addAttribute('class', 'onClickMaskExtensionManager btn btn-default'); $iconFactory = GeneralUtility::makeInstance(IconFactory::class); $this->tag->setContent($iconFactory->getIcon('actions-system-extension-' . $icon, Icon::SIZE_SMALL)->render()); return $this->tag->render(); } + + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } } diff --git a/typo3/sysext/extensionmanager/Classes/ViewHelpers/Typo3DependencyViewHelper.php b/typo3/sysext/extensionmanager/Classes/ViewHelpers/Typo3DependencyViewHelper.php index bb01b5b81cdf..9c9fbee9f036 100644 --- a/typo3/sysext/extensionmanager/Classes/ViewHelpers/Typo3DependencyViewHelper.php +++ b/typo3/sysext/extensionmanager/Classes/ViewHelpers/Typo3DependencyViewHelper.php @@ -24,7 +24,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** - * Shows the version numbers of the TYPO3 dependency, if any + * Shows the version numbers of the TYPO3 dependency, if any. * * @internal */ @@ -44,20 +44,8 @@ final class Typo3DependencyViewHelper extends AbstractViewHelper $this->registerArgument('extension', Extension::class, '', true); } - /** - * Finds and returns the suitable TYPO3 versions of an extension - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ): string { + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string + { $dependency = $arguments['extension']->getTypo3Dependency(); if ($dependency === null) { return ''; diff --git a/typo3/sysext/extensionmanager/Resources/Private/Partials/List/TerShowVersionsTable.html b/typo3/sysext/extensionmanager/Resources/Private/Partials/List/TerShowVersionsTable.html index 3428eae7fe76..f3e83b0a6553 100644 --- a/typo3/sysext/extensionmanager/Resources/Private/Partials/List/TerShowVersionsTable.html +++ b/typo3/sysext/extensionmanager/Resources/Private/Partials/List/TerShowVersionsTable.html @@ -13,7 +13,7 @@ <tbody> <f:for each="{extensions}" as="extension"> <tr> - <td><em:downloadExtension extension="{extension}" /></td> + <td><em:downloadExtension class="download" extension="{extension}" /></td> <td>{extension.title}</th> <td>{extension.version}</td> <td><f:format.nl2br>{extension.updateComment}</f:format.nl2br></td> diff --git a/typo3/sysext/extensionmanager/Resources/Private/Partials/List/TerTable.html b/typo3/sysext/extensionmanager/Resources/Private/Partials/List/TerTable.html index bdb3db86cfc4..feca9b71617a 100644 --- a/typo3/sysext/extensionmanager/Resources/Private/Partials/List/TerTable.html +++ b/typo3/sysext/extensionmanager/Resources/Private/Partials/List/TerTable.html @@ -15,7 +15,7 @@ <tbody> <f:for each="{extensions}" as="extension"> <tr class="{em:installationStateCssClass(needle:extension.extensionKey, haystack:availableAndInstalled)}"> - <td><em:downloadExtension extension="{extension}" /></td> + <td><em:downloadExtension class="download" extension="{extension}" /></td> <td> <f:link.action action="showAllVersions" arguments="{extensionKey: extension.extensionKey}" title="{f:translate(key:'extensionList.showAllVersions.label')}"> {extension.title} diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php index efb0082bfe42..2be90bda4af0 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php @@ -53,20 +53,14 @@ final class CssViewHelper extends AbstractTagBasedViewHelper */ protected $escapeChildren = false; - /** - * @var AssetCollector - */ - protected $assetCollector; + protected AssetCollector $assetCollector; - /** - * @param AssetCollector $assetCollector - */ public function injectAssetCollector(AssetCollector $assetCollector): void { $this->assetCollector = $assetCollector; } - public function initialize() + public function initialize(): void { // Add a tag builder, that does not html encode values, because rendering with encoding happens in AssetRenderer $this->setTagBuilder( @@ -80,9 +74,6 @@ final class CssViewHelper extends AbstractTagBasedViewHelper parent::initialize(); } - /** - * @api - */ public function initializeArguments(): void { parent::initializeArguments(); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php index e5e1d0dc8dbc..29a02d175006 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php @@ -51,20 +51,14 @@ final class ScriptViewHelper extends AbstractTagBasedViewHelper */ protected $escapeChildren = false; - /** - * @var AssetCollector - */ - protected $assetCollector; + protected AssetCollector $assetCollector; - /** - * @param AssetCollector $assetCollector - */ public function injectAssetCollector(AssetCollector $assetCollector): void { $this->assetCollector = $assetCollector; } - public function initialize() + public function initialize(): void { // Add a tag builder, that does not html encode values, because rendering with encoding happens in AssetRenderer $this->setTagBuilder( @@ -78,9 +72,6 @@ final class ScriptViewHelper extends AbstractTagBasedViewHelper parent::initialize(); } - /** - * @api - */ public function initializeArguments(): void { parent::initializeArguments(); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/InfoboxViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/InfoboxViewHelper.php index 1befafaf684d..fc730dbd8af8 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Be/InfoboxViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Be/InfoboxViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -72,12 +74,7 @@ final class InfoboxViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('message', 'string', 'The message of the info box, if NULL tag content is used'); $this->registerArgument('title', 'string', 'The title of the info box'); @@ -86,14 +83,7 @@ final class InfoboxViewHelper extends AbstractViewHelper $this->registerArgument('disableIcon', 'bool', 'If set to TRUE, the icon is not rendered.', false, false); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $title = $arguments['title']; $message = $renderChildrenClosure(); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/LinkViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/LinkViewHelper.php index e4a4b4d8ac7a..e78f672c585b 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Be/LinkViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Be/LinkViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -33,18 +35,12 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; */ final class LinkViewHelper extends AbstractTagBasedViewHelper { - /** * @var string */ protected $tagName = 'a'; - /** - * Arguments initialization - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('route', 'string', 'The name of the route', true); @@ -65,22 +61,16 @@ final class LinkViewHelper extends AbstractTagBasedViewHelper $this->registerUniversalTagAttributes(); } - /** - * @return string Rendered link - */ - public function render() + public function render(): string { $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $route = $this->arguments['route']; $parameters = $this->arguments['parameters']; $referenceType = $this->arguments['referenceType']; - $uri = $uriBuilder->buildUriFromRoute($route, $parameters, $referenceType); - $this->tag->addAttribute('href', $uri); - $this->tag->setContent($this->renderChildren()); + $this->tag->setContent((string)$this->renderChildren()); $this->tag->forceClosingTag(true); - return $this->tag->render(); } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/Menus/ActionMenuItemGroupViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/Menus/ActionMenuItemGroupViewHelper.php index 8b1047c75334..fefa0ce96a8c 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Be/Menus/ActionMenuItemGroupViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Be/Menus/ActionMenuItemGroupViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -46,33 +48,17 @@ final class ActionMenuItemGroupViewHelper extends AbstractTagBasedViewHelper */ protected $tagName = 'optgroup'; - /** - * An array of \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode - * - * @var array - */ - protected $childNodes = []; - - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); - $this->registerArgument('defaultController', 'string', 'The default controller to be used'); + // @todo: deprecate + $this->registerArgument('defaultController', 'string', 'Unused'); $this->registerArgument('label', 'string', 'The label of the option group', false, ''); } - /** - * @return string - */ - public function render() + public function render(): string { - $label = $this->arguments['label']; - - $this->tag->addAttribute('label', $label); + $this->tag->addAttribute('label', $this->arguments['label']); $options = ''; foreach ($this->childNodes as $childNode) { if ($childNode instanceof ViewHelperNode) { diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/PageInfoViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/PageInfoViewHelper.php index f141859dce61..146dbaa9611b 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Be/PageInfoViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Be/PageInfoViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -36,10 +38,11 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; * <f:be.pageInfo /> * * Page info icon with context menu + * + * @todo: Candidate to deprecate? The page info is typically displayed in doc header, done by ModuleTemplate in controllers. */ final class PageInfoViewHelper extends AbstractBackendViewHelper { - /** * This ViewHelper renders HTML, thus output must not be escaped * @@ -47,28 +50,12 @@ final class PageInfoViewHelper extends AbstractBackendViewHelper */ protected $escapeOutput = false; - /** - * Render javascript in header - * - * @return string the rendered page info icon - */ - public function render() + public function render(): string { - return static::renderStatic( - [], - $this->buildRenderChildrenClosure(), - $this->renderingContext - ); + return self::renderStatic([], $this->buildRenderChildrenClosure(), $this->renderingContext); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $id = GeneralUtility::_GP('id'); $pageRecord = BackendUtility::readPageAccess($id, $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW)); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/PagePathViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/PagePathViewHelper.php index f8a0da5827d8..96eaad9967f2 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Be/PagePathViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Be/PagePathViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -35,10 +37,11 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; * <f:be.pagePath /> * * Current page path, prefixed with "Path:" and wrapped in a span with the class ``typo3-docheader-pagePath``. + * + * @todo: Candidate to deprecate? The page info is typically displayed in doc header, done by ModuleTemplate in controllers. */ final class PagePathViewHelper extends AbstractBackendViewHelper { - /** * This ViewHelper renders HTML, thus output must not be escaped * @@ -46,28 +49,12 @@ final class PagePathViewHelper extends AbstractBackendViewHelper */ protected $escapeOutput = false; - /** - * Renders the current page path - * - * @return string the rendered page path - */ - public function render() + public function render(): string { - return static::renderStatic( - [], - $this->buildRenderChildrenClosure(), - $this->renderingContext - ); + return self::renderStatic([], $this->buildRenderChildrenClosure(), $this->renderingContext); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $id = GeneralUtility::_GP('id'); $pageRecord = BackendUtility::readPageAccess($id, $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW)); @@ -78,7 +65,7 @@ final class PagePathViewHelper extends AbstractBackendViewHelper $title = (string)$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; } // Setting the path of the page - $pagePath = htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.path')) . ': <span class="typo3-docheader-pagePath">'; + $pagePath = htmlspecialchars(self::getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.path')) . ': <span class="typo3-docheader-pagePath">'; // crop the title to title limit (or 50, if not defined) $cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen']; $cropLength = (int)$cropLength; @@ -92,11 +79,8 @@ final class PagePathViewHelper extends AbstractBackendViewHelper return $pagePath; } - /** - * @return LanguageService|null - */ - protected static function getLanguageService(): ?LanguageService + protected static function getLanguageService(): LanguageService { - return $GLOBALS['LANG'] ?? null; + return $GLOBALS['LANG']; } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/Security/IfAuthenticatedViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/Security/IfAuthenticatedViewHelper.php index 44cd67206420..8d32ae6c9e0c 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Be/Security/IfAuthenticatedViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Be/Security/IfAuthenticatedViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -53,9 +55,8 @@ final class IfAuthenticatedViewHelper extends AbstractConditionViewHelper * This method decides if the condition is TRUE or FALSE. It can be overridden in extending viewhelpers to adjust functionality. * * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexibility in overriding this method. - * @return bool */ - protected static function evaluateCondition($arguments = null) + protected static function evaluateCondition($arguments = null): bool { return isset($GLOBALS['BE_USER']) && $GLOBALS['BE_USER']->user['uid'] > 0; } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/Security/IfHasRoleViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/Security/IfHasRoleViewHelper.php index e6e852708695..1776de304163 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Be/Security/IfHasRoleViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Be/Security/IfHasRoleViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -67,10 +69,9 @@ final class IfHasRoleViewHelper extends AbstractConditionViewHelper * Renders <f:then> child if the current logged in BE user belongs to the specified role (aka usergroup) * otherwise renders <f:else> child. */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); - $this->registerArgument('role', 'string', 'The usergroup (either the usergroup uid or its title).'); } @@ -78,12 +79,11 @@ final class IfHasRoleViewHelper extends AbstractConditionViewHelper * This method decides if the condition is TRUE or FALSE. It can be overridden in extending viewhelpers to adjust functionality. * * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexibility in overriding this method. - * @return bool */ - protected static function evaluateCondition($arguments = null) + protected static function evaluateCondition($arguments = null): bool { $role = $arguments['role']; - if (!is_array($GLOBALS['BE_USER']->userGroups)) { + if (!is_array($GLOBALS['BE_USER']->userGroups) || $arguments['role'] === null) { return false; } if (is_numeric($role)) { diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/TableListViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/TableListViewHelper.php index c243bf07efcf..7f7521ce12ee 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Be/TableListViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Be/TableListViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -69,25 +71,14 @@ final class TableListViewHelper extends AbstractBackendViewHelper */ protected $escapeOutput = false; - /** - * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface - */ - protected $configurationManager; + protected ConfigurationManagerInterface $configurationManager; - /** - * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager - */ - public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) + public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager): void { $this->configurationManager = $configurationManager; } - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('tableName', 'string', 'name of the database table', true); @@ -101,17 +92,16 @@ final class TableListViewHelper extends AbstractBackendViewHelper $this->registerArgument('readOnly', 'bool', 'if TRUE, the edit icons won\'t be shown. Otherwise edit icons will be shown, if the current BE user has edit rights for the specified table!', false, false); $this->registerArgument('enableClickMenu', 'bool', 'enables context menu', false, true); $this->registerArgument('enableControlPanels', 'bool', 'enables control panels', false, false); - $this->registerArgument('clickTitleMode', 'string', 'one of "edit", "show" (only pages, tt_content), "info'); + $this->registerArgument('clickTitleMode', 'string', 'one of "edit", "show" (only pages, tt_content), "info', false, ''); } /** * Renders a record list as known from the TYPO3 list module * Note: This feature is experimental! * - * @return string the rendered record list * @see \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList */ - public function render() + public function render(): string { $tableName = $this->arguments['tableName']; $fieldList = $this->arguments['fieldList']; @@ -136,29 +126,29 @@ final class TableListViewHelper extends AbstractBackendViewHelper // We need to include the language file, since DatabaseRecordList is heavily using ->getLL $this->getLanguageService()->includeLLFile('EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf'); - $pageinfo = BackendUtility::readPageAccess(GeneralUtility::_GP('id'), $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW)) ?: []; - $dblist = GeneralUtility::makeInstance(DatabaseRecordList::class); - $dblist->pageRow = $pageinfo; + $pageInfo = BackendUtility::readPageAccess(GeneralUtility::_GP('id'), $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW)) ?: []; + $dbList = GeneralUtility::makeInstance(DatabaseRecordList::class); + $dbList->pageRow = $pageInfo; if ($readOnly) { - $dblist->setIsEditable(false); + $dbList->setIsEditable(false); } else { - $dblist->calcPerms = new Permission($GLOBALS['BE_USER']->calcPerms($pageinfo)); + $dbList->calcPerms = new Permission($GLOBALS['BE_USER']->calcPerms($pageInfo)); } - $dblist->disableSingleTableView = true; - $dblist->clickTitleMode = $clickTitleMode; - $dblist->clickMenuEnabled = $enableClickMenu; + $dbList->disableSingleTableView = true; + $dbList->clickTitleMode = $clickTitleMode; + $dbList->clickMenuEnabled = $enableClickMenu; if ($storagePid === null) { $frameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); $storagePid = $frameworkConfiguration['persistence']['storagePid']; } - $dblist->start($storagePid, $tableName, (int)GeneralUtility::_GP('pointer'), $filter, $levels, $recordsPerPage); + $dbList->start($storagePid, $tableName, (int)GeneralUtility::_GP('pointer'), $filter, $levels, $recordsPerPage); // Column selector is disabled since fields are defined by the "fieldList" argument - $dblist->displayColumnSelector = false; - $dblist->setFields = [$tableName => $fieldList]; - $dblist->noControlPanels = !$enableControlPanels; - $dblist->sortField = $sortField; - $dblist->sortRev = $sortDescending; - return $dblist->generateList(); + $dbList->displayColumnSelector = false; + $dbList->setFields = [$tableName => $fieldList]; + $dbList->noControlPanels = !$enableControlPanels; + $dbList->sortField = $sortField; + $dbList->sortRev = $sortDescending; + return $dbList->generateList(); } protected function getLanguageService(): LanguageService diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/UriViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/UriViewHelper.php index cfbc05705c2a..b016006be1a2 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Be/UriViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Be/UriViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -38,13 +40,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; */ final class UriViewHelper extends AbstractBackendViewHelper { - - /** - * Arguments initialization - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('route', 'string', 'The name of the route', true); @@ -58,18 +54,13 @@ final class UriViewHelper extends AbstractBackendViewHelper ); } - /** - * @return string Rendered link - */ - public function render() + public function render(): string { - /** @var UriBuilder $uriBuilder */ $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $route = $this->arguments['route']; $parameters = $this->arguments['parameters']; $referenceType = $this->arguments['referenceType']; $uri = $uriBuilder->buildUriFromRoute($route, $parameters, $referenceType); - return (string)$uri; } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php index 50e4978d0a8c..982d135665e5 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -103,17 +105,7 @@ final class CObjectViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController contains a backup of the current $GLOBALS['TSFE'] if used in BE mode - */ - protected static $tsfeBackup; - - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('data', 'mixed', 'the data to be used for rendering the cObject. Can be an object, array or string. If this argument is not set, child nodes will be used'); $this->registerArgument('typoscriptObjectPath', 'string', 'the TypoScript setup path of the TypoScript object to render', true); @@ -124,21 +116,18 @@ final class CObjectViewHelper extends AbstractViewHelper /** * Renders the TypoScript object in the given TypoScript setup path. * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return mixed - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception + * @throws Exception */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { - $data = $renderChildrenClosure(); + $data = $arguments['data'] ?? $renderChildrenClosure(); $typoscriptObjectPath = $arguments['typoscriptObjectPath']; $currentValueKey = $arguments['currentValueKey']; $table = $arguments['table']; - $contentObjectRenderer = static::getContentObjectRenderer($renderingContext->getRequest()); + $contentObjectRenderer = self::getContentObjectRenderer($renderingContext->getRequest()); + $tsfeBackup = null; if (!isset($GLOBALS['TSFE']) || !($GLOBALS['TSFE'] instanceof TypoScriptFrontendController)) { - static::simulateFrontendEnvironment(); + $tsfeBackup = self::simulateFrontendEnvironment(); } $currentValue = null; if (is_object($data)) { @@ -155,7 +144,7 @@ final class CObjectViewHelper extends AbstractViewHelper } $pathSegments = GeneralUtility::trimExplode('.', $typoscriptObjectPath); $lastSegment = (string)array_pop($pathSegments); - $setup = static::getConfigurationManager()->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); + $setup = self::getConfigurationManager()->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); foreach ($pathSegments as $segment) { if (!array_key_exists($segment . '.', $setup)) { throw new Exception( @@ -173,7 +162,7 @@ final class CObjectViewHelper extends AbstractViewHelper } $content = self::renderContentObject($contentObjectRenderer, $setup, $typoscriptObjectPath, $lastSegment); if (!isset($GLOBALS['TSFE']) || !($GLOBALS['TSFE'] instanceof TypoScriptFrontendController)) { - static::resetFrontendEnvironment(); + self::resetFrontendEnvironment($tsfeBackup); } return $content; } @@ -208,10 +197,6 @@ final class CObjectViewHelper extends AbstractViewHelper return GeneralUtility::getContainer()->get(ConfigurationManagerInterface::class); } - /** - * @param ServerRequestInterface $request - * @return ContentObjectRenderer - */ protected static function getContentObjectRenderer(ServerRequestInterface $request): ContentObjectRenderer { if (($GLOBALS['TSFE'] ?? null) instanceof TypoScriptFrontendController) { @@ -239,20 +224,19 @@ final class CObjectViewHelper extends AbstractViewHelper /** * \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->cObjGetSingle() relies on $GLOBALS['TSFE'] */ - protected static function simulateFrontendEnvironment() + protected static function simulateFrontendEnvironment(): ?TypoScriptFrontendController { - static::$tsfeBackup = $GLOBALS['TSFE'] ?? null; + $tsfeBackup = $GLOBALS['TSFE'] ?? null; $GLOBALS['TSFE'] = new \stdClass(); $GLOBALS['TSFE']->cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); + return $tsfeBackup; } /** * Resets $GLOBALS['TSFE'] if it was previously changed by simulateFrontendEnvironment() - * - * @see simulateFrontendEnvironment() */ - protected static function resetFrontendEnvironment() + protected static function resetFrontendEnvironment(?TypoScriptFrontendController $tsfeBackup): void { - $GLOBALS['TSFE'] = static::$tsfeBackup; + $GLOBALS['TSFE'] = $tsfeBackup; } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Debug/RenderViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Debug/RenderViewHelper.php index f333c4c0a5e1..04ee7507aefa 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Debug/RenderViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Debug/RenderViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -30,33 +32,24 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; */ final class RenderViewHelper extends AbstractViewHelper { - /** * @var bool */ protected $escapeOutput = false; - /** - * Initializes additional arguments available for this ViewHelper. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('debug', 'boolean', 'If true, the admin panel shows debug information if activated,', false, true); - $this->registerArgument('section', 'string', 'Section to render - combine with partial to render section in partial', false, null); - $this->registerArgument('partial', 'string', 'Partial to render, with or without section', false, null); + $this->registerArgument('section', 'string', 'Section to render - combine with partial to render section in partial', false); + $this->registerArgument('partial', 'string', 'Partial to render, with or without section', false); $this->registerArgument('arguments', 'array', 'Array of variables to be transferred. Use {_all} for all variables', false, []); $this->registerArgument('optional', 'boolean', 'If TRUE, considers the *section* optional. Partial never is.', false, false); - $this->registerArgument('default', 'mixed', 'Value (usually string) to be displayed if the section or partial does not exist', false, null); - $this->registerArgument('contentAs', 'string', 'If used, renders the child content and adds it as a template variable with this name for use in the partial/section', false, null); + $this->registerArgument('default', 'mixed', 'Value (usually string) to be displayed if the section or partial does not exist', false); + $this->registerArgument('contentAs', 'string', 'If used, renders the child content and adds it as a template variable with this name for use in the partial/section', false); } - /** - * Renders the content. - * - * @return string - */ - public function render() + public function render(): string { $isDebug = $this->arguments['debug']; $section = $this->arguments['section']; @@ -79,9 +72,9 @@ final class RenderViewHelper extends AbstractViewHelper } // Replace empty content with default value. If default is // not set, NULL is returned and cast to a new, empty string - // outside of this ViewHelper. + // outside this ViewHelper. if ($content === '') { - $content = $this->arguments['default'] ?? $tagContent; + $content = $this->arguments['default'] ?? (string)$tagContent; } // if debug is disabled, return content diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/DebugViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/DebugViewHelper.php index 561ce70b535a..ce435dfb2e5e 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/DebugViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/DebugViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -69,12 +71,7 @@ final class DebugViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('title', 'string', 'optional custom title for the debug output'); $this->registerArgument('maxDepth', 'int', 'Sets the max recursion depth of the dump (defaults to 8). De- or increase the number according to your needs and memory limit.', false, 8); @@ -87,15 +84,18 @@ final class DebugViewHelper extends AbstractViewHelper /** * A wrapper for \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(). - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { - return DebuggerUtility::var_dump($renderChildrenClosure(), $arguments['title'], $arguments['maxDepth'], (bool)$arguments['plainText'], (bool)$arguments['ansiColors'], (bool)$arguments['inline'], $arguments['blacklistedClassNames'], $arguments['blacklistedPropertyNames']); + return DebuggerUtility::var_dump( + $renderChildrenClosure(), + $arguments['title'], + $arguments['maxDepth'], + $arguments['plainText'], + $arguments['ansiColors'], + $arguments['inline'], + $arguments['blacklistedClassNames'], + $arguments['blacklistedPropertyNames'] + ); } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/ButtonViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/ButtonViewHelper.php index 12c1beba6fa9..79b7d61eac1d 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/ButtonViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/ButtonViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -49,12 +51,7 @@ final class ButtonViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'button'; - /** - * Initialize the arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerTagAttribute( @@ -97,12 +94,7 @@ final class ButtonViewHelper extends AbstractFormFieldViewHelper $this->registerArgument('type', 'string', 'Specifies the type of button (e.g. "button", "reset" or "submit")', false, 'submit'); } - /** - * Renders the button. - * - * @return string - */ - public function render() + public function render(): string { $type = $this->arguments['type']; $name = $this->getName(); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/CheckboxViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/CheckboxViewHelper.php index 220c2799c684..730c77a8089d 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/CheckboxViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/CheckboxViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -65,10 +67,7 @@ final class CheckboxViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'input'; - /** - * Initialize the arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerTagAttribute( @@ -89,13 +88,7 @@ final class CheckboxViewHelper extends AbstractFormFieldViewHelper $this->registerArgument('multiple', 'bool', 'Specifies whether this checkbox belongs to a multivalue (is part of a checkbox group)', false, false); } - /** - * Renders the checkbox. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - * @return string - */ - public function render() + public function render(): string { $checked = $this->arguments['checked']; $multiple = $this->arguments['multiple']; diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/HiddenViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/HiddenViewHelper.php index 626a3127369d..f949f900b9fd 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/HiddenViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/HiddenViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -39,10 +41,7 @@ final class HiddenViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'input'; - /** - * Initialize the arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerUniversalTagAttributes(); @@ -55,16 +54,11 @@ final class HiddenViewHelper extends AbstractFormFieldViewHelper ); } - /** - * Renders the hidden field. - * - * @return string - */ - public function render() + public function render(): string { $name = $this->getName(); $this->registerFieldNameForFormTokenGeneration($name); - $this->setRespectSubmittedDataValue((bool)($this->arguments['respectSubmittedDataValue'] ?? true)); + $this->setRespectSubmittedDataValue($this->arguments['respectSubmittedDataValue']); $this->tag->addAttribute('type', 'hidden'); $this->tag->addAttribute('name', $name); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/PasswordViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/PasswordViewHelper.php index f916eadc6e2b..9bd98cfcb3df 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/PasswordViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/PasswordViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -36,10 +38,7 @@ final class PasswordViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'input'; - /** - * Initialize the arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerTagAttribute( @@ -66,12 +65,7 @@ final class PasswordViewHelper extends AbstractFormFieldViewHelper $this->registerUniversalTagAttributes(); } - /** - * Renders the password input field. - * - * @return string - */ - public function render() + public function render(): string { $name = $this->getName(); $this->registerFieldNameForFormTokenGeneration($name); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/RadioViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/RadioViewHelper.php index 77516549a230..c126f3cc028a 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/RadioViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/RadioViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -67,10 +69,7 @@ final class RadioViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'input'; - /** - * Initialize the arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument( @@ -90,12 +89,7 @@ final class RadioViewHelper extends AbstractFormFieldViewHelper ); } - /** - * Renders the checkbox. - * - * @return string - */ - public function render() + public function render(): string { $checked = $this->arguments['checked']; diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/Select/OptgroupViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/Select/OptgroupViewHelper.php index 39e98639642b..2e43fe42381f 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/Select/OptgroupViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/Select/OptgroupViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -28,10 +30,7 @@ final class OptgroupViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'optgroup'; - /** - * Initialize additional arguments available for this tag ViewHelper. - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerUniversalTagAttributes(); $this->registerArgument('additionalAttributes', 'array', 'Additional tag attributes. They will be added directly to the resulting HTML tag.'); @@ -40,10 +39,7 @@ final class OptgroupViewHelper extends AbstractFormFieldViewHelper $this->registerTagAttribute('disabled', 'boolean', 'If true, option group is rendered as disabled', false, false); } - /** - * @return string - */ - public function render() + public function render(): string { if ($this->arguments['disabled']) { $this->tag->addAttribute('disabled', 'disabled'); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/Select/OptionViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/Select/OptionViewHelper.php index aa55865301e7..78011b22b9e0 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/Select/OptionViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/Select/OptionViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -28,10 +30,7 @@ final class OptionViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'option'; - /** - * Initialize additional arguments available for this tag ViewHelper. - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerUniversalTagAttributes(); $this->registerArgument('selected', 'boolean', 'If set, overrides automatic detection of selected state for this option.'); @@ -40,10 +39,7 @@ final class OptionViewHelper extends AbstractFormFieldViewHelper $this->registerTagAttribute('value', 'mixed', 'Value to be inserted in HTML tag - must be convertible to string!'); } - /** - * @return string - */ - public function render() + public function render(): string { $childContent = $this->renderChildren(); $this->tag->setContent($childContent); @@ -65,10 +61,6 @@ final class OptionViewHelper extends AbstractFormFieldViewHelper return $this->tag->render(); } - /** - * @param string $value - * @return bool - */ protected function isValueSelected(string $value): bool { $selectedValue = $this->renderingContext->getViewHelperVariableContainer()->get(SelectViewHelper::class, 'selectedValue'); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php index ea96081ae10a..471eaefc97c3 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -103,10 +105,7 @@ final class SelectViewHelper extends AbstractFormFieldViewHelper */ protected $selectedValue; - /** - * Initialize arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerUniversalTagAttributes(); @@ -125,18 +124,13 @@ final class SelectViewHelper extends AbstractFormFieldViewHelper $this->registerArgument('required', 'boolean', 'If set no empty value is allowed.', false, false); } - /** - * Render the tag. - * - * @return string rendered tag. - */ - public function render() + public function render(): string { - if (isset($this->arguments['required']) && $this->arguments['required']) { + if ($this->arguments['required']) { $this->tag->addAttribute('required', 'required'); } $name = $this->getName(); - if (isset($this->arguments['multiple']) && $this->arguments['multiple']) { + if ($this->arguments['multiple']) { $this->tag->addAttribute('multiple', 'multiple'); $name .= '[]'; } @@ -153,7 +147,7 @@ final class SelectViewHelper extends AbstractFormFieldViewHelper $this->registerFieldNameForFormTokenGeneration($name); // in case it is a multi-select, we need to register the field name // as often as there are elements in the box - if (isset($this->arguments['multiple']) && $this->arguments['multiple']) { + if ($this->arguments['multiple']) { $content .= $this->renderHiddenFieldForEmptyValue(); // Register the field name additional times as required by the total number of // options. Since we already registered it once above, we start the counter at 1 @@ -193,32 +187,27 @@ final class SelectViewHelper extends AbstractFormFieldViewHelper /** * Render prepended option tag - * - * @return string rendered prepended empty option */ - protected function renderPrependOptionTag() + protected function renderPrependOptionTag(): string { $output = ''; if ($this->hasArgument('prependOptionLabel')) { $value = $this->hasArgument('prependOptionValue') ? $this->arguments['prependOptionValue'] : ''; $label = $this->arguments['prependOptionLabel']; - $output .= $this->renderOptionTag($value, $label, false) . LF; + $output .= $this->renderOptionTag((string)$value, (string)$label, false) . LF; } return $output; } /** * Render the option tags. - * - * @param array $options the options for the form. - * @return string rendered tags. */ - protected function renderOptionTags($options) + protected function renderOptionTags(array $options): string { $output = ''; foreach ($options as $value => $label) { $isSelected = $this->isSelected($value); - $output .= $this->renderOptionTag($value, $label, $isSelected) . LF; + $output .= $this->renderOptionTag((string)$value, (string)$label, $isSelected) . LF; } return $output; } @@ -226,9 +215,9 @@ final class SelectViewHelper extends AbstractFormFieldViewHelper /** * Render the option tags. * - * @return array an associative array of options, key will be the value of the option tag + * @return array An associative array of options, key will be the value of the option tag */ - protected function getOptions() + protected function getOptions(): array { if (!is_array($this->arguments['options']) && !$this->arguments['options'] instanceof \Traversable) { return []; @@ -282,9 +271,9 @@ final class SelectViewHelper extends AbstractFormFieldViewHelper * Render the option tags. * * @param mixed $value Value to check for - * @return bool TRUE if the value should be marked a s selected; FALSE otherwise + * @return bool True if the value should be marked as selected. */ - protected function isSelected($value) + protected function isSelected($value): bool { $selectedValue = $this->getSelectedValue(); if ($value === $selectedValue || (string)$value === $selectedValue) { @@ -324,7 +313,7 @@ final class SelectViewHelper extends AbstractFormFieldViewHelper * Get the option value for an object * * @param mixed $valueElement - * @return string + * @return string @todo: Does not always return string ... */ protected function getOptionValueScalar($valueElement) { @@ -346,16 +335,16 @@ final class SelectViewHelper extends AbstractFormFieldViewHelper * * @param string $value value attribute of the option tag (will be escaped) * @param string $label content of the option tag (will be escaped) - * @param bool $isSelected specifies whether or not to add selected attribute + * @param bool $isSelected specifies whether to add selected attribute * @return string the rendered option tag */ - protected function renderOptionTag($value, $label, $isSelected) + protected function renderOptionTag(string $value, string $label, bool $isSelected): string { - $output = '<option value="' . htmlspecialchars((string)$value) . '"'; + $output = '<option value="' . htmlspecialchars($value) . '"'; if ($isSelected) { $output .= ' selected="selected"'; } - $output .= '>' . htmlspecialchars((string)$label) . '</option>'; + $output .= '>' . htmlspecialchars($label) . '</option>'; return $output; } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/SubmitViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/SubmitViewHelper.php index 3bb1e1f1f0c9..f648f420f124 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/SubmitViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/SubmitViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -50,10 +52,7 @@ final class SubmitViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'input'; - /** - * Initialize the arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerTagAttribute( @@ -64,12 +63,7 @@ final class SubmitViewHelper extends AbstractFormFieldViewHelper $this->registerUniversalTagAttributes(); } - /** - * Renders the submit button. - * - * @return string - */ - public function render() + public function render(): string { $name = $this->getName(); $this->registerFieldNameForFormTokenGeneration($name); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/TextareaViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/TextareaViewHelper.php index 872cbfbd2193..729143308397 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/TextareaViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/TextareaViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -38,10 +40,7 @@ final class TextareaViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'textarea'; - /** - * Initialize the arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerTagAttribute('autofocus', 'string', 'Specifies that a text area should automatically get focus when the page loads'); @@ -55,14 +54,9 @@ final class TextareaViewHelper extends AbstractFormFieldViewHelper $this->registerUniversalTagAttributes(); } - /** - * Renders the textarea. - * - * @return string - */ - public function render() + public function render(): string { - $required = $this->arguments['required'] ?? false; + $required = $this->arguments['required']; $name = $this->getName(); $this->registerFieldNameForFormTokenGeneration($name); $this->setRespectSubmittedDataValue(true); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/TextfieldViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/TextfieldViewHelper.php index 396dd1628b34..937777403c81 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/TextfieldViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/TextfieldViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -36,12 +38,7 @@ final class TextfieldViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'input'; - /** - * Initialize the arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerTagAttribute('autofocus', 'string', 'Specifies that an input should automatically get focus when the page loads'); @@ -57,15 +54,10 @@ final class TextfieldViewHelper extends AbstractFormFieldViewHelper $this->registerArgument('type', 'string', 'The field type, e.g. "text", "email", "url" etc.', false, 'text'); } - /** - * Renders the textfield. - * - * @return string - */ - public function render() + public function render(): string { - $required = $this->arguments['required'] ?? false; - $type = $this->arguments['type'] ?? null; + $required = $this->arguments['required']; + $type = $this->arguments['type']; $name = $this->getName(); $this->registerFieldNameForFormTokenGeneration($name); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/UploadViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/UploadViewHelper.php index 966d7dfcbaaa..4de4255e4360 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/UploadViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/UploadViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -37,10 +39,7 @@ final class UploadViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'input'; - /** - * Initialize the arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads'); @@ -50,12 +49,7 @@ final class UploadViewHelper extends AbstractFormFieldViewHelper $this->registerUniversalTagAttributes(); } - /** - * Renders the upload field. - * - * @return string - */ - public function render() + public function render(): string { $name = $this->getName(); $allowedFields = ['name', 'type', 'tmp_name', 'error', 'size']; diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/ValidationResultsViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/ValidationResultsViewHelper.php index 0e1187b9906f..06aabbf3ea67 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/ValidationResultsViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/ValidationResultsViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -78,20 +80,14 @@ final class ValidationResultsViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('for', 'string', 'The name of the error name (e.g. argument name or property name). This can also be a property path (like blog.title), and will then only display the validation errors of that property.', false, ''); $this->registerArgument('as', 'string', 'The name of the variable to store the current error', false, 'validationResults'); } /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return mixed + * @return mixed @todo: Really mixed here, not string? */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/AbstractEncodingViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/AbstractEncodingViewHelper.php index 3fa1c22f8344..da492bd183f0 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/AbstractEncodingViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/AbstractEncodingViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -19,7 +21,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** * This is the base class for ViewHelpers that work with encodings. - * Currently that are format.htmlentities, format.htmlentitiesDecode and format.htmlspecialchars + * Currently, that are format.htmlentities and format.htmlentitiesDecode */ abstract class AbstractEncodingViewHelper extends AbstractViewHelper { @@ -30,10 +32,8 @@ abstract class AbstractEncodingViewHelper extends AbstractViewHelper /** * Resolve the default encoding. If none is set in Frontend or Backend, uses UTF-8. - * - * @return string the encoding */ - protected static function resolveDefaultEncoding() + protected static function resolveDefaultEncoding(): string { if (self::$defaultEncoding === null) { self::$defaultEncoding = 'UTF-8'; diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/CaseViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/CaseViewHelper.php index 3fb358a2e1da..04e5e428b834 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/CaseViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/CaseViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -107,31 +109,23 @@ final class CaseViewHelper extends AbstractViewHelper */ protected $escapeChildren = false; - /** - * Initialize ViewHelper arguments - */ - public function initializeArguments() + public function initializeArguments(): void { - $this->registerArgument('value', 'string', 'The input value. If not given, the evaluated child nodes will be used.', false, null); + $this->registerArgument('value', 'string', 'The input value. If not given, the evaluated child nodes will be used.', false); $this->registerArgument('mode', 'string', 'The case to apply, must be one of this\' CASE_* constants. Defaults to uppercase application.', false, self::CASE_UPPER); } /** * Changes the case of the input string - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string * @throws Exception */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $value = $arguments['value']; $mode = $arguments['mode']; if ($value === null) { - $value = $renderChildrenClosure(); + $value = (string)$renderChildrenClosure(); } switch ($mode) { diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/CropViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/CropViewHelper.php index 308d1015f19c..2a45fbeea203 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/CropViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/CropViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -97,12 +99,7 @@ final class CropViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('maxCharacters', 'int', 'Place where to truncate the string', true); $this->registerArgument('append', 'string', 'What to append, if truncation happened', false, '…'); @@ -110,15 +107,7 @@ final class CropViewHelper extends AbstractViewHelper $this->registerArgument('respectHtml', 'bool', 'If TRUE the cropped string will respect HTML tags and entities. Technically that means, that cropHTML() is called rather than crop()', false, true); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - * @throws \InvalidArgumentException - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $maxCharacters = $arguments['maxCharacters']; $append = $arguments['append']; @@ -130,7 +119,6 @@ final class CropViewHelper extends AbstractViewHelper // It would be possible to retrieve the "current" content object via ConfigurationManager->getContentObject(), // but both crop() and cropHTML() are "nearly" static and do not depend on current content object settings, so // it is safe to use a fresh instance here directly. - /** @var ContentObjectRenderer $contentObject */ $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class); if ($respectHtml) { $content = $contentObject->cropHTML($stringToTruncate, $maxCharacters . '|' . $append . '|' . $respectWordBoundaries); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/CurrencyViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/CurrencyViewHelper.php index b7b77e7afbd3..6cc17146dd01 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/CurrencyViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/CurrencyViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -86,12 +88,7 @@ final class CurrencyViewHelper extends AbstractViewHelper */ protected $escapeChildren = false; - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('currencySign', 'string', 'The currency sign, eg $ or €.', false, ''); $this->registerArgument('decimalSeparator', 'string', 'The separator for the decimal point.', false, ','); @@ -102,16 +99,7 @@ final class CurrencyViewHelper extends AbstractViewHelper $this->registerArgument('useDash', 'bool', 'Use the dash instead of decimal 00', false, false); } - /** - * Formats a float to currency formatting - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string the formatted amount - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $currencySign = $arguments['currencySign']; $decimalSeparator = $arguments['decimalSeparator']; diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php index 1c6f64e661db..dea5ecd74b54 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -110,10 +112,7 @@ final class DateViewHelper extends AbstractViewHelper */ protected $escapeChildren = false; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('date', 'mixed', 'Either an object implementing DateTimeInterface or a string that is accepted by DateTime constructor'); $this->registerArgument('format', 'string', 'Format String which is taken to format the Date/Time', false, ''); @@ -121,14 +120,9 @@ final class DateViewHelper extends AbstractViewHelper } /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string * @throws Exception */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $format = $arguments['format']; $base = $arguments['base'] ?? GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('date', 'timestamp'); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlViewHelper.php index 72e7e231f73a..73e41f53ce3c 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -19,6 +21,7 @@ use TYPO3\CMS\Core\Http\ApplicationType; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; +use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; @@ -72,11 +75,6 @@ final class HtmlViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController contains a backup of the current $GLOBALS['TSFE'] if used in BE mode - */ - protected static $tsfeBackup; - /** * Children must not be escaped, to be able to pass {bodytext} directly to it * @@ -91,60 +89,49 @@ final class HtmlViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('parseFuncTSPath', 'string', ' path to TypoScript parseFunc setup.', false, 'lib.parseFunc_RTE'); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string the parsed string. - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $parseFuncTSPath = $arguments['parseFuncTSPath']; $isBackendRequest = ApplicationType::fromRequest($renderingContext->getRequest())->isBackend(); if ($isBackendRequest) { - self::simulateFrontendEnvironment(); + $tsfeBackup = self::simulateFrontendEnvironment(); } $value = $renderChildrenClosure(); $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class); $contentObject->start([]); $content = $contentObject->parseFunc($value, [], '< ' . $parseFuncTSPath); if ($isBackendRequest) { - self::resetFrontendEnvironment(); + self::resetFrontendEnvironment($tsfeBackup); } return $content; } /** - * Copies the specified parseFunc configuration to $GLOBALS['TSFE']->tmpl->setup in Backend mode - * This somewhat hacky work around is currently needed because the parseFunc() function of \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer relies on those variables to be set + * Copies the specified parseFunc configuration to $GLOBALS['TSFE']->tmpl->setup in Backend mode. + * This somewhat hacky work around is currently needed because ContentObjectRenderer->parseFunc() relies on those variables to be set. + * + * @return ?TypoScriptFrontendController The 'old' backed up $GLOBALS['TSFE'] or null */ - protected static function simulateFrontendEnvironment() + protected static function simulateFrontendEnvironment(): ?TypoScriptFrontendController { - self::$tsfeBackup = $GLOBALS['TSFE'] ?? null; + $tsfeBackup = $GLOBALS['TSFE'] ?? null; $GLOBALS['TSFE'] = new \stdClass(); $GLOBALS['TSFE']->tmpl = new \stdClass(); $configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class); $GLOBALS['TSFE']->tmpl->setup = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); + return $tsfeBackup; } /** * Resets $GLOBALS['TSFE'] if it was previously changed by simulateFrontendEnvironment() - * - * @see simulateFrontendEnvironment() */ - protected static function resetFrontendEnvironment() + protected static function resetFrontendEnvironment(?TypoScriptFrontendController $tsfeBackup): void { - $GLOBALS['TSFE'] = self::$tsfeBackup; + $GLOBALS['TSFE'] = $tsfeBackup; } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesDecodeViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesDecodeViewHelper.php index f58d36f05227..760b50858be5 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesDecodeViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesDecodeViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -65,10 +67,7 @@ final class HtmlentitiesDecodeViewHelper extends AbstractEncodingViewHelper */ protected $escapeOutput = false; - /** - * Initialize ViewHelper arguments - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('value', 'string', 'string to format'); @@ -80,13 +79,8 @@ final class HtmlentitiesDecodeViewHelper extends AbstractEncodingViewHelper * Converts all HTML entities to their applicable characters as needed using PHPs html_entity_decode() function. * * @see https://www.php.net/html_entity_decode - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $value = $renderChildrenClosure(); $encoding = $arguments['encoding']; diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesViewHelper.php index 98ba5e8a123b..9621d3e122ff 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -65,10 +67,7 @@ final class HtmlentitiesViewHelper extends AbstractEncodingViewHelper */ protected $escapeChildren = false; - /** - * Initialize ViewHelper arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('value', 'string', 'string to format'); $this->registerArgument('keepQuotes', 'bool', 'If TRUE, single and double quotes won\'t be replaced (sets ENT_NOQUOTES flag).', false, false); @@ -80,9 +79,6 @@ final class HtmlentitiesViewHelper extends AbstractEncodingViewHelper * Escapes special characters with their escaped counterparts as needed using PHPs htmlentities() function. * * @see https://www.php.net/manual/function.htmlentities.php - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext * @return mixed */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/JsonViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/JsonViewHelper.php index a1127e76e096..fe01fec5c403 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/JsonViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/JsonViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -13,10 +15,6 @@ * The TYPO3 project - inspiring people to share! */ -/* - * Inspired by and partially taken from the Neos.Form package (www.neos.io) - */ - namespace TYPO3\CMS\Fluid\ViewHelpers\Format; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; @@ -67,10 +65,7 @@ final class JsonViewHelper extends AbstractViewHelper */ protected $escapeChildren = false; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('value', 'mixed', 'The incoming data to convert, or null if VH children should be used'); $this->registerArgument('forceObject', 'bool', 'Outputs an JSON object rather than an array', false, false); @@ -85,11 +80,8 @@ final class JsonViewHelper extends AbstractViewHelper * If $forceObject is TRUE a JSON object is outputted even if the value is a non-associative array * Example: array('foo', 'bar') as input will not be ["foo","bar"] but {"0":"foo","1":"bar"} * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext * @see https://www.php.net/manual/function.json-encode.php - * @return string + * @return string|false */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/Nl2brViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/Nl2brViewHelper.php index c1041b3acbbd..a5dd4b658de0 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/Nl2brViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/Nl2brViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -53,26 +55,13 @@ final class Nl2brViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('value', 'string', 'string to format'); } - /** - * Applies nl2br() on the specified value. - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface $renderingContext - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { - return nl2br((string)$renderChildrenClosure()); + return nl2br((string)($arguments['value'] ?? $renderChildrenClosure())); } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/NumberViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/NumberViewHelper.php index 9c2d3151aa8c..220317190123 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/NumberViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/NumberViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -57,34 +59,21 @@ final class NumberViewHelper extends AbstractViewHelper */ protected $escapeChildren = false; - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { - $this->registerArgument('decimals', 'int', 'The number of digits after the decimal point', false, '2'); + $this->registerArgument('decimals', 'int', 'The number of digits after the decimal point', false, 2); $this->registerArgument('decimalSeparator', 'string', 'The decimal point character', false, '.'); $this->registerArgument('thousandsSeparator', 'string', 'The character for grouping the thousand digits', false, ','); } /** - * Format the numeric value as a number with grouped thousands, decimal point and - * precision. - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string The formatted number + * Format the numeric value as a number with grouped thousands, decimal point and precision. */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $decimals = $arguments['decimals']; $decimalSeparator = $arguments['decimalSeparator']; $thousandsSeparator = $arguments['thousandsSeparator']; - $stringToFormat = $renderChildrenClosure(); return number_format((float)$stringToFormat, $decimals, $decimalSeparator, $thousandsSeparator); } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/PaddingViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/PaddingViewHelper.php index ec5d3f8daa7e..ee27abea90b5 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/PaddingViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/PaddingViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -69,12 +71,7 @@ final class PaddingViewHelper extends AbstractViewHelper */ protected $escapeChildren = false; - /** - * Initialize arguments. - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('value', 'string', 'string to format'); $this->registerArgument('padLength', 'int', 'Length of the resulting string. If the value of pad_length is negative or less than the length of the input string, no padding takes place.', true); @@ -83,14 +80,9 @@ final class PaddingViewHelper extends AbstractViewHelper } /** - * Pad a string to a certain length with another string - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface $renderingContext - * @return string The formatted value + * Pad a string to a certain length with another string. */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $value = $renderChildrenClosure(); $padTypes = [ @@ -103,6 +95,6 @@ final class PaddingViewHelper extends AbstractViewHelper $padType = 'right'; } - return StringUtility::multibyteStringPad((string)$value, $arguments['padLength'], $arguments['padString'], $padTypes[$padType]); + return StringUtility::multibyteStringPad((string)$value, (int)$arguments['padLength'], (string)$arguments['padString'], $padTypes[$padType]); } } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/StripTagsViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/StripTagsViewHelper.php index 0db2ad841351..9e41be2bbfc2 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/StripTagsViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/StripTagsViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -80,16 +82,10 @@ final class StripTagsViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize ViewHelper arguments - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('value', 'string', 'string to format'); - $this->registerArgument('allowedTags', 'string', 'Optional string of allowed tags as required by PHPs strip_tags() f -unction'); + $this->registerArgument('allowedTags', 'string', 'Optional string of allowed tags as required by PHPs strip_tags() function'); } /** @@ -100,20 +96,14 @@ unction'); protected $escapeChildren = false; /** - * Applies strip_tags() on the specified value. + * Applies strip_tags() on the specified value if it's string-able. * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface $renderingContext * @see https://www.php.net/manual/function.strip-tags.php - * @return string + * @return mixed */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $value = $renderChildrenClosure(); + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + { + $value = $arguments['value'] ?? $renderChildrenClosure(); $allowedTags = $arguments['allowedTags']; if (!is_string($value) && !(is_object($value) && method_exists($value, '__toString'))) { return $value; diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/UrlencodeViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/UrlencodeViewHelper.php index 746922ec7a5c..07b861eccc8d 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/UrlencodeViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/UrlencodeViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -17,7 +19,6 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; -use TYPO3Fluid\Fluid\Core\ViewHelper\Exception; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic; /** @@ -60,12 +61,7 @@ final class UrlencodeViewHelper extends AbstractViewHelper */ protected $escapeChildren = false; - /** - * Initialize ViewHelper arguments - * - * @throws Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('value', 'string', 'string to format'); } @@ -74,15 +70,11 @@ final class UrlencodeViewHelper extends AbstractViewHelper * Escapes special characters with their escaped counterparts as needed using PHPs rawurlencode() function. * * @see https://www.php.net/manual/function.rawurlencode.php - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * * @return mixed */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { - $value = $renderChildrenClosure(); + $value = $arguments['value'] ?? $renderChildrenClosure(); if (!is_string($value) && !(is_object($value) && method_exists($value, '__toString'))) { return $value; } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php index 81aa186d9d22..b88dad895907 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -103,10 +105,7 @@ final class ImageViewHelper extends AbstractTagBasedViewHelper $this->imageService = GeneralUtility::makeInstance(ImageService::class); } - /** - * Initialize arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerUniversalTagAttributes(); @@ -134,14 +133,12 @@ final class ImageViewHelper extends AbstractTagBasedViewHelper } /** - * Resizes a given image (if required) and renders the respective img tag + * Resizes a given image (if required) and renders the respective img tag. * * @see https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Image/ - * * @throws Exception - * @return string Rendered tag */ - public function render() + public function render(): string { $src = (string)$this->arguments['src']; if (($src === '' && $this->arguments['image'] === null) || ($src !== '' && $this->arguments['image'] !== null)) { @@ -149,7 +146,11 @@ final class ImageViewHelper extends AbstractTagBasedViewHelper } if ((string)$this->arguments['fileExtension'] && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], (string)$this->arguments['fileExtension'])) { - throw new Exception('The extension ' . $this->arguments['fileExtension'] . ' is not specified in $GLOBALS[\'TYPO3_CONF_VARS\'][\'GFX\'][\'imagefile_ext\'] as a valid image file extension and can not be processed.', 1618989190); + throw new Exception( + 'The extension ' . $this->arguments['fileExtension'] . ' is not specified in $GLOBALS[\'TYPO3_CONF_VARS\'][\'GFX\'][\'imagefile_ext\']' + . ' as a valid image file extension and can not be processed.', + 1618989190 + ); } try { diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Link/EmailViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Link/EmailViewHelper.php index 0745342b3d15..6a685a31ba86 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Link/EmailViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Link/EmailViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -61,10 +63,7 @@ final class EmailViewHelper extends AbstractTagBasedViewHelper */ protected $tagName = 'a'; - /** - * Arguments initialization - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('email', 'string', 'The email address to be turned into a link', true); @@ -75,10 +74,7 @@ final class EmailViewHelper extends AbstractTagBasedViewHelper $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document'); } - /** - * @return string Rendered email link - */ - public function render() + public function render(): string { $email = $this->arguments['email']; if (ApplicationType::fromRequest($this->renderingContext->getRequest())->isFrontend()) { diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Link/ExternalViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Link/ExternalViewHelper.php index 26f89726c374..ed9121bea28d 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Link/ExternalViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Link/ExternalViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -52,10 +54,7 @@ final class ExternalViewHelper extends AbstractTagBasedViewHelper */ protected $tagName = 'a'; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('uri', 'string', 'The URI that will be put in the href attribute of the rendered link tag', true); @@ -67,10 +66,7 @@ final class ExternalViewHelper extends AbstractTagBasedViewHelper $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document'); } - /** - * @return string Rendered link - */ - public function render() + public function render(): string { $uri = $this->arguments['uri']; $defaultScheme = $this->arguments['defaultScheme']; diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Link/TypolinkViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Link/TypolinkViewHelper.php index f021b9de2b07..d7f47b4e5486 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Link/TypolinkViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Link/TypolinkViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -20,7 +22,6 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\Service\TypoLinkCodecService; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; -use TYPO3Fluid\Fluid\Core\ViewHelper\Exception; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** @@ -96,18 +97,13 @@ final class TypolinkViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize ViewHelper arguments - * - * @throws Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true); $this->registerArgument('target', 'string', 'Define where to display the linked URL', false, ''); $this->registerArgument('class', 'string', 'Define classes for the link element', false, ''); $this->registerArgument('title', 'string', 'Define the title for the link element', false, ''); - $this->registerArgument('language', 'string', 'link to a specific language - defaults to the current language, use a language ID or "current" to enforce a specific language', false, null); + $this->registerArgument('language', 'string', 'link to a specific language - defaults to the current language, use a language ID or "current" to enforce a specific language', false); $this->registerArgument('additionalParams', 'string', 'Additional query parameters to be attached to the resulting URL', false, ''); $this->registerArgument('additionalAttributes', 'array', 'Additional tag attributes to be added directly to the resulting HTML tag', false, []); $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URL', false, false); @@ -118,16 +114,10 @@ final class TypolinkViewHelper extends AbstractViewHelper } /** - * Render - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return mixed|string * @throws \InvalidArgumentException * @throws \UnexpectedValueException */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $parameter = $arguments['parameter'] ?? ''; $partsAs = $arguments['parts-as'] ?? 'typoLinkParts'; @@ -135,7 +125,7 @@ final class TypolinkViewHelper extends AbstractViewHelper $typoLinkCodec = GeneralUtility::makeInstance(TypoLinkCodecService::class); $typoLinkConfiguration = $typoLinkCodec->decode($parameter); // Merge the $parameter with other arguments - $mergedTypoLinkConfiguration = static::mergeTypoLinkConfiguration($typoLinkConfiguration, $arguments); + $mergedTypoLinkConfiguration = self::mergeTypoLinkConfiguration($typoLinkConfiguration, $arguments); $typoLinkParameter = $typoLinkCodec->encode($mergedTypoLinkConfiguration); // expose internal typoLink configuration to Fluid child context @@ -147,7 +137,7 @@ final class TypolinkViewHelper extends AbstractViewHelper $variableProvider->remove($partsAs); if ($parameter) { - $content = static::invokeContentObjectRenderer($arguments, $typoLinkParameter, $content); + $content = self::invokeContentObjectRenderer($arguments, $typoLinkParameter, $content); } return $content; } @@ -157,7 +147,7 @@ final class TypolinkViewHelper extends AbstractViewHelper $addQueryString = $arguments['addQueryString'] ?? false; $addQueryStringExclude = $arguments['addQueryStringExclude'] ?? ''; $absolute = $arguments['absolute'] ?? false; - $aTagParams = static::serializeTagParameters($arguments); + $aTagParams = self::serializeTagParameters($arguments); $instructions = [ 'parameter' => $typoLinkParameter, @@ -195,10 +185,6 @@ final class TypolinkViewHelper extends AbstractViewHelper /** * Merges view helper arguments with typolink parts. - * - * @param array $typoLinkConfiguration - * @param array $arguments - * @return array */ protected static function mergeTypoLinkConfiguration(array $typoLinkConfiguration, array $arguments): array { diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php index ba266003c967..59b822398341 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -73,10 +75,7 @@ final class MediaViewHelper extends AbstractTagBasedViewHelper */ protected $tagName = 'img'; - /** - * Initialize arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerUniversalTagAttributes(); @@ -92,12 +91,12 @@ final class MediaViewHelper extends AbstractTagBasedViewHelper } /** - * Render a given media file + * Render a given media file. * - * @return string Rendered tag * @throws \UnexpectedValueException + * @throws Exception */ - public function render() + public function render(): string { $file = $this->arguments['file']; $additionalConfig = (array)$this->arguments['additionalConfig']; @@ -115,7 +114,11 @@ final class MediaViewHelper extends AbstractTagBasedViewHelper } if ((string)$this->arguments['fileExtension'] && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], (string)$this->arguments['fileExtension'])) { - throw new Exception('The extension ' . $this->arguments['fileExtension'] . ' is not specified in $GLOBALS[\'TYPO3_CONF_VARS\'][\'GFX\'][\'imagefile_ext\'] as a valid image file extension and can not be processed.', 1619030957); + throw new Exception( + 'The extension ' . $this->arguments['fileExtension'] . ' is not specified in $GLOBALS[\'TYPO3_CONF_VARS\'][\'GFX\'][\'imagefile_ext\']' + . ' as a valid image file extension and can not be processed.', + 1619030957 + ); } $fileRenderer = GeneralUtility::makeInstance(RendererRegistry::class)->getRenderer($file); @@ -137,7 +140,7 @@ final class MediaViewHelper extends AbstractTagBasedViewHelper * @param string|null $fileExtension * @return string Rendered img tag */ - protected function renderImage(FileInterface $image, $width, $height, ?string $fileExtension) + protected function renderImage(FileInterface $image, $width, $height, ?string $fileExtension): string { $cropVariant = $this->arguments['cropVariant'] ?: 'default'; $cropString = $image instanceof FileReference ? $image->getProperty('crop') : ''; @@ -185,12 +188,7 @@ final class MediaViewHelper extends AbstractTagBasedViewHelper return $this->tag->render(); } - /** - * Return an instance of ImageService - * - * @return ImageService - */ - protected function getImageService() + protected function getImageService(): ImageService { return GeneralUtility::makeInstance(ImageService::class); } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/RenderViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/RenderViewHelper.php index fd3a961a126f..f26258945dd5 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/RenderViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/RenderViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -17,7 +19,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers; final class RenderViewHelper extends \TYPO3Fluid\Fluid\ViewHelpers\RenderViewHelper { - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('debug', 'boolean', 'If true, the admin panel shows debug information if activated,', false, true); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Sanitize/HtmlViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Sanitize/HtmlViewHelper.php index 91b8314f01b1..a13b4f5c5c4c 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Sanitize/HtmlViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Sanitize/HtmlViewHelper.php @@ -23,7 +23,6 @@ use TYPO3\HtmlSanitizer\Builder\BuilderInterface; use TYPO3\HtmlSanitizer\Sanitizer; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; -use TYPO3Fluid\Fluid\Core\ViewHelper\Exception; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** @@ -69,32 +68,22 @@ final class HtmlViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * @throws Exception - */ - public function initializeArguments() + public function initializeArguments(): void { - $this->registerArgument( - 'build', - 'string', - 'preset name or class-like name of sanitization builder', - false, - 'default' - ); + $this->registerArgument('build', 'string', 'preset name or class-like name of sanitization builder', false, 'default'); } /** * @param array{build: string|class-string} $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext - * - * @return string the parsed string. + * @return string */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $value = $renderChildrenClosure(); - $build = $arguments['build'] ?? 'default'; - return static::createSanitizer($build)->sanitize((string)$value); + $build = $arguments['build']; + return self::createSanitizer($build)->sanitize((string)$value); } protected static function createSanitizer(string $build): Sanitizer diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Security/IfAuthenticatedViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Security/IfAuthenticatedViewHelper.php index 6ad365a662ab..1e40347f32c1 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Security/IfAuthenticatedViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Security/IfAuthenticatedViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -56,13 +58,7 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper; */ final class IfAuthenticatedViewHelper extends AbstractConditionViewHelper { - /** - * This method decides if the condition is TRUE or FALSE. It can be overridden in extending viewhelpers to adjust functionality. - * - * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexibility in overriding this method. - * @return bool - */ - protected static function evaluateCondition($arguments = null) + protected static function evaluateCondition($arguments = null): bool { return GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.user', 'id', 0) > 0; } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Security/IfHasRoleViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Security/IfHasRoleViewHelper.php index 5e5c43cddaf3..b0cdda78febd 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Security/IfHasRoleViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Security/IfHasRoleViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -76,20 +78,13 @@ final class IfHasRoleViewHelper extends AbstractConditionViewHelper * Renders <f:then> child if the current logged in FE user belongs to the specified role (aka usergroup) * otherwise renders <f:else> child. */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); - $this->registerArgument('role', 'string', 'The usergroup (either the usergroup uid or its title).'); } - /** - * This method decides if the condition is TRUE or FALSE. It can be overridden in extending viewhelpers to adjust functionality. - * - * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexibility in overriding this method. - * @return bool - */ - protected static function evaluateCondition($arguments = null) + protected static function evaluateCondition($arguments = null): bool { $role = $arguments['role']; /** @var UserAspect $userAspect */ diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Transform/HtmlViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Transform/HtmlViewHelper.php index beecc0896a3e..b66288e91bd0 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Transform/HtmlViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Transform/HtmlViewHelper.php @@ -21,7 +21,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Html\HtmlWorker; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; -use TYPO3Fluid\Fluid\Core\ViewHelper\Exception as ViewHelperException; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** @@ -72,35 +71,19 @@ final class HtmlViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * @throws ViewHelperException - */ - public function initializeArguments() + public function initializeArguments(): void { - $this->registerArgument( - 'selector', - 'string', - 'comma separated list of node attributes to be considered', - false, - 'a.href' - ); - $this->registerArgument( - 'onFailure', - 'string', - 'behavior on failure, either `removeTag`, `removeAttr`, `removeEnclosure` or `null`', - false, - 'removeEnclosure' - ); + $this->registerArgument('selector', 'string', 'comma separated list of node attributes to be considered', false, 'a.href'); + $this->registerArgument('onFailure', 'string', 'behavior on failure, either `removeTag`, `removeAttr`, `removeEnclosure` or `null`', false, 'removeEnclosure'); } /** * @param array{selector: string} $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext - * * @return string transformed markup */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $content = $renderChildrenClosure(); $worker = GeneralUtility::makeInstance(HtmlWorker::class); diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ExternalViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ExternalViewHelper.php index 56cf2d2fc965..f02ade89d8e9 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ExternalViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ExternalViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -48,29 +50,16 @@ final class ExternalViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initialize arguments - * - * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('uri', 'string', 'target URI', true); $this->registerArgument('defaultScheme', 'string', 'scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already', false, 'https'); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string Rendered URI - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $uri = $arguments['uri']; $defaultScheme = $arguments['defaultScheme']; - $scheme = parse_url($uri, PHP_URL_SCHEME); if ($scheme === null && $defaultScheme !== '') { $uri = $defaultScheme . '://' . $uri; diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php index 9c3ad975b1b4..253f8dc684e2 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -86,10 +88,7 @@ final class ImageViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('src', 'string', 'src', false, ''); $this->registerArgument('treatIdAsReference', 'bool', 'given src argument is a sys_file_reference record', false, false); @@ -110,13 +109,9 @@ final class ImageViewHelper extends AbstractViewHelper /** * Resizes the image (if required) and returns its path. If the image was not resized, the path will be equal to $src * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string * @throws Exception */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $src = (string)$arguments['src']; $image = $arguments['image']; @@ -173,12 +168,7 @@ final class ImageViewHelper extends AbstractViewHelper } } - /** - * Return an instance of ImageService using object manager - * - * @return ImageService - */ - protected static function getImageService() + protected static function getImageService(): ImageService { return GeneralUtility::makeInstance(ImageService::class); } diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/TypolinkViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/TypolinkViewHelper.php index f682348a0558..2ef970e974d1 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/TypolinkViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/TypolinkViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -60,37 +62,28 @@ final class TypolinkViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true); $this->registerArgument('additionalParams', 'string', 'stdWrap.typolink additionalParams', false, ''); - $this->registerArgument('language', 'string', 'link to a specific language - defaults to the current language, use a language ID or "current" to enforce a specific language', false, null); + $this->registerArgument('language', 'string', 'link to a specific language - defaults to the current language, use a language ID or "current" to enforce a specific language', false); $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URL', false, false); $this->registerArgument('addQueryStringExclude', 'string', 'Define parameters to be excluded from the query string (only active if addQueryString is set)', false, ''); $this->registerArgument('absolute', 'bool', 'Ensure the resulting URL is an absolute URL', false, false); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $parameter = $arguments['parameter']; $typoLinkCodec = GeneralUtility::makeInstance(TypoLinkCodecService::class); $typoLinkConfiguration = $typoLinkCodec->decode($parameter); - $mergedTypoLinkConfiguration = static::mergeTypoLinkConfiguration($typoLinkConfiguration, $arguments); + $mergedTypoLinkConfiguration = self::mergeTypoLinkConfiguration($typoLinkConfiguration, $arguments); $typoLinkParameter = $typoLinkCodec->encode($mergedTypoLinkConfiguration); $content = ''; if ($parameter) { - $content = static::invokeContentObjectRenderer($arguments, $typoLinkParameter); + $content = self::invokeContentObjectRenderer($arguments, $typoLinkParameter); } return $content; } @@ -121,10 +114,6 @@ final class TypolinkViewHelper extends AbstractViewHelper /** * Merges view helper arguments with typolink parts. - * - * @param array $typoLinkConfiguration - * @param array $arguments - * @return array */ protected static function mergeTypoLinkConfiguration(array $typoLinkConfiguration, array $arguments): array { diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/ClickEnlargeViewHelper.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/ClickEnlargeViewHelper.php index 0424077021a7..384ab8dcd24c 100644 --- a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/ClickEnlargeViewHelper.php +++ b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/ClickEnlargeViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -47,10 +49,7 @@ final class ClickEnlargeViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize ViewHelper arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('image', FileInterface::class, 'The original image file', true); $this->registerArgument( @@ -61,18 +60,11 @@ final class ClickEnlargeViewHelper extends AbstractViewHelper ); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { + /** @var FileInterface $image */ $image = $arguments['image']; - if ($image instanceof FileInterface) { - self::getContentObjectRenderer()->setCurrentFile($image); - } + self::getContentObjectRenderer()->setCurrentFile($image); $objDataBackup = null; if ($renderingContext->getVariableProvider()->exists('data')) { @@ -83,24 +75,18 @@ final class ClickEnlargeViewHelper extends AbstractViewHelper $content = $renderChildrenClosure(); $configuration['enable'] = true; - $result = self::getContentObjectRenderer()->imageLinkWrap($content, $image, $configuration); + $result = self::getContentObjectRenderer()->imageLinkWrap((string)$content, $image, $configuration); if ($objDataBackup) { self::getContentObjectRenderer()->data = $objDataBackup; } return $result; } - /** - * @return ContentObjectRenderer - */ - protected static function getContentObjectRenderer() + protected static function getContentObjectRenderer(): ContentObjectRenderer { return $GLOBALS['TSFE']->cObj; } - /** - * @return TypoScriptService - */ protected static function getTypoScriptService(): TypoScriptService { return GeneralUtility::makeInstance(TypoScriptService::class); diff --git a/typo3/sysext/form/Classes/ViewHelpers/Be/MaximumFileSizeViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/Be/MaximumFileSizeViewHelper.php index 80466e965375..e9354ed8a51a 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/Be/MaximumFileSizeViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/Be/MaximumFileSizeViewHelper.php @@ -32,14 +32,7 @@ final class MaximumFileSizeViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - * @internal - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $maxUploadFileSize = GeneralUtility::getMaxUploadFileSize(); // format according to PHP formatting rules (K = kilobytes instead of kibibytes) diff --git a/typo3/sysext/form/Classes/ViewHelpers/Be/RenderContentElementPreviewViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/Be/RenderContentElementPreviewViewHelper.php index ded11e93d7c0..532af6dbff61 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/Be/RenderContentElementPreviewViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/Be/RenderContentElementPreviewViewHelper.php @@ -45,24 +45,12 @@ final class RenderContentElementPreviewViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize arguments. - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('contentElementUid', 'int', 'The uid of a content element'); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - * @internal - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $content = ''; $contentElementUid = $arguments['contentElementUid']; diff --git a/typo3/sysext/form/Classes/ViewHelpers/Form/DatePickerViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/Form/DatePickerViewHelper.php index 5abc4a5c13c0..f7e7f659586e 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/Form/DatePickerViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/Form/DatePickerViewHelper.php @@ -38,21 +38,13 @@ use TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper; */ final class DatePickerViewHelper extends AbstractFormFieldViewHelper { - /** * @var string */ protected $tagName = 'input'; - /** - * @var \TYPO3\CMS\Extbase\Property\PropertyMapper - */ - protected $propertyMapper; + protected PropertyMapper $propertyMapper; - /** - * @param \TYPO3\CMS\Extbase\Property\PropertyMapper $propertyMapper - * @internal - */ public function injectPropertyMapper(PropertyMapper $propertyMapper) { $this->propertyMapper = $propertyMapper; @@ -61,7 +53,7 @@ final class DatePickerViewHelper extends AbstractFormFieldViewHelper /** * Initialize the arguments. */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerTagAttribute('size', 'int', 'The size of the input field'); @@ -78,10 +70,8 @@ final class DatePickerViewHelper extends AbstractFormFieldViewHelper /** * Renders the text field, hidden field and required javascript - * - * @return string */ - public function render() + public function render(): string { $enableDatePicker = $this->arguments['enableDatePicker']; $dateFormat = $this->arguments['dateFormat']; @@ -128,17 +118,13 @@ final class DatePickerViewHelper extends AbstractFormFieldViewHelper $this->tag->addAttribute('id', $id); $this->setErrorClassAttribute(); - $content = ''; - $content .= $this->tag->render(); + $content = $this->tag->render(); $content .= '<input type="hidden" name="' . htmlspecialchars($name) . '[dateFormat]" value="' . htmlspecialchars($dateFormat) . '" />'; return $content; } - /** - * @return \DateTime|null - */ - protected function getSelectedDate() + protected function getSelectedDate(): ?\DateTime { /** @var FormRuntime $formRuntime */ $formRuntime = $this->renderingContext @@ -163,10 +149,6 @@ final class DatePickerViewHelper extends AbstractFormFieldViewHelper return null; } - /** - * @param string $dateFormat - * @return string - */ protected function convertDateFormatToDatePickerFormat(string $dateFormat): string { $replacements = [ diff --git a/typo3/sysext/form/Classes/ViewHelpers/Form/TimePickerViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/Form/TimePickerViewHelper.php index 0e1a571518fe..40a8502cd43c 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/Form/TimePickerViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/Form/TimePickerViewHelper.php @@ -33,32 +33,19 @@ use TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper; */ final class TimePickerViewHelper extends AbstractFormFieldViewHelper { - /** * @var string */ protected $tagName = 'select'; - /** - * @var \TYPO3\CMS\Extbase\Property\PropertyMapper - */ - protected $propertyMapper; + protected PropertyMapper $propertyMapper; - /** - * @param \TYPO3\CMS\Extbase\Property\PropertyMapper $propertyMapper - * @internal - */ public function injectPropertyMapper(PropertyMapper $propertyMapper) { $this->propertyMapper = $propertyMapper; } - /** - * Initialize the arguments. - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerTagAttribute('size', 'int', 'The size of the select field'); @@ -71,11 +58,9 @@ final class TimePickerViewHelper extends AbstractFormFieldViewHelper } /** - * Renders the select fields for hour & minute - * - * @return string + * Renders the select fields for hour & minute. */ - public function render() + public function render(): string { $name = $this->getName(); $this->registerFieldNameForFormTokenGeneration($name); @@ -85,7 +70,6 @@ final class TimePickerViewHelper extends AbstractFormFieldViewHelper $this->setErrorClassAttribute(); $content = ''; - if ($this->arguments['timeType'] === 'hour') { $content .= $this->buildHourSelector($date); } else { @@ -95,10 +79,7 @@ final class TimePickerViewHelper extends AbstractFormFieldViewHelper return $content; } - /** - * @return \DateTime|null - */ - protected function getSelectedDate() + protected function getSelectedDate(): ?\DateTime { /** @var FormRuntime $formRuntime */ $formRuntime = $this->renderingContext @@ -123,10 +104,6 @@ final class TimePickerViewHelper extends AbstractFormFieldViewHelper return null; } - /** - * @param \DateTime $date - * @return string - */ protected function buildHourSelector(\DateTime $date = null): string { $value = $date !== null ? $date->format('H') : null; @@ -142,10 +119,6 @@ final class TimePickerViewHelper extends AbstractFormFieldViewHelper return $hourSelector->render(); } - /** - * @param \DateTime $date - * @return string - */ protected function buildMinuteSelector(\DateTime $date = null): string { $value = $date !== null ? $date->format('i') : null; diff --git a/typo3/sysext/form/Classes/ViewHelpers/Form/UploadedResourceViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/Form/UploadedResourceViewHelper.php index ac0b2e39374e..2185a060d742 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/Form/UploadedResourceViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/Form/UploadedResourceViewHelper.php @@ -37,40 +37,20 @@ final class UploadedResourceViewHelper extends AbstractFormFieldViewHelper */ protected $tagName = 'input'; - /** - * @var HashService - */ - protected $hashService; + protected HashService $hashService; + protected PropertyMapper $propertyMapper; - /** - * @var \TYPO3\CMS\Extbase\Property\PropertyMapper - */ - protected $propertyMapper; - - /** - * @param HashService $hashService - * @internal - */ public function injectHashService(HashService $hashService) { $this->hashService = $hashService; } - /** - * @param \TYPO3\CMS\Extbase\Property\PropertyMapper $propertyMapper - * @internal - */ public function injectPropertyMapper(PropertyMapper $propertyMapper) { $this->propertyMapper = $propertyMapper; } - /** - * Initialize the arguments. - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('as', 'string', ''); @@ -81,10 +61,7 @@ final class UploadedResourceViewHelper extends AbstractFormFieldViewHelper $this->registerUniversalTagAttributes(); } - /** - * @return string - */ - public function render() + public function render(): string { $output = ''; @@ -135,10 +112,8 @@ final class UploadedResourceViewHelper extends AbstractFormFieldViewHelper /** * Return a previously uploaded resource. * Return NULL if errors occurred during property mapping for this property. - * - * @return FileReference|null */ - protected function getUploadedResource() + protected function getUploadedResource(): ?FileReference { if ($this->getMappingResultsForProperty()->hasErrors()) { return null; diff --git a/typo3/sysext/form/Classes/ViewHelpers/FormViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/FormViewHelper.php index 79951adbcad0..46e1f612805a 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/FormViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/FormViewHelper.php @@ -33,14 +33,13 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder; */ final class FormViewHelper extends FluidFormViewHelper { - /** * Renders hidden form fields for referrer information about * the current request. * * @return string Hidden fields with referrer information */ - protected function renderHiddenReferrerFields() + protected function renderHiddenReferrerFields(): string { $formRuntime = $this->getFormRuntime(); $prefix = $this->prefixFieldName($this->getFormObjectName()); @@ -62,11 +61,6 @@ final class FormViewHelper extends FluidFormViewHelper return $markup; } - /** - * @param string $name - * @param string $value - * @return string - */ protected function createHiddenInputElement(string $name, string $value): string { $tagBuilder = GeneralUtility::makeInstance(TagBuilder::class, 'input'); @@ -79,10 +73,8 @@ final class FormViewHelper extends FluidFormViewHelper /** * We do NOT return NULL as in this case, the Form ViewHelpers do not enter $objectAccessorMode. * However, we return the form identifier. - * - * @return string */ - protected function getFormObjectName() + protected function getFormObjectName(): string { return $this->getFormRuntime()->getFormDefinition()->getIdentifier(); } diff --git a/typo3/sysext/form/Classes/ViewHelpers/GridColumnClassAutoConfigurationViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/GridColumnClassAutoConfigurationViewHelper.php index 7d7431dfbd31..e3cd2bb7ba27 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/GridColumnClassAutoConfigurationViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/GridColumnClassAutoConfigurationViewHelper.php @@ -34,27 +34,13 @@ final class GridColumnClassAutoConfigurationViewHelper extends AbstractViewHelpe */ protected $escapeOutput = false; - /** - * Initialize the arguments. - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('element', RootRenderableInterface::class, 'A RootRenderableInterface instance', true); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string + { $formElement = $arguments['element']; $gridRowElement = $formElement->getParentRenderable(); diff --git a/typo3/sysext/form/Classes/ViewHelpers/RenderAllFormValuesViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/RenderAllFormValuesViewHelper.php index 92729aae0af1..e58fabfbd014 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/RenderAllFormValuesViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/RenderAllFormValuesViewHelper.php @@ -41,12 +41,7 @@ final class RenderAllFormValuesViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize the arguments. - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('renderable', RootRenderableInterface::class, 'A RootRenderableInterface instance', true); $this->registerArgument('as', 'string', 'The name within the template', false, 'formValue'); @@ -54,13 +49,8 @@ final class RenderAllFormValuesViewHelper extends AbstractViewHelper /** * Return array element by key. - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string the rendered form values */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $renderable = $arguments['renderable']; diff --git a/typo3/sysext/form/Classes/ViewHelpers/RenderFormValueViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/RenderFormValueViewHelper.php index 6ea03adad603..ab72270801b5 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/RenderFormValueViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/RenderFormValueViewHelper.php @@ -44,12 +44,7 @@ final class RenderFormValueViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize the arguments - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('renderable', RenderableInterface::class, 'A renderable element', true); $this->registerArgument('as', 'string', 'The name within the template', false, 'formValue'); @@ -57,13 +52,8 @@ final class RenderFormValueViewHelper extends AbstractViewHelper /** * Return array element by key - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string the rendered form values */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $element = $arguments['renderable']; @@ -95,23 +85,22 @@ final class RenderFormValueViewHelper extends AbstractViewHelper $as = $arguments['as']; $renderingContext->getVariableProvider()->add($as, $data); - $output = $renderChildrenClosure(); + $output = (string)$renderChildrenClosure(); $renderingContext->getVariableProvider()->remove($as); return $output; } /** - * Converts the given value to a simple type (string or array) considering the underlying FormElement definition + * Converts the given value to a simple type (string or array) considering the underlying FormElement definition. * * @param FormElementInterface $element * @param mixed $value * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return mixed - * @internal */ - public static function processElementValue( + protected static function processElementValue( FormElementInterface $element, $value, \Closure $renderChildrenClosure, @@ -119,7 +108,7 @@ final class RenderFormValueViewHelper extends AbstractViewHelper ) { $properties = $element->getProperties(); $options = $properties['options'] ?? null; - if ($options !== null && is_array($options)) { + if (is_array($options)) { $properties['options'] = TranslateElementPropertyViewHelper::renderStatic( ['element' => $element, 'property' => 'options'], $renderChildrenClosure, @@ -137,15 +126,11 @@ final class RenderFormValueViewHelper extends AbstractViewHelper } /** - * Replaces the given values (=keys) with the corresponding elements in $options - * @see mapValueToOption() + * Replaces the given values (=keys) with the corresponding elements in $options. * - * @param array $value - * @param array $options - * @return array - * @internal + * @see mapValueToOption() */ - public static function mapValuesToOptions(array $value, array $options): array + protected static function mapValuesToOptions(array $value, array $options): array { $result = []; foreach ($value as $key) { @@ -161,22 +146,20 @@ final class RenderFormValueViewHelper extends AbstractViewHelper * @param mixed $value * @param array $options * @return mixed - * @internal */ - public static function mapValueToOption($value, array $options) + protected static function mapValueToOption($value, array $options) { return $options[$value] ?? $value; } /** - * Converts the given $object to a string representation considering the $element FormElement definition + * Converts the given $object to a string representation considering the $element FormElement definition. * * @param FormElementInterface $element * @param object $object * @return string - * @internal */ - public static function processObject(FormElementInterface $element, $object): string + protected static function processObject(FormElementInterface $element, $object): string { if ($element instanceof StringableFormElementInterface) { return $element->valueToString($object); @@ -201,23 +184,16 @@ final class RenderFormValueViewHelper extends AbstractViewHelper return 'Object [' . get_class($object) . ']'; } - /** - * @param RenderableInterface $renderable - * @return bool - * @internal - */ - public static function isEnabled(RenderableInterface $renderable): bool + protected static function isEnabled(RenderableInterface $renderable): bool { if (!$renderable->isEnabled()) { return false; } - while ($renderable = $renderable->getParentRenderable()) { if ($renderable instanceof RenderableInterface && !$renderable->isEnabled()) { return false; } } - return true; } } diff --git a/typo3/sysext/form/Classes/ViewHelpers/RenderRenderableViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/RenderRenderableViewHelper.php index bf5a27f794ff..a0e112f689b1 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/RenderRenderableViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/RenderRenderableViewHelper.php @@ -46,26 +46,13 @@ final class RenderRenderableViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize the arguments. - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('renderable', RootRenderableInterface::class, 'A RenderableInterface instance', true); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - * @internal - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { - /** @var FormRuntime $formRuntime */ $formRuntime = $renderingContext ->getViewHelperVariableContainer() diff --git a/typo3/sysext/form/Classes/ViewHelpers/RenderViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/RenderViewHelper.php index 74e582396211..c1b6428d3193 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/RenderViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/RenderViewHelper.php @@ -54,26 +54,15 @@ final class RenderViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize the arguments. - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { - $this->registerArgument('persistenceIdentifier', 'string', 'The persistence identifier for the form.', false, null); + $this->registerArgument('persistenceIdentifier', 'string', 'The persistence identifier for the form.', false); $this->registerArgument('factoryClass', 'string', 'The fully qualified class name of the factory', false, ArrayFormFactory::class); - $this->registerArgument('prototypeName', 'string', 'Name of the prototype to use', false, null); + $this->registerArgument('prototypeName', 'string', 'Name of the prototype to use', false); $this->registerArgument('overrideConfiguration', 'array', 'factory specific configuration', false, []); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): ?string { $persistenceIdentifier = $arguments['persistenceIdentifier']; $factoryClass = $arguments['factoryClass']; diff --git a/typo3/sysext/form/Classes/ViewHelpers/TranslateElementErrorViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/TranslateElementErrorViewHelper.php index 1efbfd8b6272..f78bb210aa45 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/TranslateElementErrorViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/TranslateElementErrorViewHelper.php @@ -35,26 +35,13 @@ final class TranslateElementErrorViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initialize arguments. - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('element', RootRenderableInterface::class, 'Form Element to translate', true); $this->registerArgument('error', Error::class, 'Error', true); } - /** - * Return array element by key. - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $element = $arguments['element']; $error = $arguments['error']; diff --git a/typo3/sysext/form/Classes/ViewHelpers/TranslateElementPropertyViewHelper.php b/typo3/sysext/form/Classes/ViewHelpers/TranslateElementPropertyViewHelper.php index 7f30f69f9f4d..6bc08ca3112a 100644 --- a/typo3/sysext/form/Classes/ViewHelpers/TranslateElementPropertyViewHelper.php +++ b/typo3/sysext/form/Classes/ViewHelpers/TranslateElementPropertyViewHelper.php @@ -35,12 +35,7 @@ final class TranslateElementPropertyViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initialize arguments. - * - * @internal - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('element', RootRenderableInterface::class, 'Form Element to translate', true); $this->registerArgument('property', 'mixed', 'Property to translate', false); @@ -57,7 +52,7 @@ final class TranslateElementPropertyViewHelper extends AbstractViewHelper */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { - static::assertArgumentTypes($arguments); + self::assertArgumentTypes($arguments); $element = $arguments['element']; @@ -84,9 +79,6 @@ final class TranslateElementPropertyViewHelper extends AbstractViewHelper return GeneralUtility::makeInstance(TranslationService::class)->translateFormElementValue($element, $propertyParts, $formRuntime); } - /** - * @param array $arguments - */ protected static function assertArgumentTypes(array $arguments) { foreach (['property', 'renderingOptionProperty'] as $argumentName) { diff --git a/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/DateTimeViewHelper.php b/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/DateTimeViewHelper.php index 04feb0e752c0..29459ec80dae 100644 --- a/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/DateTimeViewHelper.php +++ b/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/DateTimeViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -21,7 +23,6 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** - * DateTime viewhelper * @internal */ final class DateTimeViewHelper extends AbstractViewHelper @@ -37,16 +38,10 @@ final class DateTimeViewHelper extends AbstractViewHelper protected $escapeChildren = false; /** - * Render the given timestamp as date & time - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string + * Render the given timestamp as date & time. */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { - return BackendUtility::datetime($renderChildrenClosure()); + return BackendUtility::datetime((int)$renderChildrenClosure()); } } diff --git a/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/FlagValueViewHelper.php b/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/FlagValueViewHelper.php index 7234b7499dfe..730f3fd56459 100644 --- a/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/FlagValueViewHelper.php +++ b/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/FlagValueViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -20,31 +22,21 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** - * FlagValue viewhelper * @internal */ final class FlagValueViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Sets up the needed arguments for this ViewHelper. - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('flags', 'int', '', true); } /** * Render additional flag information - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $flags = (int)$arguments['flags']; diff --git a/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/GroupListViewHelper.php b/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/GroupListViewHelper.php index 3260d74f5568..b86d2e1a14ae 100644 --- a/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/GroupListViewHelper.php +++ b/typo3/sysext/indexed_search/Classes/ViewHelpers/Format/GroupListViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -20,31 +22,21 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** - * Group list viewhelper * @internal */ final class GroupListViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('groups', 'array', '', false, []); } /** - * Render the given group information as string - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string + * Render the given group information as string. */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $groups = $arguments['groups']; diff --git a/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingResultsViewHelper.php b/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingResultsViewHelper.php index 345cb16ea0ee..834d35fffead 100644 --- a/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingResultsViewHelper.php +++ b/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingResultsViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -21,7 +23,8 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** - * renders the header of the results page + * Renders the header of the results page. + * * @internal */ final class PageBrowsingResultsViewHelper extends AbstractViewHelper @@ -35,23 +38,14 @@ final class PageBrowsingResultsViewHelper extends AbstractViewHelper */ protected $escapeOutput = false; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('numberOfResults', 'int', '', true); $this->registerArgument('resultsPerPage', 'int', '', true); $this->registerArgument('currentPage', 'int', '', false, 1); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $numberOfResults = $arguments['numberOfResults']; $resultsPerPage = $arguments['resultsPerPage']; diff --git a/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingViewHelper.php b/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingViewHelper.php index 0f26598d5b67..e5825dcbabe6 100644 --- a/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingViewHelper.php +++ b/typo3/sysext/indexed_search/Classes/ViewHelpers/PageBrowsingViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -21,10 +23,9 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; /** - * Page browser for indexed search, and only useful here, as the - * regular pagebrowser - * so this is a cleaner "pi_browsebox" but not a real page browser - * functionality + * Page browser for indexed search, and only useful here, as the regular pagebrowser. + * This is a cleaner "pi_browsebox" but not a real page browser functionality. + * * @internal */ final class PageBrowsingViewHelper extends AbstractTagBasedViewHelper @@ -39,10 +40,7 @@ final class PageBrowsingViewHelper extends AbstractTagBasedViewHelper */ protected $tagName = 'ul'; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('maximumNumberOfResultPages', 'int', '', true); $this->registerArgument('numberOfResults', 'int', '', true); @@ -52,10 +50,7 @@ final class PageBrowsingViewHelper extends AbstractTagBasedViewHelper $this->registerUniversalTagAttributes(); } - /** - * @inheritDoc - */ - public function render() + public function render(): string { $maximumNumberOfResultPages = $this->arguments['maximumNumberOfResultPages']; $numberOfResults = $this->arguments['numberOfResults']; diff --git a/typo3/sysext/install/Classes/ViewHelpers/Format/NoSpaceViewHelper.php b/typo3/sysext/install/Classes/ViewHelpers/Format/NoSpaceViewHelper.php index f025d9a831ca..9491430e0485 100644 --- a/typo3/sysext/install/Classes/ViewHelpers/Format/NoSpaceViewHelper.php +++ b/typo3/sysext/install/Classes/ViewHelpers/Format/NoSpaceViewHelper.php @@ -30,9 +30,6 @@ final class NoSpaceViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initialize arguments - */ public function initializeArguments(): void { parent::initializeArguments(); @@ -40,13 +37,7 @@ final class NoSpaceViewHelper extends AbstractViewHelper } /** - * Render a string with whitespaces stripped - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string + * Render a string with whitespaces stripped. */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { diff --git a/typo3/sysext/install/Classes/ViewHelpers/Format/PhpErrorCodeViewHelper.php b/typo3/sysext/install/Classes/ViewHelpers/Format/PhpErrorCodeViewHelper.php index a35a08103e6e..b8b499260feb 100644 --- a/typo3/sysext/install/Classes/ViewHelpers/Format/PhpErrorCodeViewHelper.php +++ b/typo3/sysext/install/Classes/ViewHelpers/Format/PhpErrorCodeViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -28,10 +30,7 @@ final class PhpErrorCodeViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * @var array - */ - protected static $levelNames = [ + protected static array $levelNames = [ E_ERROR => 'E_ERROR', E_WARNING => 'E_WARNING', E_PARSE => 'E_PARSE', @@ -49,24 +48,15 @@ final class PhpErrorCodeViewHelper extends AbstractViewHelper E_USER_DEPRECATED => 'E_USER_DEPRECATED', ]; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('phpErrorCode', 'int', '', true); } /** - * Render a readable string for PHP error code - * - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string + * Render a readable string for PHP error code. */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $phpErrorCode = (int)$arguments['phpErrorCode']; $levels = []; diff --git a/typo3/sysext/install/Classes/ViewHelpers/PhpInfoViewHelper.php b/typo3/sysext/install/Classes/ViewHelpers/PhpInfoViewHelper.php index 2940b9cd917c..68609bd4bee1 100644 --- a/typo3/sysext/install/Classes/ViewHelpers/PhpInfoViewHelper.php +++ b/typo3/sysext/install/Classes/ViewHelpers/PhpInfoViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -20,7 +22,8 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** - * Utility class for phpinfo() + * Utility ViewHelper for phpinfo() + * * @internal */ final class PhpInfoViewHelper extends AbstractViewHelper @@ -37,28 +40,15 @@ final class PhpInfoViewHelper extends AbstractViewHelper */ protected $escapeChildren = false; - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { - return self::removeAllHtmlOutsideBody( - self::changeHtmlToHtml5( - self::getPhpInfo() - ) - ); + return self::removeAllHtmlOutsideBody(self::changeHtmlToHtml5(self::getPhpInfo())); } /** - * Get information about PHP's configuration - * - * @return string HTML page with the configuration options + * Get information about PHP's configuration as HTML string */ - protected static function getPhpInfo() + protected static function getPhpInfo(): string { ob_start(); phpinfo(); @@ -66,31 +56,25 @@ final class PhpInfoViewHelper extends AbstractViewHelper } /** - * Remove all HTML outside the body tag from HTML string - * - * @param string $html Complete HTML markup for page - * @return string Content of the body tag + * Remove all HTML outside the body tag from HTML string. */ - protected static function removeAllHtmlOutsideBody($html) + protected static function removeAllHtmlOutsideBody(string $html): string { - // Delete anything outside of the body tag and the body tag itself + // Delete anything outside the body tag and the body tag itself $html = (string)preg_replace('/^.*?<body.*?>/is', '', $html); - $html = (string)preg_replace('/<\/body>.*?$/is', '', $html); - - return $html; + return (string)preg_replace('/<\/body>.*?$/is', '', $html); } /** - * Change HTML markup to HTML5 + * Change HTML markup to HTML5. * * @param string $html HTML markup to be cleaned * @return string */ - protected static function changeHtmlToHtml5($html) + protected static function changeHtmlToHtml5(string $html): string { // Delete obsolete attributes $html = (string)preg_replace('#\s(cellpadding|border|width)="[^"]+"#', '', $html); - // Replace font tag with span return str_replace(['<font', '</font>'], ['<span', '</span>'], $html); } diff --git a/typo3/sysext/install/Classes/ViewHelpers/Uri/ActionViewHelper.php b/typo3/sysext/install/Classes/ViewHelpers/Uri/ActionViewHelper.php index 32ed009ac664..79eb63a577d4 100644 --- a/typo3/sysext/install/Classes/ViewHelpers/Uri/ActionViewHelper.php +++ b/typo3/sysext/install/Classes/ViewHelpers/Uri/ActionViewHelper.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -32,16 +34,14 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; * <output> * install.php?install[controller]=Maintenance&install[context]= * </output> + * * @internal */ final class ActionViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initialize arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('controller', 'string', 'Target controller.', false, 'maintenance'); $this->registerArgument('arguments', 'array', 'Arguments', false, []); @@ -49,13 +49,7 @@ final class ActionViewHelper extends AbstractViewHelper $this->registerArgument('additionalParams', 'array', 'additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)', false, []); } - /** - * @param array $arguments - * @param \Closure $renderChildrenClosure - * @param RenderingContextInterface $renderingContext - * @return string - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string { $section = $arguments['section']; $additionalParams = $arguments['additionalParams']; diff --git a/typo3/sysext/redirects/Classes/ViewHelpers/TargetPageIdViewHelper.php b/typo3/sysext/redirects/Classes/ViewHelpers/TargetPageIdViewHelper.php index 4687f36a14f0..2f60f4f06dec 100644 --- a/typo3/sysext/redirects/Classes/ViewHelpers/TargetPageIdViewHelper.php +++ b/typo3/sysext/redirects/Classes/ViewHelpers/TargetPageIdViewHelper.php @@ -28,16 +28,14 @@ use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** * The target of a redirect can contain a t3://page link. * This ViewHelper checks for such a case and returns the Page ID + * * @internal */ final class TargetPageIdViewHelper extends AbstractViewHelper { use CompileWithRenderStatic; - /** - * Initializes the arguments - */ - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('target', 'string', 'The target of the redirect.', true); } -- GitLab