Fix code quality tools annotations

This commit is contained in:
Sebastian Fischer 2024-05-10 19:43:56 +02:00
parent 6cd429c808
commit 3a7abf9a73
16 changed files with 144 additions and 142 deletions

View File

@ -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();
}

View File

@ -1,25 +0,0 @@
<?php
namespace Evoweb\EwBase\EventListener;
use TYPO3\CMS\Backend\View\Event\IsContentUsedOnPageLayoutEvent;
class IsContentUsedOnPageLayout
{
public function __invoke(IsContentUsedOnPageLayoutEvent $event): void
{
$event->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;
}
}

View File

@ -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);
}
);

View File

@ -1,34 +0,0 @@
<?php
namespace Evoweb\EwBase\Hooks;
/*
* This file is developed by evoWeb.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
class PageLayoutView
{
public function contentIsUsed(array $params): bool
{
return $params['used'] || $this->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;
}
}

View File

@ -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

View File

@ -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')

View File

@ -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']);
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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 {

View File

@ -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']

View File

@ -0,0 +1,2 @@
name: evoweb/ew-base
label: evoWeb base package

View File

@ -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'

View File

@ -0,0 +1,22 @@
ew-base:
userCentrics:
loader:
preload: |
<link rel="preconnect" href="//app.usercentrics.eu">
<link rel="preconnect" href="//privacy-proxy.usercentrics.eu">
<link rel="preload" href="//app.usercentrics.eu/browser-ui/latest/loader.js" as="script">
template: |
<script src="//app.usercentrics.eu/browser-ui/latest/loader.js" data-settings-id="###ID###" id="usercentrics-cmp" async></script>
main:
preload: |
<link rel="preconnect" href="//app.usercentrics.eu">
<link rel="preconnect" href="//api.usercentrics.eu">
<link rel="preconnect" href="//privacy-proxy.usercentrics.eu">
<link rel="preload" href="//app.usercentrics.eu/latest/main.js" as="script">
template: |
<script src="//app.usercentrics.eu/latest/main.js" id="###ID###" type="application/javascript"></script>
block:
preload: |
<link rel="preload" href="//privacy-proxy.usercentrics.eu/latest/uc-block.bundle.js" as="script">
template: |
<script type="application/javascript" src="https://privacy-proxy.usercentrics.eu/latest/uc-block.bundle.js"></script>

View File

@ -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'] =
'<link rel="preconnect" href="//app.usercentrics.eu">
<link rel="preconnect" href="//privacy-proxy.usercentrics.eu">
<link rel="preload" href="//app.usercentrics.eu/browser-ui/latest/loader.js" as="script">';
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['loader']['template'] =
'<script src="//app.usercentrics.eu/browser-ui/latest/loader.js" data-settings-id="###ID###" id="usercentrics-cmp" async></script>';
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['main']['preload'] =
'<link rel="preconnect" href="//app.usercentrics.eu">
<link rel="preconnect" href="//api.usercentrics.eu">
<link rel="preconnect" href="//privacy-proxy.usercentrics.eu">
<link rel="preload" href="//app.usercentrics.eu/latest/main.js" as="script">';
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['main']['template'] =
'<script src="//app.usercentrics.eu/latest/main.js" id="###ID###" type="application/javascript"></script>';
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['block']['preload'] =
'<link rel="preload" href="//privacy-proxy.usercentrics.eu/latest/uc-block.bundle.js" as="script">';
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['ew_base']['userCentrics']['block']['template'] =
'<script type="application/javascript" src="https://privacy-proxy.usercentrics.eu/latest/uc-block.bundle.js"></script>';
}
});