From 3a7abf9a73e4a875e6f76170d6ea59839d2b5d1a Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Fri, 10 May 2024 19:43:56 +0200 Subject: [PATCH] Fix code quality tools annotations --- Classes/Command/ContentElementCommand.php | 5 +- .../IsContentUsedOnPageLayout.php | 25 ---------- Classes/Form/Element/PickColorFromImage.php | 5 +- Classes/Hooks/PageLayoutView.php | 34 -------------- Classes/Hooks/UsercentricsPostRenderHook.php | 46 +++++++++++-------- .../GridelementsToContainerService.php | 3 +- Classes/User/AssetPath.php | 2 +- .../ViewHelpers/Array/ExplodeViewHelper.php | 25 +++++----- Classes/ViewHelpers/HashViewHelper.php | 11 ++--- Classes/ViewHelpers/SvgViewHelper.php | 46 ++++++++++++++++--- Classes/Xclass/SiteDatabaseEditRow.php | 2 +- Configuration/Services.yaml | 3 -- Configuration/Sets/EwBase/config.yaml | 2 + .../Sets/EwBase/settings.definitions.yaml | 33 +++++++++++++ Configuration/Sets/EwBase/settings.yaml | 22 +++++++++ ext_localconf.php | 22 --------- 16 files changed, 144 insertions(+), 142 deletions(-) delete mode 100755 Classes/EventListener/IsContentUsedOnPageLayout.php delete mode 100755 Classes/Hooks/PageLayoutView.php create mode 100644 Configuration/Sets/EwBase/config.yaml create mode 100644 Configuration/Sets/EwBase/settings.definitions.yaml create mode 100644 Configuration/Sets/EwBase/settings.yaml diff --git a/Classes/Command/ContentElementCommand.php b/Classes/Command/ContentElementCommand.php index 488b022..d59a5c8 100755 --- a/Classes/Command/ContentElementCommand.php +++ b/Classes/Command/ContentElementCommand.php @@ -28,11 +28,8 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; class ContentElementCommand extends Command { - protected ConnectionPool $connectionPool; - - public function __construct(ConnectionPool $connectionPool) + public function __construct(protected ConnectionPool $connectionPool) { - $this->connectionPool = $connectionPool; parent::__construct(); } diff --git a/Classes/EventListener/IsContentUsedOnPageLayout.php b/Classes/EventListener/IsContentUsedOnPageLayout.php deleted file mode 100755 index dbf6175..0000000 --- a/Classes/EventListener/IsContentUsedOnPageLayout.php +++ /dev/null @@ -1,25 +0,0 @@ -setUsed($event->isRecordUsed() || $this->findCTypeBegin($event->getRecord()['CType'])); - } - - public function findCTypeBegin($cType): bool - { - $found = false; - foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['ContentUsedStrings'] ?? [] as $search) { - if (str_contains($cType, $search)) { - $found = true; - break; - } - } - return $found; - } -} diff --git a/Classes/Form/Element/PickColorFromImage.php b/Classes/Form/Element/PickColorFromImage.php index e9e2e4e..98c5df9 100755 --- a/Classes/Form/Element/PickColorFromImage.php +++ b/Classes/Form/Element/PickColorFromImage.php @@ -120,9 +120,6 @@ class PickColorFromImage extends AbstractFormElement private readonly HashService $hashService, ) {} - /** - * @throws InvalidConfigurationException - */ public function render(): array { $resultArray = $this->initializeResultArray(); @@ -238,7 +235,7 @@ class PickColorFromImage extends AbstractFormElement $cropVariant['allowedAspectRatios'] = array_filter( $cropVariant['allowedAspectRatios'] ?? [], static function ($aspectRatio) { - return !(bool)($aspectRatio['disabled'] ?? false); + return !($aspectRatio['disabled'] ?? false); } ); diff --git a/Classes/Hooks/PageLayoutView.php b/Classes/Hooks/PageLayoutView.php deleted file mode 100755 index 608ccf1..0000000 --- a/Classes/Hooks/PageLayoutView.php +++ /dev/null @@ -1,34 +0,0 @@ -findCTypeBegin($params['record']['CType']); - } - - public function findCTypeBegin($cType): bool - { - $found = false; - foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['ContentUsedStrings'] ?? [] as $search) { - if (str_contains($cType, $search)) { - $found = true; - break; - } - } - return $found; - } -} diff --git a/Classes/Hooks/UsercentricsPostRenderHook.php b/Classes/Hooks/UsercentricsPostRenderHook.php index adf37f0..da1304e 100755 --- a/Classes/Hooks/UsercentricsPostRenderHook.php +++ b/Classes/Hooks/UsercentricsPostRenderHook.php @@ -15,10 +15,9 @@ namespace Evoweb\EwBase\Hooks; use Exception; use Psr\Http\Message\ServerRequestInterface; -use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Core\Environment; +use TYPO3\CMS\Core\Site\Entity\Site; use TYPO3\CMS\Core\Site\SiteFinder; -use TYPO3\CMS\Core\Utility\GeneralUtility; class UsercentricsPostRenderHook { @@ -28,6 +27,12 @@ class UsercentricsPostRenderHook 'useBlocker' => false, ]; + protected ?Site $site = null; + + public function __construct(protected SiteFinder $siteFinder) + { + } + public function executePostRenderHook(array $params): void { $pageUid = $this->getRequest()->getAttribute('frontend.controller')->page['uid'] ?? 0; @@ -38,16 +43,16 @@ class UsercentricsPostRenderHook $siteArguments = $this->getCurrentSiteArguments($pageUid); $id = $siteArguments['id'] ?? ''; if ($id !== '') { - $extensionConfig = $this->getExtensionConfiguration(); + $extensionConfig = $this->getExtensionConfiguration($pageUid); $preload = []; - $usercentrics = []; + $userCentrics = []; // CMP 1, 2, ... $version = $siteArguments['version'] ?? ''; if ($config = $extensionConfig[$version] ?? false) { $preload[] = $config['preload'] ?? ''; - $usercentrics[] = $config['template'] ?? ''; + $userCentrics[] = $config['template'] ?? ''; } // Blocker @@ -56,10 +61,10 @@ class UsercentricsPostRenderHook && $config = $extensionConfig['block'] ?? false ) { $preload[] = $config['preload'] ?? ''; - $usercentrics[] = $config['template'] ?? ''; + $userCentrics[] = $config['template'] ?? ''; } - $params['titleTag'] .= str_replace('###ID###', $id, implode(LF, array_merge($preload, $usercentrics))); + $params['titleTag'] .= str_replace('###ID###', $id, implode(LF, array_merge($preload, $userCentrics))); } } @@ -67,10 +72,8 @@ class UsercentricsPostRenderHook { $siteArguments = $this->siteArguments; + $site = $this->getSiteByPageUid($pageUid); try { - /** @var SiteFinder $siteFinder */ - $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); - $site = $siteFinder->getSiteByPageId($pageUid); foreach ($site->getAttribute('usercentrics') as $usercentrics) { if (str_contains($usercentrics['applicationContext'] ?? '', (string)Environment::getContext())) { $siteArguments = $usercentrics; @@ -78,21 +81,28 @@ class UsercentricsPostRenderHook } } } catch (Exception) { + $siteArguments = []; } return is_array($siteArguments) ? $siteArguments : []; } - protected function getExtensionConfiguration(): array + protected function getExtensionConfiguration($pageUid): array { - /** @var ExtensionConfiguration $extensionConfiguration */ - $extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class); - try { - $configuration = $extensionConfiguration->get('ew_base', 'userCentrics'); - } catch (Exception) { - $configuration = []; + $siteSettings = $this->getSiteByPageUid($pageUid)->getSettings(); + $configuration = $siteSettings->has('ew-base') ? $siteSettings->get('ew-base') : []; + return is_array($configuration['userCentrics'] ?? false) ? $configuration['userCentrics'] : []; + } + + protected function getSiteByPageUid(int $pageUid): Site + { + if (!$this->site) { + try { + $this->site = $this->siteFinder->getSiteByPageId($pageUid); + } catch (Exception) { + } } - return is_array($configuration) ? $configuration : []; + return $this->site; } protected function getRequest(): ServerRequestInterface diff --git a/Classes/Updates/GridelementsToContainerService.php b/Classes/Updates/GridelementsToContainerService.php index 4b0cdac..7a8f70d 100755 --- a/Classes/Updates/GridelementsToContainerService.php +++ b/Classes/Updates/GridelementsToContainerService.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Evoweb\EwBase\Updates; +use Doctrine\DBAL\ParameterType; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; @@ -227,7 +228,7 @@ class GridelementsToContainerService ->where( $queryBuilder->expr()->eq( 'tx_gridelements_container', - $queryBuilder->createNamedParameter($containerUid, \PDO::PARAM_INT) + $queryBuilder->createNamedParameter($containerUid, ParameterType::INTEGER) ) ) ->orderBy('sorting') diff --git a/Classes/User/AssetPath.php b/Classes/User/AssetPath.php index 45b94f4..4b047ba 100755 --- a/Classes/User/AssetPath.php +++ b/Classes/User/AssetPath.php @@ -17,6 +17,6 @@ class AssetPath { public function getAbsolutePublicPath(string $content, array $conf): string { - return PathUtility::getAbsoluteWebPath($conf['file']); + return $content . PathUtility::getAbsoluteWebPath($conf['file']); } } diff --git a/Classes/ViewHelpers/Array/ExplodeViewHelper.php b/Classes/ViewHelpers/Array/ExplodeViewHelper.php index 364d39e..1757334 100755 --- a/Classes/ViewHelpers/Array/ExplodeViewHelper.php +++ b/Classes/ViewHelpers/Array/ExplodeViewHelper.php @@ -35,14 +35,14 @@ class ExplodeViewHelper extends AbstractViewHelper $this->registerArgument( 'as', 'string', - 'Template variable name to assign; if not specified the ViewHelper returns the variable instead.' + 'Template variable name to assign; if not specified the ViewHelper returns the variable instead.', ); $this->registerArgument('content', 'string', 'String to be exploded by glue'); $this->registerArgument( 'glue', 'string', - 'String used as glue in the string to be exploded. Use glue value of "constant:NAMEOFCONSTANT" ' . - '(fx "constant:LF" for linefeed as glue)', + 'String used as glue in the string to be exploded. Use glue value of "constant:NAMEOFCONSTANT" ' + . '(fx "constant:LF" for linefeed as glue)', false, ',' ); @@ -58,13 +58,13 @@ class ExplodeViewHelper extends AbstractViewHelper $content = call_user_func_array(static::$method, [$glue, $content]); $as = $arguments['as']; - if (true === empty($as)) { - $output = $content; - } else { + if ($as !== null) { $templateVariableContainer = $renderingContext->getVariableProvider(); $templateVariableContainer->add($as, $content); $output = $renderChildrenClosure(); $templateVariableContainer->remove($as); + } else { + $output = $content; } return $output; } @@ -72,16 +72,13 @@ class ExplodeViewHelper extends AbstractViewHelper protected static function resolveGlue(array $arguments): string { $glue = $arguments['glue']; - if (false !== strpos($glue, ':') && 1 < strlen($glue)) { + if (str_contains($glue, ':') && 1 < strlen($glue)) { // glue contains a special type identifier, resolve the actual glue list ($type, $value) = explode(':', $glue); - switch ($type) { - case 'constant': - $glue = constant($value); - break; - default: - $glue = $value; - } + $glue = match ($type) { + 'constant' => constant($value), + default => $value, + }; } return $glue; } diff --git a/Classes/ViewHelpers/HashViewHelper.php b/Classes/ViewHelpers/HashViewHelper.php index 6eb11fc..ebd997c 100755 --- a/Classes/ViewHelpers/HashViewHelper.php +++ b/Classes/ViewHelpers/HashViewHelper.php @@ -14,7 +14,6 @@ namespace Evoweb\EwBase\ViewHelpers; */ use TYPO3\CMS\Core\Crypto\HashService; -use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; @@ -47,13 +46,9 @@ class HashViewHelper extends AbstractViewHelper && $arguments['arguments'] !== null && isset($arguments['arguments']['user']) ) { - if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 13) { - $result = GeneralUtility::hmac($arguments['action'] . '::' . $arguments['arguments']['user']); - } else { - /** @var HashService $hashService */ - $hashService = GeneralUtility::makeInstance(HashService::class); - $result = $hashService->hmac($arguments['action'] . '::' . $arguments['arguments']['user'], ''); - } + /** @var HashService $hashService */ + $hashService = GeneralUtility::makeInstance(HashService::class); + $result = $hashService->hmac($arguments['action'] . '::' . $arguments['arguments']['user'], ''); } return $result; diff --git a/Classes/ViewHelpers/SvgViewHelper.php b/Classes/ViewHelpers/SvgViewHelper.php index b3e5c76..2281ae1 100755 --- a/Classes/ViewHelpers/SvgViewHelper.php +++ b/Classes/ViewHelpers/SvgViewHelper.php @@ -15,7 +15,8 @@ namespace Evoweb\EwBase\ViewHelpers; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; -use TYPO3\CMS\Core\Type\Icon\IconState; +use TYPO3\CMS\Core\Imaging\IconSize; +use TYPO3\CMS\Core\Imaging\IconState; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; @@ -75,11 +76,42 @@ class SvgViewHelper extends AbstractViewHelper 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, ''); - $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, ''); + $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, + IconSize::SMALL + ); + $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, + '' + ); } public static function renderStatic( @@ -90,7 +122,7 @@ class SvgViewHelper extends AbstractViewHelper $identifier = $arguments['identifier']; $size = $arguments['size']; $overlay = $arguments['overlay']; - $state = IconState::cast($arguments['state']); + $state = IconState::tryFrom($arguments['state']); $alternativeMarkupIdentifier = $arguments['alternativeMarkupIdentifier']; $iconFactory = GeneralUtility::makeInstance(IconFactory::class); return $iconFactory->getIcon($identifier, $size, $overlay, $state)->getMarkup($alternativeMarkupIdentifier); diff --git a/Classes/Xclass/SiteDatabaseEditRow.php b/Classes/Xclass/SiteDatabaseEditRow.php index 93fae38..7b184ba 100755 --- a/Classes/Xclass/SiteDatabaseEditRow.php +++ b/Classes/Xclass/SiteDatabaseEditRow.php @@ -37,7 +37,7 @@ class SiteDatabaseEditRow extends BaseSiteDatabaseEditRow } $rowData = $rowData[$parentFieldName][$result['vanillaUid']]; $result['databaseRow']['uid'] = $result['vanillaUid']; - } catch (SiteNotFoundException $e) { + } catch (SiteNotFoundException) { $rowData = []; } } else { diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 8050c5b..7654eb3 100755 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -20,9 +20,6 @@ services: Evoweb\EwBase\EventListener\JsMerger: tags: ['event.listener'] - Evoweb\EwBase\EventListener\IsContentUsedOnPageLayout: - tags: ['event.listener'] - Evoweb\EwBase\ToolbarItems\ReleaseToolbarItem: tags: ['backend.toolbar.item'] diff --git a/Configuration/Sets/EwBase/config.yaml b/Configuration/Sets/EwBase/config.yaml new file mode 100644 index 0000000..81addb3 --- /dev/null +++ b/Configuration/Sets/EwBase/config.yaml @@ -0,0 +1,2 @@ +name: evoweb/ew-base +label: evoWeb base package diff --git a/Configuration/Sets/EwBase/settings.definitions.yaml b/Configuration/Sets/EwBase/settings.definitions.yaml new file mode 100644 index 0000000..31732ee --- /dev/null +++ b/Configuration/Sets/EwBase/settings.definitions.yaml @@ -0,0 +1,33 @@ +settings: + ew-base.userCentrics.loader.preload: + default: '' + label: 'UserCentrics loader preloader' + type: string + description: 'Preloader for loader' + ew-base.userCentrics.loader.template: + default: '' + label: 'UserCentrics loader template' + type: string + description: 'Template for loader' + + ew-base.userCentrics.main.preload: + default: '' + label: 'UserCentrics main preloader' + type: string + description: 'Preloader for main' + ew-base.userCentrics.main.template: + default: '' + label: 'UserCentrics main template' + type: string + description: 'Template for main' + + ew-base.userCentrics.block.preload: + default: '' + label: 'UserCentrics block preloader' + type: string + description: 'Preloader for block' + ew-base.userCentrics.block.template: + default: '' + label: 'UserCentrics block template' + type: string + description: 'Template for block' diff --git a/Configuration/Sets/EwBase/settings.yaml b/Configuration/Sets/EwBase/settings.yaml new file mode 100644 index 0000000..a40b5a9 --- /dev/null +++ b/Configuration/Sets/EwBase/settings.yaml @@ -0,0 +1,22 @@ +ew-base: + userCentrics: + loader: + preload: | + + + + template: | + + main: + preload: | + + + + + template: | + + block: + preload: | + + template: | + diff --git a/ext_localconf.php b/ext_localconf.php index 5fd1db4..cca6d61 100755 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -12,8 +12,6 @@ use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseParentPageRow; use TYPO3\CMS\Backend\Form\FormDataProvider\SiteDatabaseEditRow as BaseSiteDatabaseEditRow; use TYPO3\CMS\Backend\Form\FormDataProvider\SiteTcaInline as BaseSiteTcaInline; use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSiteLanguage; -use TYPO3\CMS\Core\Information\Typo3Version; -use TYPO3\CMS\Core\Utility\GeneralUtility; call_user_func(function () { $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['ewb'] = [ 'Evoweb\\EwBase\\ViewHelpers' ]; @@ -46,24 +44,4 @@ call_user_func(function () { 'depends' => [ BaseSiteTcaInline::class ], 'before' => [ TcaSiteLanguage::class ], ]; - - if (empty($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics'] ?? [])) { - $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['loader']['preload'] = - ' - -'; - $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['loader']['template'] = - ''; - $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['main']['preload'] = - ' - - -'; - $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['main']['template'] = - ''; - $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['block']['preload'] = - ''; - $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['block']['template'] = - ''; - } });