From a36b01a8aacdfbe16f7f9c39ec08838694686cf4 Mon Sep 17 00:00:00 2001 From: Ingo Pfennigstorf Date: Thu, 27 Feb 2025 14:58:36 +0100 Subject: [PATCH] Fix code for TYPO3 12 --- .github/workflows/ci.yml | 4 +- .php-cs-fixer.php | 10 +- .php-version | 2 +- Classes/Controller/SearchController.php | 24 +-- Classes/Hooks/RealUrl.php | 74 ------- Classes/Service/AbstractServiceProvider.php | 5 +- Classes/Service/ServiceProviderInterface.php | 37 +--- Classes/Service/SolrServiceProvider.php | 189 +++++++----------- Classes/Utility/ArrayUtility.php | 11 +- Classes/Utility/FrontendUtility.php | 12 +- Classes/Utility/LoggerUtility.php | 6 +- Classes/Utility/SettingsUtility.php | 4 +- Classes/Utility/UpgradeUtility.php | 2 +- .../ViewHelpers/Data/ArrayFirstViewHelper.php | 19 +- .../ViewHelpers/Data/IsArrayViewHelper.php | 16 +- .../ViewHelpers/Data/NewArrayViewHelper.php | 56 +++--- Classes/ViewHelpers/Data/SplitViewHelper.php | 28 +-- .../ViewHelpers/Data/TransposeViewHelper.php | 49 ++--- .../Data/ValueForKeyViewHelper.php | 12 +- .../Find/FacetIsActiveViewHelper.php | 34 ++-- .../Find/FacetLinkArgumentsViewHelper.php | 39 ++-- .../Find/HighlightFieldViewHelper.php | 106 +++++----- .../Find/LocalizedFacetDataViewHelper.php | 27 +-- .../ViewHelpers/Find/PageListViewHelper.php | 32 +-- .../PageNumberForResultNumberViewHelper.php | 22 +- .../ViewHelpers/Find/PathExistsViewHelper.php | 18 +- .../Find/SelectOptionsForFacetViewHelper.php | 59 +++--- .../ViewHelpers/Format/CSVLineViewHelper.php | 24 +-- .../Format/FieldContentViewHelper.php | 18 +- Classes/ViewHelpers/Format/JoinViewHelper.php | 33 ++- Classes/ViewHelpers/Format/JsonViewHelper.php | 21 +- .../ViewHelpers/Format/RegexpViewHelper.php | 51 +++-- .../Format/SolrEscapeViewHelper.php | 24 +-- .../ViewHelpers/Format/StripViewHelper.php | 44 ++-- Classes/ViewHelpers/Format/XMLViewHelper.php | 20 +- .../LinkedData/ContainerViewHelper.php | 36 ++-- .../ViewHelpers/LinkedData/ItemViewHelper.php | 46 ++--- .../LinkedData/Renderer/AbstractRenderer.php | 17 +- .../LinkedData/Renderer/JSONLDRenderer.php | 24 +-- .../LinkedData/Renderer/RDFRenderer.php | 38 ++-- .../LinkedData/Renderer/RendererInterface.php | 8 - .../LinkedData/Renderer/TurtleRenderer.php | 56 +++--- Classes/ViewHelpers/Logic/AndViewHelper.php | 22 +- Classes/ViewHelpers/Logic/NotViewHelper.php | 15 +- Classes/ViewHelpers/Logic/OrViewHelper.php | 22 +- .../ViewHelpers/Page/LinkCSSViewHelper.php | 46 ++--- Classes/ViewHelpers/Page/ScriptViewHelper.php | 74 ++----- Classes/ViewHelpers/Page/TitleViewHelper.php | 26 +-- .../Solr/CountFromSolrViewHelper.php | 45 ++--- .../Unit/Controller/SearchControllerTest.php | 57 ------ .../Unit/Service/SolrServiceProviderTest.php | 79 -------- Tests/Unit/Utility/UpgradeUtilityTest.php | 10 +- .../Data/ArrayFirstViewHelperTest.php | 26 +-- .../Data/IsArrayViewHelperTest.php | 26 +-- .../Data/NewArrayViewHelperTest.php | 44 ++-- .../ViewHelpers/Data/SplitViewHelperTest.php | 29 +-- .../Data/TransposeViewHelperTest.php | 36 +--- .../Data/ValueForKeyViewHelperTest.php | 28 +-- .../Find/FacetIsActiveViewHelperTest.php | 14 +- .../Find/FacetLinkArgumentsViewHelperTest.php | 18 +- .../Find/HighlightFieldViewHelperTest.php | 62 ------ ...ageNumberForResultNumberViewHelperTest.php | 33 +-- .../Find/PathExistsViewHelperTest.php | 76 ------- .../SelectOptionsForFacetViewHelperTest.php | 15 +- .../Format/CSVLineViewHelperTest.php | 34 ++-- .../ViewHelpers/Format/JoinViewHelperTest.php | 30 +-- .../Format/RegexpViewHelperTest.php | 30 ++- .../Format/StripViewHelperTest.php | 25 +-- .../ViewHelpers/Format/XMLViewHelperTest.php | 24 +-- .../LinkedData/ItemViewHelperTest.php | 54 ++--- .../ViewHelpers/Logic/AndViewHelperTest.php | 17 +- .../ViewHelpers/Logic/NotViewHelperTest.php | 22 +- .../ViewHelpers/Logic/OrViewHelperTest.php | 27 ++- .../ViewHelpers/MockRenderingContextTrait.php | 7 +- composer.json | 22 +- ext_emconf.php | 6 +- rector.php | 44 ++-- 77 files changed, 814 insertions(+), 1688 deletions(-) delete mode 100644 Classes/Hooks/RealUrl.php delete mode 100644 Tests/Unit/Controller/SearchControllerTest.php delete mode 100644 Tests/Unit/Service/SolrServiceProviderTest.php delete mode 100644 Tests/Unit/ViewHelpers/Find/HighlightFieldViewHelperTest.php delete mode 100644 Tests/Unit/ViewHelpers/Find/PathExistsViewHelperTest.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58e064cf..e27e4790 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,9 +11,8 @@ jobs: fail-fast: false matrix: env: - - { php: 8.0 } - - { php: 8.1 } - { php: 8.2 } + - { php: 8.3 } env: ${{ matrix.env }} @@ -42,7 +41,6 @@ jobs: - name: Check coding style run: composer lint - if: ${{ matrix.env.php == '8.1' }} - name: Run Unit Tests run: | diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 7a3a161c..5b0115d7 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,13 +1,13 @@ exclude('vendor') ->exclude('node_modules') ->in(__DIR__); -return (new PhpCsFixer\Config) - ->setRules([ - '@Symfony' => true, - 'array_syntax' => ['syntax' => 'short'], - ]) + +$config = CsFixerConfig::create(); + +return $config ->setFinder($finder); diff --git a/.php-version b/.php-version index b8eb0263..2983cad0 100644 --- a/.php-version +++ b/.php-version @@ -1 +1 @@ -8.1 +8.2 diff --git a/Classes/Controller/SearchController.php b/Classes/Controller/SearchController.php index 84d07d2c..1c25dce0 100644 --- a/Classes/Controller/SearchController.php +++ b/Classes/Controller/SearchController.php @@ -48,12 +48,9 @@ class SearchController extends ActionController protected ?object $searchProvider = null; - private LoggerInterface $logger; + private readonly LoggerInterface $logger; - public function __construct(LogManagerInterface $logManager) - { - $this->logger = $logManager->getLogger('find'); - } + public function __construct(private readonly LogManagerInterface $logManager, private readonly AssetCollector $assetCollector) {} /** * @throws NoSuchArgumentException @@ -68,12 +65,11 @@ public function detailAction(string $id): ResponseInterface $underlyingQueryScriptTagContent = FrontendUtility::addQueryInformationAsJavaScript( $underlyingQueryInfo['q'], $this->settings, - (int) $underlyingQueryInfo['position'], + (int)$underlyingQueryInfo['position'], $arguments ); - GeneralUtility::makeInstance(AssetCollector::class) - ->addInlineJavaScript('underlyingQueryVar', $underlyingQueryScriptTagContent, ['type' => 'text/javascript'], ['priority' => true]); + $this - \ASSETCOLLECTOR->addInlineJavaScript('underlyingQueryVar', $underlyingQueryScriptTagContent, ['type' => 'text/javascript'], ['priority' => true]); } $this->addStandardAssignments(); @@ -87,9 +83,6 @@ public function detailAction(string $id): ResponseInterface return $this->htmlResponse(); } - /** - * Index Action. - */ public function indexAction(): ResponseInterface { if (array_key_exists('id', $this->requestArguments)) { @@ -158,7 +151,7 @@ protected function addStandardAssignments(): void $this->searchProvider->setConfigurationValue('extendedSearch', $this->searchProvider->isExtendedSearch()); $this->searchProvider->setConfigurationValue( 'uid', - $this->configurationManager->getContentObject()->data['uid'] + $this->request->getAttribute('currentContentObject')->data['uid'] ); $this->searchProvider->setConfigurationValue('prefixID', 'tx_find_find'); $this->searchProvider->setConfigurationValue('pageTitle', $GLOBALS['TSFE']->page['title']); @@ -172,8 +165,11 @@ protected function initializeConnection($activeConnection): void $connectionConfiguration = $this->settings['connections'][$activeConnection]; /* @var ServiceProviderInterface $searchProvider */ - $this->searchProvider = GeneralUtility::makeInstance($connectionConfiguration['provider'], $activeConnection, - $this->settings); + $this->searchProvider = GeneralUtility::makeInstance( + $connectionConfiguration['provider'], + $activeConnection, + $this->settings + ); $this->searchProvider->connect(); } } diff --git a/Classes/Hooks/RealUrl.php b/Classes/Hooks/RealUrl.php deleted file mode 100644 index 82634b31..00000000 --- a/Classes/Hooks/RealUrl.php +++ /dev/null @@ -1,74 +0,0 @@ - - * & Sven-S. Porst - * Göttingen State and University Library - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - * ************************************************************* */ - -/** - * RealUrl Hook for automatic URL generation. - */ -class RealUrl -{ - /** - * Create automatic RealUrl Configuratoin. - * - * @param $params - * - * @return array - */ - public function addRealUrlConfiguration($params, &$pObj) - { - return array_merge_recursive($params['config'], [ - 'postVarSets' => [ - '_DEFAULT' => [ - 'id' => [ - [ - 'GETvar' => 'tx_find_find[id]', - ], - ], - 'a' => [ - [ - 'GETvar' => 'tx_find_find[action]', - 'valueMap' => [ - 'data' => 'data', - 'suggest' => 'suggest', - ], - 'noMatch' => 'bypass', - ], - ], - 'c' => [ - [ - 'GETvar' => 'tx_find_find[controller]', - 'noMatch' => 'bypass', - ], - ], - ], - ], - ] - ); - } -} diff --git a/Classes/Service/AbstractServiceProvider.php b/Classes/Service/AbstractServiceProvider.php index a8748b1c..1f911bca 100644 --- a/Classes/Service/AbstractServiceProvider.php +++ b/Classes/Service/AbstractServiceProvider.php @@ -28,10 +28,7 @@ public function getRequestArguments() return $this->requestArguments; } - /** - * @param array $requestArguments - */ - public function setRequestArguments($requestArguments) + public function setRequestArguments(array $requestArguments) { $this->requestArguments = $requestArguments; } diff --git a/Classes/Service/ServiceProviderInterface.php b/Classes/Service/ServiceProviderInterface.php index 646ff2ba..9dba3508 100644 --- a/Classes/Service/ServiceProviderInterface.php +++ b/Classes/Service/ServiceProviderInterface.php @@ -46,44 +46,17 @@ public function getRequestArguments(); public function isExtendedSearch(); - /** - * @param $query - * - * @return mixed - */ public function search($query); - /** - * @param string $actionName - */ - public function setAction($actionName); - - /** - * @param $key - * @param $value - * - * @return mixed - */ + public function setAction(string $actionName); + public function setConfigurationValue($key, $value); - /** - * @param string $key - */ - public function setControllerExtensionKey($key); + public function setControllerExtensionKey(string $key); public function setCounter(); - /** - * @param array $requestArguments - * - * @return mixed - */ - public function setRequestArguments($requestArguments); - - /** - * @param $settings - * - * @return mixed - */ + public function setRequestArguments(array $requestArguments); + public function suggestQuery($settings); } diff --git a/Classes/Service/SolrServiceProvider.php b/Classes/Service/SolrServiceProvider.php index b621f8ca..e1e63335 100644 --- a/Classes/Service/SolrServiceProvider.php +++ b/Classes/Service/SolrServiceProvider.php @@ -29,7 +29,6 @@ use Solarium\Client; use Solarium\Component\Highlighting\Field; use Solarium\Core\Client\Adapter\Curl; -use Solarium\Core\Client\Adapter\Http; use Solarium\Exception\HttpException; use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Result\Result; @@ -55,7 +54,7 @@ class SolrServiceProvider extends AbstractServiceProvider protected Query $query; - public function connect() + public function connect(): void { $currentConnectionSettings = $this->settings['connections'][$this->connectionName]['options']; // Upgrading to Solarium >= 5 @@ -67,7 +66,7 @@ public function connect() 'endpoint' => [ $this->connectionName => [ 'host' => $currentConnectionSettings['host'], - 'port' => (int) $currentConnectionSettings['port'], + 'port' => (int)$currentConnectionSettings['port'], 'path' => $currentConnectionSettings['path'], 'scheme' => $currentConnectionSettings['scheme'], 'core' => $currentConnectionSettings['core'], @@ -79,7 +78,7 @@ public function connect() $adapter = new Curl(); $eventDispatcher = new EventDispatcher(); if (array_key_exists('timeout', $currentConnectionSettings)) { - $adapter->setTimeout((int) $currentConnectionSettings['timeout']); + $adapter->setTimeout((int)$currentConnectionSettings['timeout']); } // create a client instance @@ -153,16 +152,14 @@ public function getDocumentById(string $id): array /** * Returns whether extended search should be used or not. - * - * @return bool */ - public function isExtendedSearch() + public function isExtendedSearch(): bool { $result = false; if (array_key_exists('extended', $this->requestArguments)) { // Show extended search when told so by the »extended« argument. - $result = ((bool) $this->requestArguments['extended']); + $result = ((bool)$this->requestArguments['extended']); } elseif (array_key_exists('q', $this->requestArguments)) { foreach ($this->settings['queryFields'] as $fieldInfo) { if (array_key_exists('extended', $fieldInfo) @@ -172,7 +169,7 @@ public function isExtendedSearch() // Check if the request argument is an array itself (appies to field type "Range") if (is_array($this->requestArguments['q'][$fieldInfo['id']])) { foreach ($this->requestArguments['q'][$fieldInfo['id']] as $key => $value) { - if ('' !== $value) { + if ($value !== '') { $result = true; break; } @@ -188,75 +185,59 @@ public function isExtendedSearch() return $result; } - /** - * @param $query - */ public function search($query) { // TODO: Implement search() method. } - /** - * @param string $action - */ - public function setAction($action) + public function setAction(string $actionName): void { - $this->action = $action; + $this->action = $actionName; } - /** - * @param array $configuration - */ - public function setConfiguration($configuration) + public function setConfiguration(array $configuration): void { $this->configuration = $configuration; } - /** - * @param mixed $key - * @param mixed $value - */ - public function setConfigurationValue($key, $value) + public function setConfigurationValue($key, $value): void { $this->configuration[$key] = $value; } - /** - * @param string $controllerExtensionKey - */ - public function setControllerExtensionKey($controllerExtensionKey) + public function setControllerExtensionKey(string $key): void { - $this->controllerExtensionKey = $controllerExtensionKey; + $this->controllerExtensionKey = $key; } - public function setCounter() + public function setCounter(): void { $this->setConfigurationValue('counterStart', $this->counterStart()); $this->setConfigurationValue('counterEnd', $this->counterEnd()); } /** - * @param array $arguments + * @param array $settings */ - public function suggestQuery($arguments): array + public function suggestQuery($settings): array { $query = $this->getConnection()->createSuggester(); $results = []; - if (array_key_exists('q', $arguments)) { - $query->setQuery($arguments['q']); - if ($arguments['dictionary']) { - $query->setDictionary($arguments['dictionary']); + if (array_key_exists('q', $settings)) { + $query->setQuery($settings['q']); + if ($settings['dictionary']) { + $query->setDictionary($settings['dictionary']); } - $this->addFacetFilters($arguments); + $this->addFacetFilters($settings); $solrResults = $this->getConnection()->execute($query)->getResults(); foreach ($solrResults as $suggestions) { $results = array_merge($results, $suggestions->getSuggestions()); } - } else { - // TODO: Error message in JSON? } + // TODO: Error message in JSON? + return $results; } @@ -277,14 +258,14 @@ protected function addFacetFilters(array $arguments): array foreach ($activeFacets as $facetID => $facets) { foreach ($facets as $facetTerm => $facetInfo) { $facetQuery = $this->getFacetQuery($this->getFacetConfig($facetID), $facetTerm); - if (array_key_exists('queryStyle', $facetInfo['config']) && 'and' === $facetInfo['config']['queryStyle']) { + if (array_key_exists('queryStyle', $facetInfo['config']) && $facetInfo['config']['queryStyle'] === 'and') { // TODO: Do we really use this part of the condition? Can it be removed? // Alternative query style: adding a conjunction to the main query. // Can be useful when using {!join} to filter on the underlying // records instead of the joined ones. $queryString = $this->query->getQuery(); if ($queryString) { - $queryString .= ' '.Query::QUERY_OPERATOR_AND.' '; + $queryString .= ' ' . Query::QUERY_OPERATOR_AND . ' '; } $queryString .= $facetQuery; @@ -295,7 +276,7 @@ protected function addFacetFilters(array $arguments): array // Add tag/key when configured to excludeOwnFilter for this facet. // Do not add it otherwise as the additional {!tag …} prepended to the Solr query // will break usage of {!join …} in the query. - $queryInfo = ['key' => 'facet-'.$facetID.'-'.$facetTerm]; + $queryInfo = ['key' => 'facet-' . $facetID . '-' . $facetTerm]; if (array_key_exists('excludeOwnFilter', $facetInfo['config']) && $facetInfo['config']['excludeOwnFilter'] && $facetQuery) { $queryInfo['tag'] = $this->tagForFacet($facetID); } @@ -304,7 +285,7 @@ protected function addFacetFilters(array $arguments): array // set solr query to exclude all known facet values if (array_key_exists('labelMissing', $facetInfo['config']) && $facetTerm === $facetInfo['config']['labelMissing']) { $this->query->createFilterQuery($queryInfo) - ->setQuery('-'.str_replace('("%s")', '[* TO *]', $facetInfo['config']['query'])); + ->setQuery('-' . str_replace('("%s")', '[* TO *]', $facetInfo['config']['query'])); } else { $this->query->createFilterQuery($queryInfo) ->setQuery($facetQuery); @@ -354,7 +335,7 @@ protected function addFacetQueries(): void } } - if (array_key_exists('excludeOwnFilter', $facet) && 1 === (int) $facet['excludeOwnFilter']) { + if (array_key_exists('excludeOwnFilter', $facet) && (int)$facet['excludeOwnFilter'] === 1) { $queryForFacet->addExclude($this->tagForFacet($facetID)); } } else { @@ -365,11 +346,11 @@ protected function addFacetQueries(): void ->setSort($facet['sortOrder']); } - if (array_key_exists('excludeOwnFilter', $facet) && 1 === $facet['excludeOwnFilter']) { + if (array_key_exists('excludeOwnFilter', $facet) && $facet['excludeOwnFilter'] === 1) { $queryForFacet->addExclude($this->tagForFacet($facetID)); } - if (array_key_exists('showMissing', $facet) && 1 === $facet['showMissing']) { + if (array_key_exists('showMissing', $facet) && $facet['showMissing'] === 1) { $queryForFacet->setMissing(true); } } else { @@ -406,7 +387,7 @@ protected function addHighlighting(array $arguments): void { $highlightConfig = SettingsUtility::getMergedSettings('highlight', $this->settings); - if ($highlightConfig && $highlightConfig['fields'] && [] !== $highlightConfig['fields']) { + if ($highlightConfig && $highlightConfig['fields'] && $highlightConfig['fields'] !== []) { $highlight = $this->query->getHighlighting(); // Configure highlight queries. @@ -462,7 +443,7 @@ protected function addHighlighting(array $arguments): void $queryComponents = []; foreach ($queryWords as $queryWord) { - $queryComponents[] = '('.sprintf($highlightConfig['query'], $queryWord).')'; + $queryComponents[] = '(' . sprintf($highlightConfig['query'], $queryWord) . ')'; } $queryString = implode(' OR ', $queryComponents); @@ -475,7 +456,7 @@ protected function addHighlighting(array $arguments): void // Configure the fragment length. if (array_key_exists('fragsize', $highlightConfig)) { - $highlight->setFragSize((int) $highlightConfig['fragsize']); + $highlight->setFragSize((int)$highlightConfig['fragsize']); } // Set up alternative fields. @@ -547,7 +528,7 @@ protected function addSortOrdersToTemplate(array $arguments): void ksort($this->settings['sort']); foreach ($this->settings['sort'] as $sortOptionIndex => $sortOption) { if (array_key_exists('id', $sortOption) && array_key_exists('sortCriteria', $sortOption)) { - $localisationKey = 'LLL:'.$this->settings['languageRootPath'].'locallang-form.xml:input.sort-'.$sortOption['id']; + $localisationKey = 'LLL:' . $this->settings['languageRootPath'] . 'locallang-form.xml:input.sort-' . $sortOption['id']; $localisedLabel = LocalizationUtility::translate( $localisationKey, $this->getControllerExtensionKey() @@ -558,7 +539,7 @@ protected function addSortOrdersToTemplate(array $arguments): void $sortOptions['menu'][$sortOption['sortCriteria']] = $localisedLabel; - if ('default' === $sortOption['id']) { + if ($sortOption['id'] === 'default') { $sortOptions['default'] = $sortOption['sortCriteria']; } } else { @@ -590,22 +571,22 @@ protected function addSortOrdersToTemplate(array $arguments): void */ protected function addSortStringForQuery(string $sortString): void { - if ('' !== $sortString) { + if ($sortString !== '') { $sortCriteria = explode(',', $sortString); foreach ($sortCriteria as $sortCriterion) { $sortCriterionParts = explode(' ', $sortCriterion); - if (2 === count($sortCriterionParts)) { + if (count($sortCriterionParts) === 2) { $sortDirection = Query::SORT_ASC; - if ('desc' === $sortCriterionParts[1]) { + if ($sortCriterionParts[1] === 'desc') { $sortDirection = Query::SORT_DESC; - } elseif ('asc' !== $sortCriterionParts[1]) { + } elseif ($sortCriterionParts[1] !== 'asc') { $this->logger->warning(sprintf('sort criterion »%s«’s sort direction is »%s« It should be »asc« or »desc«. Ignoring it.', $sortCriterion, $sortCriterionParts[1])); continue; } $this->query->addSort($sortCriterionParts[0], $sortDirection); } else { - $this->logger->warning('sort criterion »%s« does not have the required form »fieldName [asc|desc]«. Ignoring it.', $sortCriterion); + $this->logger->warning('sort criterion »%s« does not have the required form »fieldName [asc|desc]«. Ignoring it.', [$sortCriterion]); } } } @@ -618,7 +599,7 @@ protected function addTypoScriptFilters(): SolrServiceProvider { if (!empty($this->settings['additionalFilters'])) { foreach ($this->settings['additionalFilters'] as $key => $filterQuery) { - $this->query->createFilterQuery('additionalFilter-'.$key) + $this->query->createFilterQuery('additionalFilter-' . $key) ->setQuery($filterQuery); } } @@ -672,9 +653,9 @@ protected function createQueryForArguments(array $arguments): void // Process parameters to eliminate empty values $queryParameters = []; - if (is_array($rawQueryParameters) && [] !== $rawQueryParameters) { + if (is_array($rawQueryParameters) && $rawQueryParameters !== []) { foreach ($rawQueryParameters as $key => $value) { - if (is_array($value) && [] !== array_filter($value)) { + if (is_array($value) && array_filter($value) !== []) { $queryParameters[$key] = array_filter($value); } elseif (!empty($value) && !is_array($value)) { $queryParameters[$key] = $value; @@ -683,7 +664,7 @@ protected function createQueryForArguments(array $arguments): void } $queryComponents = $this->queryComponentsForQueryParameters($queryParameters); - $queryString = implode(' '.Query::QUERY_OPERATOR_AND.' ', $queryComponents); + $queryString = implode(' ' . Query::QUERY_OPERATOR_AND . ' ', $queryComponents); $this->query->setQuery($queryString); @@ -699,9 +680,6 @@ protected function createQueryForArguments(array $arguments): void $this->addFacetQueries(); } - /** - * @return string - */ protected function getAction(): ?string { return $this->action; @@ -740,9 +718,6 @@ protected function getConnection(): Client return $this->connection; } - /** - * @return string - */ protected function getControllerExtensionKey(): ?string { return $this->controllerExtensionKey; @@ -758,17 +733,17 @@ protected function getControllerExtensionKey(): ?string */ protected function getCount(?array $arguments = null): int { - if (null === $arguments) { + if ($arguments === null) { $arguments = $this->getRequestArguments(); } - $count = (int) $this->settings['paging']['perPage']; + $count = (int)$this->settings['paging']['perPage']; if (array_key_exists('count', $arguments)) { - $count = (int) $this->requestArguments['count']; + $count = (int)$this->requestArguments['count']; } - $maxCount = (int) $this->settings['paging']['maximumPerPage']; + $maxCount = (int)$this->settings['paging']['maximumPerPage']; $count = min([$count, $maxCount]); $this->setConfigurationValue('count', $count); @@ -778,8 +753,6 @@ protected function getCount(?array $arguments = null): int /** * Returns the facet configuration for the given $id. - * - * @return array */ protected function getFacetConfig(string $id): ?array { @@ -798,14 +771,12 @@ protected function getFacetConfig(string $id): ?array /** * Returns query for the given facet $ID and $term based on the facet’s * configuration. - * - * @return string query string */ protected function getFacetQuery(array $facetConfig, string $queryTerm): ?string { $queryString = null; - if ([] !== $facetConfig) { + if ($facetConfig !== []) { if (array_key_exists('facetQuery', $facetConfig)) { // Facet queries are configured: use one of them. foreach ($facetConfig['facetQuery'] as $facetQueryConfig) { @@ -815,7 +786,7 @@ protected function getFacetQuery(array $facetConfig, string $queryTerm): ?string } } - if (null === $queryString) { + if ($queryString === null) { $this->logger->info( sprintf('Results for Facet »%s« with facetQuery ID »%s« were requested, but this facetQuery is not configured. Building a generic facet query instead.', $facetConfig['id'], $queryTerm), [ @@ -827,12 +798,12 @@ protected function getFacetQuery(array $facetConfig, string $queryTerm): ?string } } - if (null === $queryString) { + if ($queryString === null) { // No Facet queries applicable: build the query. if (array_key_exists('query', $facetConfig)) { $queryPattern = $facetConfig['query']; } else { - $queryPattern = ($facetConfig['field'] ?: $facetConfig['id']).':'.'%s'; + $queryPattern = ($facetConfig['field'] ?: $facetConfig['id']) . ':%s'; } // Hack: convert strings »RANGE XX TO YY« Solr style range queries »[XX TO YY]« @@ -857,16 +828,16 @@ protected function getFacetQuery(array $facetConfig, string $queryTerm): ?string */ protected function getOffset(?array $arguments = null): int { - if (null === $arguments) { + if ($arguments === null) { $arguments = $this->requestArguments; } $offset = 0; if (array_key_exists('start', $arguments)) { - $offset = (int) $arguments['start']; + $offset = (int)$arguments['start']; } elseif (array_key_exists('page', $arguments)) { - $offset = ((int) $arguments['page'] - 1) * $this->getCount(); + $offset = ((int)$arguments['page'] - 1) * $this->getCount(); } $this->setConfigurationValue('offset', $offset); @@ -874,10 +845,6 @@ protected function getOffset(?array $arguments = null): int return $offset; } - /** - * @param $id - * @param $arguments - */ protected function getRecordsWithUnderlyingQuery(array $assignments, array $index, $id, $arguments): array { $connection = $this->getConnection(); @@ -894,7 +861,7 @@ protected function getRecordsWithUnderlyingQuery(array $assignments, array $inde $document = $resultSet[$index['resultIndexOffset']]; if ($document['id'] === $id) { $assignments['document'] = $document; - if (0 !== $index['resultIndexOffset']) { + if ($index['resultIndexOffset'] !== 0) { $assignments['document-previous'] = $resultSet[0]; $assignments['document-previous-number'] = $index['previousIndex'] + 1; } @@ -926,19 +893,13 @@ protected function getRecordsWithUnderlyingQuery(array $assignments, array $inde return $assignments; } - /** - * @param $id - * @param $assignments - * - * @return mixed - */ protected function getTheRecordSpecified($id, $assignments) { $connection = $this->getConnection(); $this->createQuery(); $escapedID = $this->query->getHelper()->escapeTerm($id); - $this->query->setQuery('id:'.$escapedID); + $this->query->setQuery('id:' . $escapedID); try { /** @var Result $selectResults */ $selectResults = $connection->execute($this->query); @@ -975,7 +936,7 @@ protected function queryComponentsForQueryParameters(array $queryParameters): ar $queryFields = $this->settings['queryFields']; foreach ($queryFields as $fieldInfo) { $fieldID = $fieldInfo['id']; - if ($fieldID && array_key_exists($fieldID, $queryParameters) && null !== $queryParameters[$fieldID]) { + if ($fieldID && array_key_exists($fieldID, $queryParameters) && $queryParameters[$fieldID] !== null) { // Extract array of query terms from the different structures: // a) just a single string (e.g. text field) // b) array of strings (e.g. date range field) @@ -1016,7 +977,7 @@ protected function queryComponentsForQueryParameters(array $queryParameters): ar // Escape all arguments unless told not to do so. if (!$fieldInfo['noescape']) { $escapedQueryTerms = []; - if (is_array($queryTerms) && [] !== $queryTerms && count($queryTerms) > 1) { + if (is_array($queryTerms) && $queryTerms !== [] && count($queryTerms) > 1) { foreach ($queryTerms as $key => $term) { if ($fieldInfo['phrase']) { $escapedQueryTerms[$key] = $this->query->getHelper()->escapePhrase($term); @@ -1038,14 +999,14 @@ protected function queryComponentsForQueryParameters(array $queryParameters): ar } if (empty($queryFormat)) { - $queryFormat = $fieldID.':%s'; + $queryFormat = $fieldID . ':%s'; } ksort($queryTerms); $magicFieldPrefix = ''; - if ((array_key_exists('luceneMatchVersionNumber', $this->settings) && (int) $this->settings['luceneMatchVersionNumber'] < 8) || (!array_key_exists('luceneMatchVersionNumber', $this->settings))) { + if ((array_key_exists('luceneMatchVersionNumber', $this->settings) && (int)$this->settings['luceneMatchVersionNumber'] < 8) || (!array_key_exists('luceneMatchVersionNumber', $this->settings))) { $magicFieldPrefix = '_query_:'; } @@ -1053,29 +1014,29 @@ protected function queryComponentsForQueryParameters(array $queryParameters): ar $magicFieldPrefix .= '{!edismax}'; } - if (2 === (int) $fieldInfo['noescape']) { - $chars = explode(',', $fieldInfo['escapechar']); + if ((int)$fieldInfo['noescape'] === 2) { + $chars = explode(',', (string)$fieldInfo['escapechar']); foreach ($queryTerms as $key => $term) { foreach ($chars as $char) { - $queryTerms[$key] = str_replace($char, '\\'.$char, $term); + $queryTerms[$key] = str_replace($char, '\\' . $char, $term); } } - $queryPart = $magicFieldPrefix.vsprintf($queryFormat, $queryTerms); - } elseif (1 === (int) $fieldInfo['noescape']) { - $queryPart = $magicFieldPrefix.vsprintf($queryFormat, $queryTerms); + $queryPart = $magicFieldPrefix . vsprintf($queryFormat, $queryTerms); + } elseif ((int)$fieldInfo['noescape'] === 1) { + $queryPart = $magicFieldPrefix . vsprintf($queryFormat, $queryTerms); } else { - $queryPart = $magicFieldPrefix.$this->query->getHelper()->escapePhrase(vsprintf($queryFormat, $queryTerms)); + $queryPart = $magicFieldPrefix . $this->query->getHelper()->escapePhrase(vsprintf($queryFormat, $queryTerms)); } - if ('' !== $queryPart && '0' !== $queryPart) { + if ($queryPart !== '' && $queryPart !== '0') { $queryComponents[$fieldID] = $queryPart; } } } // Ask for all results if there is no query. - if ([] === $queryComponents) { + if ($queryComponents === []) { $queryComponents[] = $this->settings['defaultQuery']; } @@ -1102,7 +1063,7 @@ protected function setActiveFacetSelectionForID(array &$activeFacets, string $fa $facetQueries[$facetTerm] = $facetInfo; } - if ([] !== $facetQueries) { + if ($facetQueries !== []) { $activeFacets[$facetID] = $facetQueries; } } @@ -1124,7 +1085,7 @@ protected function setFields(array $arguments): void // Use field list from query parameters or from defaults. if (array_key_exists('data-fields', $arguments) && $arguments['data-fields']) { - $fields = explode(',', $arguments['data-fields']); + $fields = explode(',', (string)$arguments['data-fields']); } elseif (array_key_exists('default', $arguments) && $fieldsConfig['default']) { $fields = array_values($fieldsConfig['default']); } @@ -1148,7 +1109,7 @@ protected function setFields(array $arguments): void } // Only set fields of the query if there is a result. Otherwise use the default setting. - if ([] !== $fields) { + if ($fields !== []) { $this->query->setFields($fields); } } @@ -1176,7 +1137,7 @@ protected function setSortOrder(array $arguments): void $sortString = $arguments['sort']; } elseif (!empty($this->settings['sort'])) { foreach ($this->settings['sort'] as $sortSetting) { - if ('default' === $sortSetting['id']) { + if ($sortSetting['id'] === 'default') { $sortString = $sortSetting['sortCriteria']; break; } @@ -1192,13 +1153,13 @@ protected function setSortOrder(array $arguments): void */ protected function tagForFacet(string $facetID): string { - return 'facet-'.$facetID; + return 'facet-' . $facetID; } /* * Set configured main query operator. Defaults to 'AND'. */ - private function addDefaultQueryOperator() + private function addDefaultQueryOperator(): void { if (isset($this->settings['defaultQueryOperator'])) { $defaultQueryOperator = $this->settings['defaultQueryOperator']; diff --git a/Classes/Utility/ArrayUtility.php b/Classes/Utility/ArrayUtility.php index 5e0cc506..94bfb9e7 100644 --- a/Classes/Utility/ArrayUtility.php +++ b/Classes/Utility/ArrayUtility.php @@ -27,9 +27,6 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -/** - * Array Helper. - */ class ArrayUtility { /** @@ -39,15 +36,11 @@ class ArrayUtility * * Specifically aimed at the __hmac and __referrer keys introduced by Fluid * forms as well as the text submitted by empty search form fields. - * - * @param array $array - * - * @return array */ - public static function cleanArgumentsArray($array) + public static function cleanArgumentsArray(array $array): array { foreach ($array as $key => &$value) { - if (str_starts_with($key, '__') || '' === $value) { + if (str_starts_with($key, '__') || $value === '') { unset($array[$key]); } elseif (is_array($value)) { self::cleanArgumentsArray($value); diff --git a/Classes/Utility/FrontendUtility.php b/Classes/Utility/FrontendUtility.php index b613353e..fd84448b 100644 --- a/Classes/Utility/FrontendUtility.php +++ b/Classes/Utility/FrontendUtility.php @@ -36,11 +36,11 @@ class FrontendUtility * Stores information about the active query in the »underlyingQuery« JavaScript variable. * * @param int|null $position of the record in the result list - * @param array $arguments overrides $this->requestArguments if set + * @param array $arguments overrides $this->requestArguments if set * * @throws \JsonException */ - public static function addQueryInformationAsJavaScript($query, array $settings, ?int $position = null, $arguments = []): string + public static function addQueryInformationAsJavaScript($query, array $settings, ?int $position = null, array $arguments = []): string { if ($settings['paging']['detailPagePaging']) { if (array_key_exists('underlyingQuery', $arguments)) { @@ -52,7 +52,7 @@ public static function addQueryInformationAsJavaScript($query, array $settings, $underlyingQuery['facet'] = $arguments['facet']; } - if (null !== $position) { + if ($position !== null) { $underlyingQuery['position'] = $position; } @@ -66,18 +66,16 @@ public static function addQueryInformationAsJavaScript($query, array $settings, $underlyingQuery['sort'] = $arguments['sort']; } - return 'var underlyingQuery = '.json_encode($underlyingQuery, JSON_THROW_ON_ERROR).';'; + return 'var underlyingQuery = ' . json_encode($underlyingQuery, JSON_THROW_ON_ERROR) . ';'; } return ''; } /** - * @param $underlyingQueryInfo - * * @return array */ - public static function getIndexes($underlyingQueryInfo) + public static function getIndexes($underlyingQueryInfo): array { return ['positionIndex' => $underlyingQueryInfo['position'] - 1, 'previousIndex' => max([$underlyingQueryInfo['position'] - 2, 0]), 'nextIndex' => $underlyingQueryInfo['position'], 'resultIndexOffset' => (0 === $underlyingQueryInfo['position'] - 1) ? 0 : 1]; } diff --git a/Classes/Utility/LoggerUtility.php b/Classes/Utility/LoggerUtility.php index 65859c40..4ac6e87a 100644 --- a/Classes/Utility/LoggerUtility.php +++ b/Classes/Utility/LoggerUtility.php @@ -34,12 +34,8 @@ class LoggerUtility { /** * Returns an array that can be handled by devLog with the information from an exception. - * - * @param \Exception $exception - * - * @return array */ - public static function exceptionToArray($exception, $includePrevious = false) + public static function exceptionToArray(\Throwable $exception, $includePrevious = false): array { $array = [ 'message' => $exception->getMessage(), diff --git a/Classes/Utility/SettingsUtility.php b/Classes/Utility/SettingsUtility.php index 316d4b32..46b6fe4a 100644 --- a/Classes/Utility/SettingsUtility.php +++ b/Classes/Utility/SettingsUtility.php @@ -40,12 +40,10 @@ class SettingsUtility * Settings array keys need to be non-numeric if they are supposed to be overriden. * * @param string $settingName the key of the subarray of $this->settings to work on - * @param array $settings - * @param string $actionName * * @return array highlight configuration */ - public static function getMergedSettings($settingName, $settings, $actionName = 'index') + public static function getMergedSettings(string $settingName, array $settings, string $actionName = 'index'): array { $config = []; diff --git a/Classes/Utility/UpgradeUtility.php b/Classes/Utility/UpgradeUtility.php index ccee7740..5855b636 100644 --- a/Classes/Utility/UpgradeUtility.php +++ b/Classes/Utility/UpgradeUtility.php @@ -10,7 +10,7 @@ public static function handleSolariumUpgrade(array $connectionSettings): array { trigger_error('Please read the upgrading instructions at https://github.com/subugoe/typo3-find/blob/main/UPGRADING.md', E_USER_DEPRECATED); - if (str_contains($connectionSettings['path'], '/solr/')) { + if (str_contains((string)$connectionSettings['path'], '/solr/')) { $connectionSettings['core'] = str_replace('/solr/', '', $connectionSettings['path']); $connectionSettings['core'] = str_replace('/', '', $connectionSettings['core']); $connectionSettings['path'] = '/'; diff --git a/Classes/ViewHelpers/Data/ArrayFirstViewHelper.php b/Classes/ViewHelpers/Data/ArrayFirstViewHelper.php index b75ebbe4..7e49046f 100644 --- a/Classes/ViewHelpers/Data/ArrayFirstViewHelper.php +++ b/Classes/ViewHelpers/Data/ArrayFirstViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -38,28 +37,22 @@ */ class ArrayFirstViewHelper extends AbstractViewHelper { - /** - * Register arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('array', 'array|string', 'the array to return the first value of', false, null); } - /** - * @return string|int|bool|array - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public function render() { $result = null; - $array = $arguments['array']; - if (null === $array) { - $array = $renderChildrenClosure(); + $array = $this->arguments['array']; + if ($array === null) { + $array = $this->renderChildren(); } - if (is_array($array) && [] !== $array) { + if (is_array($array) && $array !== []) { $arrayKeys = array_keys($array); $firstKey = $arrayKeys[0]; $result = $array[$firstKey]; diff --git a/Classes/ViewHelpers/Data/IsArrayViewHelper.php b/Classes/ViewHelpers/Data/IsArrayViewHelper.php index 9c76ca3d..d4dcc7b5 100644 --- a/Classes/ViewHelpers/Data/IsArrayViewHelper.php +++ b/Classes/ViewHelpers/Data/IsArrayViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -39,25 +38,22 @@ class IsArrayViewHelper extends AbstractViewHelper /** * Register arguments. */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('subject', 'array|string|int', 'The variable to inspect', false, null); } - /** - * @return bool - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public function render(): bool { $result = false; - $subject = $arguments['subject']; - if (null === $subject) { - $subject = $renderChildrenClosure(); + $subject = $this->arguments['subject']; + if ($subject === null) { + $subject = $this->renderChildren(); } - if (null !== $subject) { + if ($subject !== null) { $result = is_array($subject); } diff --git a/Classes/ViewHelpers/Data/NewArrayViewHelper.php b/Classes/ViewHelpers/Data/NewArrayViewHelper.php index ba92494c..402bd206 100644 --- a/Classes/ViewHelpers/Data/NewArrayViewHelper.php +++ b/Classes/ViewHelpers/Data/NewArrayViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -39,10 +38,7 @@ class NewArrayViewHelper extends AbstractViewHelper { protected $escapeOutput = false; - /** - * Register arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('name', 'string', 'name of template variable to assign the result to'); @@ -51,46 +47,50 @@ public function initializeArguments() $this->registerArgument('keys', 'array', 'array of keys'); $this->registerArgument('values', 'array', 'array of values', false, []); - $this->registerArgument('global', 'boolean', - 'whether to make the variable available to all templates coming afterwards', false, false); + $this->registerArgument( + 'global', + 'boolean', + 'whether to make the variable available to all templates coming afterwards', + false, + false + ); $this->registerArgument('omitEmptyFields', 'boolean', 'omits empty fields', false, false); } - /** - * @return array - */ - public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) + public function render(): array { - $result = $arguments['array'] ?? []; + $result = $this->arguments['array'] ?? []; - if ($arguments['keys']) { - if (count($arguments['keys']) === count($arguments['values'])) { - foreach ($arguments['keys'] as $index => $key) { - $value = $arguments['values'][$index]; - if (!$arguments['omitEmptyFields'] || $value) { + if ($this->arguments['keys']) { + if (count($this->arguments['keys']) === count($this->arguments['values'])) { + foreach ($this->arguments['keys'] as $index => $key) { + $value = $this->arguments['values'][$index]; + if (!$this->arguments['omitEmptyFields'] || $value) { $result[$key] = $value; } } } else { - $result = 'newArray View Helper: Number of keys and values must be the same.'.PHP_EOL.print_r($arguments, - true); + $result = 'newArray View Helper: Number of keys and values must be the same.' . PHP_EOL . print_r( + $this->arguments, + true + ); } } else { - foreach ($arguments['values'] as $value) { + foreach ($this->arguments['values'] as $value) { $result[] = $value; } } - $variableName = $arguments['name'] ?? null; - if (null !== $variableName) { - if ($renderingContext->getVariableProvider()->exists($variableName)) { - $renderingContext->getVariableProvider()->remove($variableName); + $variableName = $this->arguments['name'] ?? null; + if ($variableName !== null) { + if ($this->renderingContext->getVariableProvider()->exists($variableName)) { + $this->renderingContext->getVariableProvider()->remove($variableName); } - $renderingContext->getVariableProvider()->add($variableName, $result); - $result = $renderChildrenClosure(); - if (true !== $arguments['global']) { - $renderingContext->getVariableProvider()->remove($variableName); + $this->renderingContext->getVariableProvider()->add($variableName, $result); + $result = $this->renderChildren(); + if ($this->arguments['global'] !== true) { + $this->renderingContext->getVariableProvider()->remove($variableName); } } diff --git a/Classes/ViewHelpers/Data/SplitViewHelper.php b/Classes/ViewHelpers/Data/SplitViewHelper.php index 28c73779..ce6b8cc9 100644 --- a/Classes/ViewHelpers/Data/SplitViewHelper.php +++ b/Classes/ViewHelpers/Data/SplitViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -42,33 +41,24 @@ class SplitViewHelper extends AbstractViewHelper */ public const DEFAULT_SEPARATOR = ', '; - /** - * Register arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('string', 'string', 'The string to split into components', false, null); $this->registerArgument('separator', 'string', 'The string separating the components', false, self::DEFAULT_SEPARATOR); } - /** - * @return array - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $string = $arguments['string']; - if (null === $string) { - $string = $renderChildrenClosure; + public function render( + ): array { + $string = $this->arguments['string']; + if ($string === null) { + $string = $this->renderChildren(); } - if (empty($arguments['separator'])) { - $arguments['separator'] = self::DEFAULT_SEPARATOR; + if (empty($this->arguments['separator'])) { + $this->arguments['separator'] = self::DEFAULT_SEPARATOR; } - return explode($arguments['separator'], $string); + return explode($this->arguments['separator'], (string)$string); } } diff --git a/Classes/ViewHelpers/Data/TransposeViewHelper.php b/Classes/ViewHelpers/Data/TransposeViewHelper.php index f485de46..b3c92e1d 100644 --- a/Classes/ViewHelpers/Data/TransposeViewHelper.php +++ b/Classes/ViewHelpers/Data/TransposeViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -37,55 +36,45 @@ */ class TransposeViewHelper extends AbstractViewHelper { - /** - * Register arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('arrays', 'array', 'Array with keys: field names and values: arrays', false, []); $this->registerArgument('name', 'string', 'Variable name to assign the new array to', true); } - /** - * @return string Rendered string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { + public function render(): array + { $arrays = []; $iterationArray = []; // Strip non-numeric keys in the value arrays. - foreach ($arguments['arrays'] as $key => $array) { - $iterationArray = (null !== $array) ? $array : []; + foreach ($this->arguments['arrays'] as $key => $array) { + $iterationArray = $array ?? []; $arrays[$key] = array_values($iterationArray); } if ($iterationArray && static::identicalLengths($arrays)) { $rows = []; foreach (array_keys($iterationArray) as $rowIndex) { - $row = []; - foreach ($arrays as $key => $array) { - $row[$key] = $array[$rowIndex]; - } + $row = array_map(fn($array) => $array[$rowIndex], $arrays); $rows[] = $row; } - $variableName = $arguments['name']; - $renderingContext->getVariableProvider()->add($variableName, $rows); - $output = $renderChildrenClosure(); - $renderingContext->getVariableProvider()->remove($variableName); + $variableName = $this->arguments['name']; + $this->renderingContext->getVariableProvider()->add($variableName, $rows); + $output = $this->renderChildren(); + $this->renderingContext->getVariableProvider()->remove($variableName); } else { $info = []; - foreach ($arguments['arrays'] as $key => $array) { - $info[] = $key.': '.count($array); + foreach ($this->arguments['arrays'] as $key => $array) { + $info[] = $key . ': ' . count($array); } - $output = 'The arrays passed in the »arrays« argument do not have identical numbers of values: ('.implode(', ', - $info).')'; + $output = 'The arrays passed in the »arrays« argument do not have identical numbers of values: (' . implode( + ', ', + $info + ) . ')'; } return $output; @@ -95,16 +84,14 @@ public static function renderStatic( * Returns TRUE if all elements of $arrays have the same count(), FALSE otherwise. * * @param array $arrays array of arrays - * - * @return bool */ - protected static function identicalLengths($arrays) + protected static function identicalLengths(array $arrays): bool { $result = true; $length = null; foreach ($arrays as $array) { - if (null === $length) { + if ($length === null) { $length = count($array); } elseif ($length !== count($array)) { $result = false; diff --git a/Classes/ViewHelpers/Data/ValueForKeyViewHelper.php b/Classes/ViewHelpers/Data/ValueForKeyViewHelper.php index bdaa4060..b73c2af4 100644 --- a/Classes/ViewHelpers/Data/ValueForKeyViewHelper.php +++ b/Classes/ViewHelpers/Data/ValueForKeyViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -37,7 +36,7 @@ */ class ValueForKeyViewHelper extends AbstractViewHelper { - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('array', 'array', 'The array to extract the value from', true); @@ -47,15 +46,12 @@ public function initializeArguments() /** * @return string|int|bool|array */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext + public function render( ) { $result = null; - if ((is_int($arguments['key']) || is_string($arguments['key'])) && ($arguments['array'] && array_key_exists($arguments['key'], $arguments['array']))) { - $result = $arguments['array'][$arguments['key']]; + if ((is_int($this->arguments['key']) || is_string($this->arguments['key'])) && ($this->arguments['array'] && array_key_exists($this->arguments['key'], $this->arguments['array']))) { + $result = $this->arguments['array'][$this->arguments['key']]; } return $result; diff --git a/Classes/ViewHelpers/Find/FacetIsActiveViewHelper.php b/Classes/ViewHelpers/Find/FacetIsActiveViewHelper.php index 054ad589..8910ca9c 100644 --- a/Classes/ViewHelpers/Find/FacetIsActiveViewHelper.php +++ b/Classes/ViewHelpers/Find/FacetIsActiveViewHelper.php @@ -29,7 +29,6 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -37,36 +36,27 @@ */ class FacetIsActiveViewHelper extends AbstractViewHelper { - /** - * Register arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('facetID', 'string', 'ID of the facet to determine the selection status of', true); - $this->registerArgument('facetTerm', 'string', + $this->registerArgument( + 'facetTerm', + 'string', 'Term of the facet item to determine the selection status of; if NULL any facet with the given facetID matches', - false, null); + false, + null + ); $this->registerArgument('activeFacets', 'array', 'Array of active facets', false, []); $this->registerArgument('type', 'string', 'Query type [string, range]', false, 'string'); } - /** - * @return bool - */ - - /** - * @return string|int|bool|array - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - foreach ($arguments['activeFacets'] as $facets) { + public function render( + ): bool { + foreach ($this->arguments['activeFacets'] as $facets) { foreach ($facets as $facetInfo) { - if ($facetInfo['id'] === $arguments['facetID'] - && ($facetInfo['term'] === $arguments['facetTerm'] || null === $arguments['facetTerm']) + if ($facetInfo['id'] === $this->arguments['facetID'] + && ($facetInfo['term'] === $this->arguments['facetTerm'] || $this->arguments['facetTerm'] === null) ) { return true; } diff --git a/Classes/ViewHelpers/Find/FacetLinkArgumentsViewHelper.php b/Classes/ViewHelpers/Find/FacetLinkArgumentsViewHelper.php index ad6dda1b..d6f02f06 100644 --- a/Classes/ViewHelpers/Find/FacetLinkArgumentsViewHelper.php +++ b/Classes/ViewHelpers/Find/FacetLinkArgumentsViewHelper.php @@ -28,7 +28,6 @@ * * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -45,16 +44,17 @@ */ class FacetLinkArgumentsViewHelper extends AbstractViewHelper { - /** - * Register arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('facetID', 'string', 'ID of the facet to determine the selection status of', true); - $this->registerArgument('facetTerm', 'string', + $this->registerArgument( + 'facetTerm', + 'string', 'Term of the facet item to determine the selection status of; if NULL any facet with the given facetID matches', - false, null); + false, + null + ); $this->registerArgument('activeFacets', 'array', 'Array of active facets', false, []); $this->registerArgument('mode', 'string', 'add|remove', false, 'add'); } @@ -63,26 +63,21 @@ public function initializeArguments() * Create the return array required to add/remove the URL parameters by * passing it to f.link.action’s »arguments« * or »argumentsToBeExcludedFromQueryString«. - * - * @return array */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { + public function render(): array + { $result = []; - $facetID = $arguments['facetID']; - $facetTerm = $arguments['facetTerm']; - $activeFacets = $arguments['activeFacets']; - $mode = $arguments['mode']; - if ('remove' === $mode && $activeFacets) { + $facetID = $this->arguments['facetID']; + $facetTerm = $this->arguments['facetTerm']; + $activeFacets = $this->arguments['activeFacets']; + $mode = $this->arguments['mode']; + if ($mode === 'remove' && $activeFacets) { if (array_key_exists($facetID, $activeFacets)) { - $itemToRemove = 'tx_find_find[facet]['.$facetID.']'; + $itemToRemove = 'tx_find_find[facet][' . $facetID . ']'; if (array_key_exists($facetTerm, $activeFacets[$facetID])) { - $itemToRemove .= '['.$facetTerm.']'; + $itemToRemove .= '[' . $facetTerm . ']'; } $result[] = $itemToRemove; @@ -90,7 +85,7 @@ public static function renderStatic( // Go back to page 1. $result[] = 'tx_find_find[page]'; - } elseif ('add' === $mode) { + } elseif ($mode === 'add') { $result['facet'] = [ $facetID => [$facetTerm => 1], ]; diff --git a/Classes/ViewHelpers/Find/HighlightFieldViewHelper.php b/Classes/ViewHelpers/Find/HighlightFieldViewHelper.php index 6ac04492..c89039d4 100644 --- a/Classes/ViewHelpers/Find/HighlightFieldViewHelper.php +++ b/Classes/ViewHelpers/Find/HighlightFieldViewHelper.php @@ -26,9 +26,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ + use Solarium\QueryType\Select\Result\Document; use Solarium\QueryType\Select\Result\Result; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -47,48 +47,62 @@ */ class HighlightFieldViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('results', Result::class, 'Query results', true); - $this->registerArgument('document', Document::class, 'Result document to work on', - true); + $this->registerArgument( + 'document', + Document::class, + 'Result document to work on', + true + ); $this->registerArgument('field', 'string', 'name of field in document to highlight', true); - $this->registerArgument('alternateField', 'string', - 'name of alternate field in document to use for highlighting', false, null); - $this->registerArgument('index', 'int', 'if the field is an array: index of the single element to highlight', - false); + $this->registerArgument( + 'alternateField', + 'string', + 'name of alternate field in document to use for highlighting', + false, + null + ); + $this->registerArgument( + 'index', + 'int', + 'if the field is an array: index of the single element to highlight', + false + ); $this->registerArgument('idKey', 'string', 'name of the field in document that is its ID', false, 'id'); - $this->registerArgument('highlightTagOpen', 'string', 'opening tag to insert to begin highlighting', false, - ''); - $this->registerArgument('highlightTagClose', 'string', 'closing tag to insert to end highlighting', false, - ''); + $this->registerArgument( + 'highlightTagOpen', + 'string', + 'opening tag to insert to begin highlighting', + false, + '' + ); + $this->registerArgument( + 'highlightTagClose', + 'string', + 'closing tag to insert to end highlighting', + false, + '' + ); $this->registerArgument('raw', 'boolean', 'whether to not HTML escape the output', false, false); } - /** - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - if ($arguments['document']) { - $fields = $arguments['document']->getFields(); - $fieldContent = $fields[$arguments['field']]; - if (null !== $arguments['index']) { - if (is_array($fieldContent) && count($fieldContent) > $arguments['index']) { - $fieldContent = $fieldContent[$arguments['index']]; - } else { - // TODO: error message + public function render(): array|string + { + if ($this->arguments['document']) { + $fields = $this->arguments['document']->getFields(); + $fieldContent = $fields[$this->arguments['field']]; + if ($this->arguments['index'] !== null) { + if (is_array($fieldContent) && count($fieldContent) > $this->arguments['index']) { + $fieldContent = $fieldContent[$this->arguments['index']]; } + + // TODO: error message } - return self::highlightField($fieldContent, $arguments); + return $this->highlightField($fieldContent, $this->arguments); } return ''; @@ -99,19 +113,19 @@ public static function renderStatic( * by \ueeee and \ueeef. * * @param array|string $fieldContent content of the field to highlight - * @param array $arguments + * @param array $arguments */ - protected static function highlightField(array|string $fieldContent, $arguments): array|string + protected function highlightField(array|string $fieldContent, array $arguments): array|string { - $highlightInfo = self::getHighlightInfo($arguments); + $highlightInfo = $this->getHighlightInfo($arguments); if (is_array($fieldContent)) { $result = []; foreach ($fieldContent as $singleField) { - $result[] = self::highlightSingleField($singleField, $highlightInfo, $arguments); + $result[] = $this->highlightSingleField($singleField, $highlightInfo, $arguments); } } else { - $result = self::highlightSingleField($fieldContent, $highlightInfo, $arguments); + $result = $this->highlightSingleField($fieldContent, $highlightInfo, $arguments); } return $result; @@ -120,10 +134,8 @@ protected static function highlightField(array|string $fieldContent, $arguments) /** * Returns highlight information for the document and field configured in * our arguments. - * - * @return array */ - protected static function getHighlightInfo($arguments) + protected function getHighlightInfo($arguments) { $highlightInfo = []; $documentID = $arguments['document'][$arguments['idKey']]; @@ -147,34 +159,32 @@ protected static function getHighlightInfo($arguments) * * @param string $fieldString the string to highlight * @param array $highlightInfo information provided by the index’ highlighter - * @param array $arguments - * - * @return string */ - protected static function highlightSingleField($fieldString, $highlightInfo, $arguments) + protected function highlightSingleField(string $fieldString, array $highlightInfo, $arguments): ?string { $result = null; foreach ($highlightInfo as $highlightItem) { $highlightItemStripped = str_replace(['\ueeee', '\ueeef'], ['', ''], $highlightItem); - if (null !== strpos($fieldString, $highlightItemStripped)) { + if (strpos($fieldString, (string)$highlightItemStripped) !== null) { // HTML escape the text here if not explicitly configured to not do so. // Use f:format.raw in the template to avoid double escaping the HTML tags. if (!$arguments['raw']) { - $highlightItem = htmlspecialchars($highlightItem); + $highlightItem = htmlspecialchars((string)$highlightItem); } $highlightItemMarkedUp = str_replace( ['\ueeee', '\ueeef'], [$arguments['highlightTagOpen'], $arguments['highlightTagClose']], - $highlightItem); + $highlightItem + ); $result = str_replace($highlightItemStripped, $highlightItemMarkedUp, $fieldString); break; } } // If no highlighted string is present, use the original one. - if (null === $result) { + if ($result === null) { $result = $arguments['raw'] ? $fieldString : htmlspecialchars($fieldString); } diff --git a/Classes/ViewHelpers/Find/LocalizedFacetDataViewHelper.php b/Classes/ViewHelpers/Find/LocalizedFacetDataViewHelper.php index 448ea0cd..053ff6a1 100644 --- a/Classes/ViewHelpers/Find/LocalizedFacetDataViewHelper.php +++ b/Classes/ViewHelpers/Find/LocalizedFacetDataViewHelper.php @@ -27,7 +27,6 @@ ******************************************************************************/ use TYPO3\CMS\Extbase\Utility\LocalizationUtility; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -57,42 +56,36 @@ class LocalizedFacetDataViewHelper extends AbstractViewHelper /** * Registers own arguments. */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('data', 'Array', 'facet data', true); $this->registerArgument('settings', 'Array', 'find settings', true); } - /** - * @return array - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { + public function render( + ): array { $facetNames = []; $facetEntryNames = []; - $baseKey = 'LLL:'.$arguments['settings']['languageRootPath'].'locallang-facets.xml:facet'; - foreach ($arguments['data'] as $facetID => $facetData) { - $facetKey = $baseKey.'.'.$facetID; + $baseKey = 'LLL:' . $this->arguments['settings']['languageRootPath'] . 'locallang-facets.xml:facet'; + foreach ($this->arguments['data'] as $facetID => $facetData) { + $facetKey = $baseKey . '.' . $facetID; $localizedFacetName = LocalizationUtility::translate($facetKey, '', []); - if (null !== $localizedFacetName) { + if ($localizedFacetName !== null) { $facetNames[$facetID] = $localizedFacetName; } $localizationsForFacet = []; foreach ($facetData->getValues() as $facetEntryID => $count) { - $facetEntryKey = $facetKey.'.'.$facetEntryID; + $facetEntryKey = $facetKey . '.' . $facetEntryID; $localizedFacetEntryName = LocalizationUtility::translate($facetEntryKey, '', []); - if (null !== $localizedFacetEntryName) { + if ($localizedFacetEntryName !== null) { $localizationsForFacet[$facetEntryID] = $localizedFacetEntryName; } } - if ([] !== $localizationsForFacet) { + if ($localizationsForFacet !== []) { $facetEntryNames[$facetID] = $localizationsForFacet; } } diff --git a/Classes/ViewHelpers/Find/PageListViewHelper.php b/Classes/ViewHelpers/Find/PageListViewHelper.php index 6cd3a58d..8e55eb44 100644 --- a/Classes/ViewHelpers/Find/PageListViewHelper.php +++ b/Classes/ViewHelpers/Find/PageListViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -34,10 +33,7 @@ */ class PageListViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('currentPage', 'int', 'number of the current page', false, 1); @@ -47,20 +43,14 @@ public function initializeArguments() $this->registerArgument('minimumGapSize', 'int', 'gaps of fewer items than this are filles', false, 2); } - /** - * @return array - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $currentPage = ($arguments['currentPage'] ? (int) $arguments['currentPage'] : 1); - $numberOfPages = (int) ceil($arguments['resultCount'] / $arguments['perPage']); - $adjacentPages = (int) $arguments['adjacentPages']; + public function render( + ): array { + $currentPage = ($this->arguments['currentPage'] ? (int)$this->arguments['currentPage'] : 1); + $numberOfPages = (int)ceil($this->arguments['resultCount'] / $this->arguments['perPage']); + $adjacentPages = (int)$this->arguments['adjacentPages']; $adjacentFirst = max($currentPage - $adjacentPages, 1); $adjacentLast = min($currentPage + $adjacentPages, $numberOfPages); - $minimumGapSize = (int) $arguments['minimumGapSize']; + $minimumGapSize = (int)$this->arguments['minimumGapSize']; $pageIndex = 1; while ($pageIndex <= $numberOfPages) { @@ -69,7 +59,7 @@ public static function renderStatic( if ($pageIndex === $currentPage) { $pageInfo['status'] = 'current'; $pageInfo['current'] = true; - } elseif ((1 === $pageIndex | $pageIndex === $numberOfPages) !== 0) { + } elseif (($pageIndex === 1 | $pageIndex === $numberOfPages) !== 0) { $pageInfo['status'] = 'edge'; } elseif (abs($pageIndex - $currentPage) <= $adjacentPages) { $pageInfo['status'] = 'adjacent'; @@ -81,7 +71,7 @@ public static function renderStatic( $pageInfo['gap'] = true; } - if ('gap' === $pageInfo['status']) { + if ($pageInfo['status'] === 'gap') { $pageInfo['text'] = '…'; if ($pageIndex < $currentPage) { $pageIndex = $currentPage - $adjacentPages; @@ -89,7 +79,7 @@ public static function renderStatic( $pageIndex = $numberOfPages; } } else { - $pageInfo['text'] = (string) $pageIndex; + $pageInfo['text'] = (string)$pageIndex; ++$pageIndex; } @@ -99,7 +89,7 @@ public static function renderStatic( return [ 'pages' => $pages, 'current' => $currentPage, - 'previous' => (1 === $currentPage) ? null : $currentPage - 1, + 'previous' => ($currentPage === 1) ? null : $currentPage - 1, 'next' => ($currentPage === $numberOfPages) ? null : $currentPage + 1, ]; } diff --git a/Classes/ViewHelpers/Find/PageNumberForResultNumberViewHelper.php b/Classes/ViewHelpers/Find/PageNumberForResultNumberViewHelper.php index 76353473..9f3c7913 100644 --- a/Classes/ViewHelpers/Find/PageNumberForResultNumberViewHelper.php +++ b/Classes/ViewHelpers/Find/PageNumberForResultNumberViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -44,28 +43,19 @@ class PageNumberForResultNumberViewHelper extends AbstractViewHelper */ public const DEFAULT_RESULTS_PER_PAGE = 20; - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('resultNumber', 'int', 'number of the result to determine the page number for', true); $this->registerArgument('resultsPerPage', 'int', 'number of results per page', false, self::DEFAULT_RESULTS_PER_PAGE); } - /** - * @return int - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - if (0 === $arguments['resultsPerPage']) { - $arguments['resultsPerPage'] = self::DEFAULT_RESULTS_PER_PAGE; + public function render( + ): int { + if ($this->arguments['resultsPerPage'] === 0) { + $this->arguments['resultsPerPage'] = self::DEFAULT_RESULTS_PER_PAGE; } - return (int) ceil($arguments['resultNumber'] / $arguments['resultsPerPage']); + return (int)ceil($this->arguments['resultNumber'] / $this->arguments['resultsPerPage']); } } diff --git a/Classes/ViewHelpers/Find/PathExistsViewHelper.php b/Classes/ViewHelpers/Find/PathExistsViewHelper.php index 0f147c1e..429703af 100644 --- a/Classes/ViewHelpers/Find/PathExistsViewHelper.php +++ b/Classes/ViewHelpers/Find/PathExistsViewHelper.php @@ -28,7 +28,6 @@ ******************************************************************************/ use TYPO3\CMS\Core\Core\Environment; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,23 +35,14 @@ */ class PathExistsViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('path', 'string', 'the path to check the existence of', true); } - /** - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - return file_exists(Environment::getPublicPath().'/'.$arguments['path']); + public function render( + ): bool { + return file_exists(Environment::getPublicPath() . '/' . $this->arguments['path']); } } diff --git a/Classes/ViewHelpers/Find/SelectOptionsForFacetViewHelper.php b/Classes/ViewHelpers/Find/SelectOptionsForFacetViewHelper.php index 63573c81..47175e21 100644 --- a/Classes/ViewHelpers/Find/SelectOptionsForFacetViewHelper.php +++ b/Classes/ViewHelpers/Find/SelectOptionsForFacetViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ use TYPO3\CMS\Extbase\Utility\LocalizationUtility; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,42 +35,48 @@ */ class SelectOptionsForFacetViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('values', 'array', 'values array for a facet', false, []); - $this->registerArgument('showCount', 'boolean', 'include the item count for the facet in the label?', false, - false); - $this->registerArgument('leadingBlank', 'boolean', 'begin the select with a blank item? (for jquery.chosen)', - false, false); + $this->registerArgument( + 'showCount', + 'boolean', + 'include the item count for the facet in the label?', + false, + false + ); + $this->registerArgument( + 'leadingBlank', + 'boolean', + 'begin the select with a blank item? (for jquery.chosen)', + false, + false + ); $this->registerArgument('sortByName', 'boolean', 'sort the items alphabetically?', false, false); - $this->registerArgument('sortPrefixSeparator', 'string', - 'sort the whole string but only keep the part after the separator for display', false, null); + $this->registerArgument( + 'sortPrefixSeparator', + 'string', + 'sort the whole string but only keep the part after the separator for display', + false, + null + ); $this->registerArgument('localisationPrefix', 'string', 'prefix for the localisation key', false, ''); } - /** - * @return array - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { + public function render( + ): array { $result = []; // Start the select with a blank element? - if ($arguments['leadingBlank']) { + if ($this->arguments['leadingBlank']) { $result[''] = ''; } - if (!empty($arguments['values'])) { - foreach ($arguments['values'] as $item => $count) { + if (!empty($this->arguments['values'])) { + foreach ($this->arguments['values'] as $item => $count) { // Localise item name. - $localisationKey = $arguments['localisationPrefix'].$item; + $localisationKey = $this->arguments['localisationPrefix'] . $item; $localisedItem = LocalizationUtility::translate($localisationKey, 'find'); if (!$localisedItem) { @@ -79,20 +84,20 @@ public static function renderStatic( } // Append count to item name? - $result[$item] = $localisedItem.($arguments['showCount'] ? ' ('.$count.')' : ''); + $result[$item] = $localisedItem . ($this->arguments['showCount'] ? ' (' . $count . ')' : ''); } } // Sort the array? - if ($arguments['sortByName']) { + if ($this->arguments['sortByName']) { ksort($result); } // Strip sort prefixes. - if ($arguments['sortPrefixSeparator']) { + if ($this->arguments['sortPrefixSeparator']) { $strippedResult = []; foreach ($result as $key => $value) { - $valueParts = explode($arguments['sortPrefixSeparator'], $value, 2); + $valueParts = explode($this->arguments['sortPrefixSeparator'], $value, 2); $strippedResult[$key] = $valueParts[count($valueParts) - 1]; } diff --git a/Classes/ViewHelpers/Format/CSVLineViewHelper.php b/Classes/ViewHelpers/Format/CSVLineViewHelper.php index 99d6e624..d74ed5c2 100644 --- a/Classes/ViewHelpers/Format/CSVLineViewHelper.php +++ b/Classes/ViewHelpers/Format/CSVLineViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,10 +35,7 @@ */ class CSVLineViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('data', 'array', 'The array to output as CSV line', false, null); @@ -47,22 +43,16 @@ public function initializeArguments() $this->registerArgument('fieldEnclosure', 'string', 'The string to enclose the field content in', false, '"'); } - /** - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $data = $arguments['data']; - if (null === $data) { - $data = $renderChildrenClosure(); + public function render( + ): false|string { + $data = $this->arguments['data']; + if ($data === null) { + $data = $this->renderChildren(); } // Write CSV to pseudo-file as PHP cannot write it directly to a string. $fp = fopen('php://temp', 'r+'); - fputcsv($fp, $data, $arguments['fieldDelimiter'], $arguments['fieldEnclosure']); + fputcsv($fp, $data, $this->arguments['fieldDelimiter'], $this->arguments['fieldEnclosure']); rewind($fp); $result = fgets($fp); fclose($fp); diff --git a/Classes/ViewHelpers/Format/FieldContentViewHelper.php b/Classes/ViewHelpers/Format/FieldContentViewHelper.php index 2c64bf78..a363b16e 100644 --- a/Classes/ViewHelpers/Format/FieldContentViewHelper.php +++ b/Classes/ViewHelpers/Format/FieldContentViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -34,24 +33,15 @@ */ class FieldContentViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('string', 'string', 'String to be examined for display', false, null); } - /** - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $string = $arguments['string']; + public function render(): string + { + $string = $this->arguments['string']; if (is_array($string) && array_key_exists('term', $string)) { $string = $string['term']; diff --git a/Classes/ViewHelpers/Format/JoinViewHelper.php b/Classes/ViewHelpers/Format/JoinViewHelper.php index e452ccca..3bdeb32f 100644 --- a/Classes/ViewHelpers/Format/JoinViewHelper.php +++ b/Classes/ViewHelpers/Format/JoinViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,30 +35,26 @@ */ class JoinViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('array', 'array', 'the array to join the elements of', false, null); - $this->registerArgument('separator', 'string', 'the separator string placed between the elements of the array', - false, ', '); + $this->registerArgument( + 'separator', + 'string', + 'the separator string placed between the elements of the array', + false, + ', ' + ); } - /** - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $array = $arguments['array']; - if (null === $array) { - $array = $renderChildrenClosure(); + public function render(): string + { + $array = $this->arguments['array']; + if ($array === null) { + $array = $this->renderChildren(); } - return implode($arguments['separator'], $array); + return implode($this->arguments['separator'], $array); } } diff --git a/Classes/ViewHelpers/Format/JsonViewHelper.php b/Classes/ViewHelpers/Format/JsonViewHelper.php index 33ad8a72..f893f7c0 100644 --- a/Classes/ViewHelpers/Format/JsonViewHelper.php +++ b/Classes/ViewHelpers/Format/JsonViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -38,33 +37,25 @@ */ class JsonViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('data', 'mixed', 'The data to output as JSON', false, null); } - /** - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { + public function render() + { @trigger_error('Please use f:format.json instead', E_USER_DEPRECATED); // Transform arguments for being compatible to the core ViewHelper arguments $data = []; - $data['value'] = $arguments['data']; + $data['value'] = $this->arguments['data']; $data['forceObject'] = false; // Call the Core ViewHelper $jsonViewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\Format\JsonViewHelper(); + $jsonViewHelper->setArguments(['data' => $data]); - return $jsonViewHelper::renderStatic($data, $renderChildrenClosure, $renderingContext); + return $jsonViewHelper->render(); } } diff --git a/Classes/ViewHelpers/Format/RegexpViewHelper.php b/Classes/ViewHelpers/Format/RegexpViewHelper.php index a4a595a0..51a5d86b 100644 --- a/Classes/ViewHelpers/Format/RegexpViewHelper.php +++ b/Classes/ViewHelpers/Format/RegexpViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,40 +35,40 @@ */ class RegexpViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); - $this->registerArgument('string', 'string', - 'The string to work on; if not given, the content of the tag is used', false, null); + $this->registerArgument( + 'string', + 'string', + 'The string to work on; if not given, the content of the tag is used', + false, + null + ); $this->registerArgument('match', 'string', 'The regular expression used for matching', true); $this->registerArgument('replace', 'string', 'The regular expression replacement string', false, null); - $this->registerArgument('useMBEreg', 'boolean', 'Whether to use mb_ereg_replace() instead of preg_replace()', - false, false); + $this->registerArgument( + 'useMBEreg', + 'boolean', + 'Whether to use mb_ereg_replace() instead of preg_replace()', + false, + false + ); } - /** - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $input = $arguments['string']; - if (null === $input) { - $input = $renderChildrenClosure(); + public function render() + { + $input = $this->arguments['string']; + if ($input === null) { + $input = $this->renderChildren(); } - $result = null; - if (null === $arguments['replace']) { - $result = preg_match($arguments['match'], $input); - } elseif (!$arguments['useMBEreg']) { - $result = preg_replace($arguments['match'], $arguments['replace'], $input); + if ($this->arguments['replace'] === null) { + $result = preg_match($this->arguments['match'], (string)$input); + } elseif (!$this->arguments['useMBEreg']) { + $result = preg_replace($this->arguments['match'], $this->arguments['replace'], (string)$input); } else { - $result = mb_ereg_replace($arguments['match'], $arguments['replace'], $input); + $result = mb_ereg_replace((string)$this->arguments['match'], $this->arguments['replace'], (string)$input); } return $result; diff --git a/Classes/ViewHelpers/Format/SolrEscapeViewHelper.php b/Classes/ViewHelpers/Format/SolrEscapeViewHelper.php index 1f578bd6..99ed9f49 100644 --- a/Classes/ViewHelpers/Format/SolrEscapeViewHelper.php +++ b/Classes/ViewHelpers/Format/SolrEscapeViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ use Solarium\Core\Query\Helper; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -37,31 +36,22 @@ */ class SolrEscapeViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('string', 'string', 'the string to escape for Solr', false, null); $this->registerArgument('phrase', 'boolean', 'whether to use phrase escaping', false, false); } - /** - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $string = $arguments['string']; - if (null === $string) { - $string = $renderChildrenClosure(); + public function render(): string + { + $string = $this->arguments['string']; + if ($string === null) { + $string = $this->renderChildren(); } $solariumHelper = new Helper(); - return $arguments['phrase'] ? $solariumHelper->escapePhrase($string) : $solariumHelper->escapeTerm($string); + return $this->arguments['phrase'] ? $solariumHelper->escapePhrase($string) : $solariumHelper->escapeTerm($string); } } diff --git a/Classes/ViewHelpers/Format/StripViewHelper.php b/Classes/ViewHelpers/Format/StripViewHelper.php index 9b794ef8..b8fb93d5 100644 --- a/Classes/ViewHelpers/Format/StripViewHelper.php +++ b/Classes/ViewHelpers/Format/StripViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,33 +35,32 @@ */ class StripViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); - $this->registerArgument('string', 'string', - 'The string to strip leading and trailing whitespace from; If not given, the tag content is used', false, - null); - $this->registerArgument('strip', 'string', - 'The characters to strip from the string; If not given, defaults to standard PHP whitespace setting', false, - null); + $this->registerArgument( + 'string', + 'string', + 'The string to strip leading and trailing whitespace from; If not given, the tag content is used', + false, + null + ); + $this->registerArgument( + 'strip', + 'string', + 'The characters to strip from the string; If not given, defaults to standard PHP whitespace setting', + false, + null + ); } - /** - * @return array - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $string = $arguments['string']; - if (null === $string) { - $string = $renderChildrenClosure(); + public function render(): string + { + $string = $this->arguments['string']; + if ($string === null) { + $string = $this->renderChildren(); } - return null === $arguments['strip'] ? trim($string) : trim($string, $arguments['strip']); + return $this->arguments['strip'] === null ? trim((string)$string) : trim((string)$string, $this->arguments['strip']); } } diff --git a/Classes/ViewHelpers/Format/XMLViewHelper.php b/Classes/ViewHelpers/Format/XMLViewHelper.php index 38ac1831..9db370a8 100644 --- a/Classes/ViewHelpers/Format/XMLViewHelper.php +++ b/Classes/ViewHelpers/Format/XMLViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,24 +35,15 @@ */ class XMLViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('htmloutput', 'Boolean', 'Whether to output as HTML', false, false); } - /** - * @return string - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $input = $renderChildrenClosure(); + public function render(): false|string + { + $input = $this->renderChildren(); $XML = new \DOMDocument(); $XML->preserveWhiteSpace = false; $XML->formatOutput = true; @@ -62,6 +52,6 @@ public static function renderStatic( // TODO: Error handling? - return $arguments['htmloutput'] ? $XML->saveHTML() : $XML->saveXML(); + return $this->arguments['htmloutput'] ? $XML->saveHTML() : $XML->saveXML(); } } diff --git a/Classes/ViewHelpers/LinkedData/ContainerViewHelper.php b/Classes/ViewHelpers/LinkedData/ContainerViewHelper.php index 0d218699..af6c7920 100644 --- a/Classes/ViewHelpers/LinkedData/ContainerViewHelper.php +++ b/Classes/ViewHelpers/LinkedData/ContainerViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ use Subugoe\Find\ViewHelpers\LinkedData\Renderer\AbstractRenderer; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -38,34 +37,33 @@ */ class ContainerViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('format', 'string', 'The linked data format to create', false, 'turtle'); $this->registerArgument('prefixes', 'array', 'The namespace names to use', false, []); - $this->registerArgument('name', 'string', 'The name of the template variable to store the data in', false, - 'linkedDataContainer'); + $this->registerArgument( + 'name', + 'string', + 'The name of the template variable to store the data in', + false, + 'linkedDataContainer' + ); } /** - * @return string + * @throws \DOMException */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $renderingContext->getVariableProvider()->add($arguments['name'], []); + public function render(): string + { + $this->renderingContext->getVariableProvider()->add($this->arguments['name'], []); - $renderChildrenClosure(); - $items = $renderingContext->getVariableProvider()->get($arguments['name']); - $renderingContext->getVariableProvider()->remove($arguments['name']); + $this->renderChildren(); + $items = $this->renderingContext->getVariableProvider()->get($this->arguments['name']); + $this->renderingContext->getVariableProvider()->remove($this->arguments['name']); - $LDRenderer = AbstractRenderer::instantiateSubclassForType($arguments['format']); - $LDRenderer->setPrefixes($arguments['prefixes']); + $LDRenderer = AbstractRenderer::instantiateSubclassForType($this->arguments['format']); + $LDRenderer->setPrefixes($this->arguments['prefixes']); return $LDRenderer->renderItems($items); } diff --git a/Classes/ViewHelpers/LinkedData/ItemViewHelper.php b/Classes/ViewHelpers/LinkedData/ItemViewHelper.php index 041c774e..381f8c11 100644 --- a/Classes/ViewHelpers/LinkedData/ItemViewHelper.php +++ b/Classes/ViewHelpers/LinkedData/ItemViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,10 +35,7 @@ */ class ItemViewHelper extends AbstractViewHelper { - /**; - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('subject', 'string', 'The triple’s subject', true); @@ -47,34 +43,36 @@ public function initializeArguments() $this->registerArgument('object', 'string', 'The triple’s object', false, null); $this->registerArgument('objectType', 'string', 'Type of the triple’s object', false, null); $this->registerArgument('language', 'string', 'ISO 639-1 language code for the triple’s object', false, null); - $this->registerArgument('name', 'string', 'The name of the template variable to store the data in', false, - 'linkedDataContainer'); + $this->registerArgument( + 'name', + 'string', + 'The name of the template variable to store the data in', + false, + 'linkedDataContainer' + ); } - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $container = $renderingContext->getVariableProvider()->get($arguments['name']); - if (!$container[$arguments['subject']]) { - $container[$arguments['subject']] = []; + public function render(): void + { + $container = $this->renderingContext->getVariableProvider()->get($this->arguments['name']); + if (!$container[$this->arguments['subject']]) { + $container[$this->arguments['subject']] = []; } - if (!$container[$arguments['subject']][$arguments['predicate']]) { - $container[$arguments['subject']][$arguments['predicate']] = []; + if (!$container[$this->arguments['subject']][$this->arguments['predicate']]) { + $container[$this->arguments['subject']][$this->arguments['predicate']] = []; } - if (null !== $arguments['object']) { - $container[$arguments['subject']][$arguments['predicate']][$arguments['object']] = null; + if ($this->arguments['object'] !== null) { + $container[$this->arguments['subject']][$this->arguments['predicate']][$this->arguments['object']] = null; } else { - $container[$arguments['subject']][$arguments['predicate']][$renderChildrenClosure()] = [ - 'type' => $arguments['objectType'], - 'language' => $arguments['language'], + $container[$this->arguments['subject']][$this->arguments['predicate']][$this->renderChildren()] = [ + 'type' => $this->arguments['objectType'], + 'language' => $this->arguments['language'], ]; } - $renderingContext->getVariableProvider()->remove($arguments['name']); - $renderingContext->getVariableProvider()->add($arguments['name'], $container); + $this->renderingContext->getVariableProvider()->remove($this->arguments['name']); + $this->renderingContext->getVariableProvider()->add($this->arguments['name'], $container); } } diff --git a/Classes/ViewHelpers/LinkedData/Renderer/AbstractRenderer.php b/Classes/ViewHelpers/LinkedData/Renderer/AbstractRenderer.php index ec0826b3..b0aceade 100644 --- a/Classes/ViewHelpers/LinkedData/Renderer/AbstractRenderer.php +++ b/Classes/ViewHelpers/LinkedData/Renderer/AbstractRenderer.php @@ -29,25 +29,17 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; -/** - * Class AbstractRenderer. - */ abstract class AbstractRenderer { protected array $prefixes = []; protected array $usedPrefixes = []; - /** - * @param $type - * - * @return object - */ public static function instantiateSubclassForType($type) { - if ('rdf' === $type) { + if ($type === 'rdf') { $instance = GeneralUtility::makeInstance(RDFRenderer::class); - } elseif ('json-ld' === $type) { + } elseif ($type === 'json-ld') { $instance = GeneralUtility::makeInstance(JSONLDRenderer::class); } else { $instance = GeneralUtility::makeInstance(TurtleRenderer::class); @@ -56,10 +48,7 @@ public static function instantiateSubclassForType($type) return $instance; } - /** - * @param $prefixes - */ - public function setPrefixes($prefixes) + public function setPrefixes($prefixes): void { $this->prefixes = $prefixes; } diff --git a/Classes/ViewHelpers/LinkedData/Renderer/JSONLDRenderer.php b/Classes/ViewHelpers/LinkedData/Renderer/JSONLDRenderer.php index fa519605..e7f1c72b 100644 --- a/Classes/ViewHelpers/LinkedData/Renderer/JSONLDRenderer.php +++ b/Classes/ViewHelpers/LinkedData/Renderer/JSONLDRenderer.php @@ -32,12 +32,7 @@ */ class JSONLDRenderer extends AbstractRenderer implements RendererInterface { - /** - * @param $items - * - * @return string - */ - public function renderItems($items) + public function renderItems($items): string { $graph = []; @@ -49,7 +44,7 @@ public function renderItems($items) foreach ($subjectStatements as $predicateURI => $objects) { // loop over objects foreach ($objects as $objectString => $properties) { - if (null === $properties) { + if ($properties === null) { $object = $this->prefixedName($objectString); } else { $object = ['@value' => $objectString]; @@ -93,19 +88,16 @@ public function renderItems($items) ]); } - /** - * @param $name - * - * @return mixed - */ - protected function prefixedName($name) + protected function prefixedName(string $name): string { foreach ($this->prefixes as $acronym => $URI) { - if (str_starts_with($name, $URI)) { - $name = str_replace($URI, $acronym.':', $name); + if (str_starts_with($name, (string)$URI)) { + $name = str_replace($URI, $acronym . ':', $name); $this->usedPrefixes[$acronym] = true; break; - } elseif (str_starts_with($name, $acronym.':')) { + } + + if (str_starts_with($name, $acronym . ':')) { $this->usedPrefixes[$acronym] = true; break; } diff --git a/Classes/ViewHelpers/LinkedData/Renderer/RDFRenderer.php b/Classes/ViewHelpers/LinkedData/Renderer/RDFRenderer.php index bfcd51a2..948c736e 100644 --- a/Classes/ViewHelpers/LinkedData/Renderer/RDFRenderer.php +++ b/Classes/ViewHelpers/LinkedData/Renderer/RDFRenderer.php @@ -34,11 +34,9 @@ class RDFRenderer extends AbstractRenderer implements RendererInterface { /** - * @param $items - * - * @return string + * @throws \DOMException */ - public function renderItems($items) + public function renderItems($items): false|string { $doc = new \DOMDocument(); $this->prefixes['rdf'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; @@ -57,22 +55,26 @@ public function renderItems($items) $predicateElement = $doc->createElement($this->prefixedName($predicate)); $subjectDescription->appendChild($predicateElement); - if (null === $properties) { - $objectParts = explode(':', $object, 2); - if ($this->prefixes[$objectParts[0]] && 2 === count($objectParts)) { - $object = $this->prefixes[$objectParts[0]].$objectParts[1]; + if ($properties === null) { + $objectParts = explode(':', (string)$object, 2); + if ($this->prefixes[$objectParts[0]] && count($objectParts) === 2) { + $object = $this->prefixes[$objectParts[0]] . $objectParts[1]; } - $predicateElement->setAttribute($this->prefixedName('rdf:resource'), - $this->prefixedName($object, true)); + $predicateElement->setAttribute( + $this->prefixedName('rdf:resource'), + $this->prefixedName($object, true) + ); } else { if ($properties['language']) { $predicateElement->setAttribute($this->prefixedName('xml:lang'), $properties['language']); } if ($properties['type']) { - $predicateElement->setAttribute($this->prefixedName('rdf:datatype'), - $this->prefixedName($properties['type'], true)); + $predicateElement->setAttribute( + $this->prefixedName('rdf:datatype'), + $this->prefixedName($properties['type'], true) + ); } $predicateElement->appendChild($doc->createTextNode($object)); @@ -88,7 +90,7 @@ public function renderItems($items) // Add the prefixes that are used as xmlns. foreach (array_keys($this->usedPrefixes) as $prefix) { if ($this->prefixes[$prefix]) { - $doc->firstChild->setAttribute('xmlns:'.$prefix, $this->prefixes[$prefix]); + $doc->firstChild->setAttribute('xmlns:' . $prefix, $this->prefixes[$prefix]); } } @@ -97,19 +99,13 @@ public function renderItems($items) return $doc->saveXML(); } - /** - * @param $name - * @param bool $expand - * - * @return string - */ - protected function prefixedName($name, $expand = false) + protected function prefixedName(string $name, bool $expand = false): string { $nameParts = explode(':', $name, 2); if ($this->prefixes[$nameParts[0]]) { $this->usedPrefixes[$nameParts[0]] = true; if ($expand && count($nameParts) > 1) { - $name = $this->prefixes[$nameParts[0]].$nameParts[1]; + $name = $this->prefixes[$nameParts[0]] . $nameParts[1]; } } diff --git a/Classes/ViewHelpers/LinkedData/Renderer/RendererInterface.php b/Classes/ViewHelpers/LinkedData/Renderer/RendererInterface.php index dd3ceae2..ddda943d 100644 --- a/Classes/ViewHelpers/LinkedData/Renderer/RendererInterface.php +++ b/Classes/ViewHelpers/LinkedData/Renderer/RendererInterface.php @@ -27,15 +27,7 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -/** - * Interface RendererInterface. - */ interface RendererInterface { - /** - * @param $items - * - * @return mixed - */ public function renderItems($items); } diff --git a/Classes/ViewHelpers/LinkedData/Renderer/TurtleRenderer.php b/Classes/ViewHelpers/LinkedData/Renderer/TurtleRenderer.php index f5f5547b..50900252 100644 --- a/Classes/ViewHelpers/LinkedData/Renderer/TurtleRenderer.php +++ b/Classes/ViewHelpers/LinkedData/Renderer/TurtleRenderer.php @@ -32,9 +32,6 @@ */ class TurtleRenderer extends AbstractRenderer implements RendererInterface { - /** - * @param $items - */ public function renderItems($items): string { $result = ''; @@ -42,37 +39,39 @@ public function renderItems($items): string // loop over subjects $subjectArray = []; foreach ($items as $subject => $subjectStatements) { - $subjectString = $this->turtleString($subject)."\n\t"; + $subjectString = $this->turtleString($subject) . "\n\t"; // loop over predicates $predicateArray = []; foreach ($subjectStatements as $predicate => $objects) { - $predicateString = $this->turtleString($predicate).' '; + $predicateString = $this->turtleString($predicate) . ' '; // loop over objects $objectArray = []; foreach ($objects as $object => $properties) { $objectString = ''; - if (null === $properties) { + if ($properties === null) { $objectString = $this->turtleString($object); } else { - if (!str_contains($object, '"') && !str_contains($object, "\r") && !str_contains($object, - "\n")) { - $objectString = '"'.$object.'"'; - } elseif (!str_contains($object, '"""')) { - $objectString = '"""'.$object.'"""'; - } elseif (!str_contains($object, "'''")) { - $objectString = "'''".$object."'''"; - } else { - // TODO: Error Handling for could not escape. + if (!str_contains((string)$object, '"') && !str_contains((string)$object, "\r") && !str_contains( + (string)$object, + "\n" + )) { + $objectString = '"' . $object . '"'; + } elseif (!str_contains((string)$object, '"""')) { + $objectString = '"""' . $object . '"""'; + } elseif (!str_contains((string)$object, "'''")) { + $objectString = "'''" . $object . "'''"; } + // TODO: Error Handling for could not escape. + if ($properties['language']) { - $objectString .= '@'.$properties['language']; + $objectString .= '@' . $properties['language']; } if ($properties['type']) { - $objectString .= '^^'.$this->turtleString($properties['type']); + $objectString .= '^^' . $this->turtleString($properties['type']); } } @@ -87,41 +86,42 @@ public function renderItems($items): string $subjectArray[] = $subjectString; } - $result .= implode(' .'.PHP_EOL.PHP_EOL, $subjectArray).' .'.PHP_EOL; + $result .= implode(' .' . PHP_EOL . PHP_EOL, $subjectArray) . ' .' . PHP_EOL; // Prepend the prefixes that are used. $prefixes = []; foreach ($this->prefixes as $acronym => $prefix) { - if (true === $this->usedPrefixes[$acronym]) { - $prefixes[] = '@prefix '.$acronym.': '.$this->turtleString($prefix, false).' .'.PHP_EOL; + if ($this->usedPrefixes[$acronym] === true) { + $prefixes[] = '@prefix ' . $acronym . ': ' . $this->turtleString($prefix, false) . ' .' . PHP_EOL; } } - return PHP_EOL.implode('', $prefixes).PHP_EOL.$result; + return PHP_EOL . implode('', $prefixes) . PHP_EOL . $result; } /** - * @param $item * @param bool $usePrefixes * * @return mixed|string */ protected function turtleString($item, $usePrefixes = true) { - $result = '<'.$item.'>'; + $result = '<' . $item . '>'; - $itemParts = explode(':', $item, 2); + $itemParts = explode(':', (string)$item, 2); $rdfTypeURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'; if ($item === $rdfTypeURI - || (count($itemParts) > 1 && $this->prefixes[$itemParts[0]].$itemParts[1] === $rdfTypeURI)) { + || (count($itemParts) > 1 && $rdfTypeURI === $this->prefixes[$itemParts[0]] . $itemParts[1])) { $result = 'a'; } elseif ($usePrefixes) { foreach ($this->prefixes as $acronym => $prefix) { - if (str_starts_with($item, $prefix)) { - $result = str_replace($prefix, $acronym.':', $item); + if (str_starts_with((string)$item, (string)$prefix)) { + $result = str_replace($prefix, $acronym . ':', $item); $this->usedPrefixes[$acronym] = true; break; - } elseif ($itemParts[0] === $acronym) { + } + + if ($itemParts[0] === $acronym) { $result = $item; $this->usedPrefixes[$acronym] = true; break; diff --git a/Classes/ViewHelpers/Logic/AndViewHelper.php b/Classes/ViewHelpers/Logic/AndViewHelper.php index ddb5618a..44738c48 100644 --- a/Classes/ViewHelpers/Logic/AndViewHelper.php +++ b/Classes/ViewHelpers/Logic/AndViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -37,28 +36,19 @@ */ class AndViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('conditions', 'array', 'the array of conditions to AND', true); } - /** - * @return bool - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { + public function render( + ): bool { $result = true; - foreach ($arguments['conditions'] as $condition) { - $result &= (true == $condition); + foreach ($this->arguments['conditions'] as $condition) { + $result &= ($condition == true); } - return (bool) $result; + return (bool)$result; } } diff --git a/Classes/ViewHelpers/Logic/NotViewHelper.php b/Classes/ViewHelpers/Logic/NotViewHelper.php index 2337d07a..f14bda9b 100644 --- a/Classes/ViewHelpers/Logic/NotViewHelper.php +++ b/Classes/ViewHelpers/Logic/NotViewHelper.php @@ -27,7 +27,6 @@ * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -37,20 +36,14 @@ */ class NotViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('condition', 'string|int|float|array', 'the condition to NOT', true); } - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ): bool { - return true != $arguments['condition']; + public function render(): bool + { + return $this->arguments['condition'] != true; } } diff --git a/Classes/ViewHelpers/Logic/OrViewHelper.php b/Classes/ViewHelpers/Logic/OrViewHelper.php index c1de612d..3fbac75a 100644 --- a/Classes/ViewHelpers/Logic/OrViewHelper.php +++ b/Classes/ViewHelpers/Logic/OrViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,28 +35,19 @@ */ class OrViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('conditions', 'array', 'the array of conditions to OR', true); } - /** - * @return bool - */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { + public function render(): bool + { $result = false; - foreach ($arguments['conditions'] as $condition) { - $result |= (true == $condition); + foreach ($this->arguments['conditions'] as $condition) { + $result |= ($condition == true); } - return (bool) $result; + return (bool)$result; } } diff --git a/Classes/ViewHelpers/Page/LinkCSSViewHelper.php b/Classes/ViewHelpers/Page/LinkCSSViewHelper.php index 8967c841..59710f68 100644 --- a/Classes/ViewHelpers/Page/LinkCSSViewHelper.php +++ b/Classes/ViewHelpers/Page/LinkCSSViewHelper.php @@ -31,11 +31,7 @@ use TYPO3\CMS\Core\Resource\Exception\InvalidFileException; use TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException; use TYPO3\CMS\Core\Resource\Exception\InvalidPathException; -use TYPO3\CMS\Core\TimeTracker\TimeTracker; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Utility\VersionNumberUtility; use TYPO3\CMS\Frontend\Resource\FilePathSanitizer; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -45,43 +41,29 @@ */ class LinkCSSViewHelper extends AbstractViewHelper { - public function initializeArguments() + public function __construct(private readonly PageRenderer $pageRenderer, private readonly FilePathSanitizer $filePathSanitizer) {} + + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('file', 'string', 'File to add a CSS header for'); } /** - * @return string + * @throws InvalidPathException + * @throws InvalidFileException + * @throws InvalidFileNameException + * @throws FileDoesNotExistException */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $typo3VersionConstraint = version_compare(VersionNumberUtility::getNumericTypo3Version(), '9.5.0', '<'); - - if ($typo3VersionConstraint) { - try { - $CSSFileName = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize((string) $arguments['file']); - } catch (InvalidFileNameException) { - $CSSFileName = null; - } catch (InvalidPathException|FileDoesNotExistException|InvalidFileException $e) { - $CSSFileName = null; - if ($GLOBALS['TSFE']->tmpl->tt_track) { - GeneralUtility::makeInstance(TimeTracker::class)->setTSlogMessage($e->getMessage(), 3); - } - } - } else { - $fileNameFromArguments = $arguments['file']; - if ($fileNameFromArguments) { - $CSSFileName = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize($fileNameFromArguments); - } + public function render(): string + { + $fileNameFromArguments = $this->arguments['file']; + if ($fileNameFromArguments) { + $CSSFileName = $this->filePathSanitizer->sanitize($fileNameFromArguments); } - if ($CSSFileName) { - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); - $pageRenderer->addCSSFile($CSSFileName); + if ($CSSFileName !== '' && $CSSFileName !== '0') { + $this->pageRenderer->addCSSFile($CSSFileName); } } } diff --git a/Classes/ViewHelpers/Page/ScriptViewHelper.php b/Classes/ViewHelpers/Page/ScriptViewHelper.php index 926fe293..ebb7a7aa 100644 --- a/Classes/ViewHelpers/Page/ScriptViewHelper.php +++ b/Classes/ViewHelpers/Page/ScriptViewHelper.php @@ -23,11 +23,11 @@ * THE SOFTWARE. ******************************************************************************/ use TYPO3\CMS\Core\Page\PageRenderer; -use TYPO3\CMS\Core\TypoScript\TemplateService; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Utility\VersionNumberUtility; +use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException; +use TYPO3\CMS\Core\Resource\Exception\InvalidFileException; +use TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException; +use TYPO3\CMS\Core\Resource\Exception\InvalidPathException; use TYPO3\CMS\Frontend\Resource\FilePathSanitizer; -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -37,65 +37,33 @@ */ class ScriptViewHelper extends AbstractViewHelper { - /** - * @return PageRenderer - */ - protected static function getPageRenderer() - { - return GeneralUtility::makeInstance(PageRenderer::class); - } - - /** - * @return TemplateService - */ - protected static function getTypoScriptTemplateService() - { - return $GLOBALS['TSFE']->tmpl; - } + public function __construct(private readonly PageRenderer $pageRenderer, private readonly FilePathSanitizer $filePathSanitizer) {} - public function initializeArguments() + public function initializeArguments(): void { $this->registerArgument('file', 'string', 'File to append as script'); $this->registerArgument('name', 'string', 'Name to use', true); } /** - * @return string + * @throws InvalidPathException + * @throws InvalidFileNameException + * @throws InvalidFileException + * @throws FileDoesNotExistException */ - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $name = $arguments['name']; - $pageRenderer = self::getPageRenderer(); - - $typo3VersionConstraint = version_compare(VersionNumberUtility::getNumericTypo3Version(), '9.5.0', '<'); - - if ($typo3VersionConstraint) { - $scriptPath = static::getTypoScriptTemplateService()->getFileName($arguments['file']); - - if ($scriptPath) { - $pageRenderer->addJsFooterLibrary($name, $scriptPath); - - return ''; - } - - $content = $renderChildrenClosure(); - $pageRenderer->addJsFooterInlineCode($name, $content); + public function render(): string + { + $name = $this->arguments['name']; - return ''; + $fileNameFromArguments = $this->arguments['file']; + if ($fileNameFromArguments) { + $scriptPath = $this->filePathSanitizer->sanitize($fileNameFromArguments); + $this->pageRenderer->addJsFooterLibrary($name, $scriptPath); } else { - $fileNameFromArguments = $arguments['file']; - if ($fileNameFromArguments) { - $scriptPath = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize($fileNameFromArguments); - $pageRenderer->addJsFooterLibrary($name, $scriptPath); - } else { - $content = $renderChildrenClosure(); - $pageRenderer->addJsFooterInlineCode($name, $content); - } - - return ''; + $content = $this->renderChildren(); + $this->pageRenderer->addJsFooterInlineCode($name, $content); } + + return ''; } } diff --git a/Classes/ViewHelpers/Page/TitleViewHelper.php b/Classes/ViewHelpers/Page/TitleViewHelper.php index dee52a1c..7fe37330 100644 --- a/Classes/ViewHelpers/Page/TitleViewHelper.php +++ b/Classes/ViewHelpers/Page/TitleViewHelper.php @@ -26,7 +26,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ -use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -36,23 +35,17 @@ */ class TitleViewHelper extends AbstractViewHelper { - /** - * Registers own arguments. - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('title', 'string', 'the title to set for the page', false, null); } - public static function renderStatic( - array $arguments, - \Closure $renderChildrenClosure, - RenderingContextInterface $renderingContext - ) { - $title = $arguments['title']; - if (null === $title) { - $title = $renderChildrenClosure(); + public function render(): void + { + $title = $this->arguments['title']; + if ($title === null) { + $title = $this->renderChildren(); } /* @@ -66,8 +59,11 @@ public static function renderStatic( * appearing once inside the tag. Otherwise the order of the components in the page title will be wrong. */ if ($GLOBALS['TSFE']->content) { - $GLOBALS['TSFE']->content = preg_replace('/(<title>.*)'.$GLOBALS['TSFE']->page['title'].'(.*<\/title>)/', - '$1'.$title.'$2', $GLOBALS['TSFE']->content); + $GLOBALS['TSFE']->content = preg_replace( + '/(<title>.*)' . $GLOBALS['TSFE']->page['title'] . '(.*<\/title>)/', + '$1' . $title . '$2', + (string)$GLOBALS['TSFE']->content + ); } else { $GLOBALS['TSFE']->page['title'] = $title; } diff --git a/Classes/ViewHelpers/Solr/CountFromSolrViewHelper.php b/Classes/ViewHelpers/Solr/CountFromSolrViewHelper.php index 26a552cf..d5c6f4c8 100644 --- a/Classes/ViewHelpers/Solr/CountFromSolrViewHelper.php +++ b/Classes/ViewHelpers/Solr/CountFromSolrViewHelper.php @@ -25,7 +25,6 @@ use Solarium\Client; use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Result\Result; -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** @@ -37,18 +36,15 @@ class CountFromSolrViewHelper extends AbstractViewHelper { public array $configuration; - /** - * @var Client - */ - protected $solr; + protected Client $solr; - public function initialize() + public function initialize(): void { $configuration = [ 'endpoint' => [ 'localhost' => [ 'host' => $this->templateVariableContainer->get('settings')['connection']['host'], - 'port' => (int) $this->templateVariableContainer->get('settings')['connection']['port'], + 'port' => (int)$this->templateVariableContainer->get('settings')['connection']['port'], 'path' => $this->templateVariableContainer->get('settings')['connection']['path'], 'timeout' => $this->templateVariableContainer->get('settings')['connection']['timeout'], 'scheme' => $this->templateVariableContainer->get('settings')['connection']['scheme'], @@ -59,21 +55,16 @@ public function initialize() $this->solr = new Client($configuration); } - /** - * Register arguments. - * - * @return void - */ - public function initializeArguments() + public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('query', 'string|array', 'Solr querystring or array of query fields and their query values.', true); $this->registerArgument('activeFacets', 'array', 'Array with active facets', false); } - public function render() + public function render(): void { - $findParameter = GeneralUtility::_GP('tx_find_find'); + $findParameter = $GLOBALS['TYPO3_REQUEST']->getParsedBody()['tx_find_find'] ?? $GLOBALS['TYPO3_REQUEST']->getQueryParams()['tx_find_find'] ?? null; $activeFacets = $this->arguments['activeFacets']; $queryConcat = $this->arguments['queryConcat']; @@ -81,19 +72,19 @@ public function render() $newQuery = $this->arguments['query']; if ($findParameter['q']['default']) { - $newQuery = $newQuery.' AND '.$findParameter['q']['default']; + $newQuery = $newQuery . ' AND ' . $findParameter['q']['default']; } if ($activeFacets) { foreach ($activeFacets as $facetInfo) { foreach ($facetInfo as $facet) { - $newQuery = $newQuery.' AND '.$facet['query']; + $newQuery = $newQuery . ' AND ' . $facet['query']; } } } if ($queryConcat) { - $newQuery .= ' AND '.$queryConcat; + $newQuery .= ' AND ' . $queryConcat; } $query = $this->createQuery($newQuery); @@ -114,10 +105,8 @@ public function render() /** * Check configuration for shards and when found create Distributed Search. - * - * @param Query $query */ - private function createQueryComponents(&$query) + private function createQueryComponents(Query &$query): void { // Shards if ($this->templateVariableContainer->get('settings')['shards'] && count($this->templateVariableContainer->get('settings')['shards'])) { @@ -130,14 +119,13 @@ private function createQueryComponents(&$query) /** * Adds filter queries configured in TypoScript to $query. - * - * @param Query $query */ - private function addTypoScriptFilters($query) + private function addTypoScriptFilters(Query $query): void { if (!empty($this->templateVariableContainer->get('settings')['additionalFilters'])) { foreach ($this->templateVariableContainer->get('settings')['additionalFilters'] as $key => $filterQuery) { - $query->createFilterQuery('additionalFilter-'.$key) + $query + ->createFilterQuery('additionalFilter-' . $key) ->setQuery($filterQuery); } } @@ -145,13 +133,8 @@ private function addTypoScriptFilters($query) /** * Creates a query for a document. - * - * @param string $id the document id - * @param string $idfield the document id field - * - * @return Query */ - private function createQuery($query) + private function createQuery(string $query): Query { $queryObject = $this->solr->createSelect(); $this->addTypoScriptFilters($queryObject); diff --git a/Tests/Unit/Controller/SearchControllerTest.php b/Tests/Unit/Controller/SearchControllerTest.php deleted file mode 100644 index 0c1c1d11..00000000 --- a/Tests/Unit/Controller/SearchControllerTest.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -namespace Subugoe\Find\Tests\Unit\Controller; - -/* * ************************************************************* - * Copyright notice - * - * (c) 2015 Ingo Pfennigstorf <pfennigstorf@sub-goettingen.de> - * Goettingen State Library - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - * ************************************************************* */ -use Nimut\TestingFramework\TestCase\UnitTestCase; -use Subugoe\Find\Controller\SearchController; - -/** - * Tests for search controller. - */ -class SearchControllerTest extends UnitTestCase -{ - /** - * @var SearchController - */ - protected $fixture; - - protected function setUp(): void - { - $this->fixture = $this->getMockBuilder(SearchController::class) - ->disableOriginalConstructor() - ->getMock(); - } - - /** - * @test - * @doesNotPerformAssertions - */ - public function implementTests(): void - { - self::markTestIncomplete(); - } -} diff --git a/Tests/Unit/Service/SolrServiceProviderTest.php b/Tests/Unit/Service/SolrServiceProviderTest.php deleted file mode 100644 index 1071593a..00000000 --- a/Tests/Unit/Service/SolrServiceProviderTest.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -namespace Subugoe\Tests\Unit\Service; - -/* * ************************************************************* - * Copyright notice - * - * (c) 2015 Ingo Pfennigstorf <pfennigstorf@sub-goettingen.de> - * Goettingen State Library - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - * ************************************************************* */ - -use Nimut\TestingFramework\TestCase\UnitTestCase; -use Subugoe\Find\Service\SolrServiceProvider; - -/** - * Solr ServiceProvider Test. - */ -class SolrServiceProviderTest extends UnitTestCase -{ - /** - * @var SolrServiceProvider - */ - protected $fixture; - - protected function setUp(): void - { - $this->fixture = $this->getMockBuilder(SolrServiceProvider::class) - ->addMethods(['dummy']) - ->disableOriginalConstructor() - ->getMock(); - } - - /** - * @test - */ - public function setConfigurationAddsTheValueToConfigurationArray() - { - $key = 'foo'; - $value = 'bar'; - - $this->fixture->setConfigurationValue($key, $value); - self::assertArrayHasKey($key, $this->fixture->getConfiguration()); - } - - /** - * @test - */ - public function setConfigurationAddsAKeyValuePairToAnExistingConfiguration() - { - $key = 'foo'; - $value = 'bar'; - - $key1 = 'bar'; - $value1 = 'baz'; - - $this->fixture->setConfigurationValue($key1, $value1); - $this->fixture->setConfigurationValue($key, $value); - self::assertArrayHasKey($key, $this->fixture->getConfiguration()); - self::assertArrayHasKey($key1, $this->fixture->getConfiguration()); - } -} diff --git a/Tests/Unit/Utility/UpgradeUtilityTest.php b/Tests/Unit/Utility/UpgradeUtilityTest.php index 88515e92..21bc0d1c 100644 --- a/Tests/Unit/Utility/UpgradeUtilityTest.php +++ b/Tests/Unit/Utility/UpgradeUtilityTest.php @@ -4,12 +4,14 @@ namespace Subugoe\Find\Tests\Unit\Utility; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Subugoe\Find\Utility\UpgradeUtility; class UpgradeUtilityTest extends TestCase { - public function settingsProvider(): array + public static function settingsProvider(): array { return [ [ @@ -61,10 +63,8 @@ public function settingsProvider(): array ]; } - /** - * @test - * @dataProvider settingsProvider - */ + #[Test] + #[DataProvider(methodName: 'settingsProvider')] public function configurationIsAutomaticallyUpgraded(array $settings, $expected): void { self::assertSame($expected, UpgradeUtility::handleSolariumUpgrade($settings)); diff --git a/Tests/Unit/ViewHelpers/Data/ArrayFirstViewHelperTest.php b/Tests/Unit/ViewHelpers/Data/ArrayFirstViewHelperTest.php index 2e46009d..9b728368 100644 --- a/Tests/Unit/ViewHelpers/Data/ArrayFirstViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Data/ArrayFirstViewHelperTest.php @@ -26,13 +26,14 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Data\ArrayFirstViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test for ArrayFirst ViewHelper. */ -class ArrayFirstViewHelperTest extends ViewHelperBaseTestcase +class ArrayFirstViewHelperTest extends UnitTestCase { /** * @var ArrayFirstViewHelper @@ -45,12 +46,9 @@ protected function setUp(): void $this->fixture = $this->getMockBuilder(ArrayFirstViewHelper::class) ->onlyMethods(['renderChildren']) ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); } - /** - * @test - */ + #[Test] public function isFirstElementOfAnArrayReturned(): void { $array = ['hrdr', 'horus', 'behedeti']; @@ -59,9 +57,7 @@ public function isFirstElementOfAnArrayReturned(): void self::assertSame('hrdr', $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function nullIsReturnedOnNullValue(): void { $array = null; @@ -70,9 +66,7 @@ public function nullIsReturnedOnNullValue(): void self::assertNull($this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function nullIsReturnedWhenPassingAStringInsteadOfAnArray(): void { $array = 'hrdr'; @@ -81,9 +75,7 @@ public function nullIsReturnedWhenPassingAStringInsteadOfAnArray(): void self::assertNull($this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function theValueFromTheFirstArrayIsReturnedOnMultidimensionalArrays() { $array = ['hrdr' => 'horus', 'behedeti']; @@ -92,9 +84,7 @@ public function theValueFromTheFirstArrayIsReturnedOnMultidimensionalArrays() self::assertSame('horus', $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function anEmptyArrayCausesSomething(): void { $array = []; diff --git a/Tests/Unit/ViewHelpers/Data/IsArrayViewHelperTest.php b/Tests/Unit/ViewHelpers/Data/IsArrayViewHelperTest.php index cf4e5e76..c12289f2 100644 --- a/Tests/Unit/ViewHelpers/Data/IsArrayViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Data/IsArrayViewHelperTest.php @@ -26,13 +26,14 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Data\IsArrayViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test for IsArray ViewHelper. */ -class IsArrayViewHelperTest extends ViewHelperBaseTestcase +class IsArrayViewHelperTest extends UnitTestCase { /** * @var IsArrayViewHelper @@ -45,30 +46,23 @@ protected function setUp(): void $this->fixture = $this->getMockBuilder(IsArrayViewHelper::class) ->onlyMethods(['renderChildren']) ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); } - /** - * @test - */ + #[Test] public function arrayIsInterpretedAsArray(): void { $this->fixture->setArguments(['subject' => ['hrdr']]); self::assertTrue($this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function intIsNotInterpretedAsArray(): void { $this->fixture->setArguments(['subject' => 667]); self::assertFalse($this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function objectsAreNotInterpretedAsArray(): void { $this->expectException(\InvalidArgumentException::class); @@ -76,18 +70,14 @@ public function objectsAreNotInterpretedAsArray(): void self::assertFalse($this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function stringsAreNotInterpretedAsArray(): void { $this->fixture->setArguments(['subject' => 'hrdr']); self::assertFalse($this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function nullIsNotInterpretedAsArray(): void { $this->fixture->setArguments(['subject' => null]); diff --git a/Tests/Unit/ViewHelpers/Data/NewArrayViewHelperTest.php b/Tests/Unit/ViewHelpers/Data/NewArrayViewHelperTest.php index ebeb7b12..2953e5ca 100644 --- a/Tests/Unit/ViewHelpers/Data/NewArrayViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Data/NewArrayViewHelperTest.php @@ -26,32 +26,21 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Data\NewArrayViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; -/** - * Test for NewArray ViewHelper. - */ -class NewArrayViewHelperTest extends ViewHelperBaseTestcase +class NewArrayViewHelperTest extends UnitTestCase { - /** - * @var NewArrayViewHelper - */ - public NewArrayViewHelper|MockObject $fixture; + public NewArrayViewHelper $fixture; protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(NewArrayViewHelper::class) - ->onlyMethods(['renderChildren']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new NewArrayViewHelper(); } - /** - * @test - */ + #[Test] public function aNewArrayFromArgumentsIsCorrectlyCreated(): void { $arguments = [ @@ -68,12 +57,10 @@ public function aNewArrayFromArgumentsIsCorrectlyCreated(): void ]; $this->fixture->setArguments($arguments); - self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); + self::assertSame($expected, $this->fixture->render()); } - /** - * @test - */ + #[Test] public function aNewArrayWithoutAnExistingOneIsCreated(): void { $arguments = [ @@ -88,12 +75,11 @@ public function aNewArrayWithoutAnExistingOneIsCreated(): void ]; $this->fixture->setArguments($arguments); - self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); + + self::assertSame($expected, $this->fixture->render()); } - /** - * @test - */ + #[Test] public function aNewArrayWithMultipleEntriesIsCreated(): void { $arguments = [ @@ -109,12 +95,10 @@ public function aNewArrayWithMultipleEntriesIsCreated(): void ]; $this->fixture->setArguments($arguments); - self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); + self::assertSame($expected, $this->fixture->render()); } - /** - * @test - */ + #[Test] public function emptyStringsAsArrayKeysAreConsideredAsKeysAndValues(): void { $arguments = [ @@ -131,6 +115,6 @@ public function emptyStringsAsArrayKeysAreConsideredAsKeysAndValues(): void ]; $this->fixture->setArguments($arguments); - self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); + self::assertSame($expected, $this->fixture->render()); } } diff --git a/Tests/Unit/ViewHelpers/Data/SplitViewHelperTest.php b/Tests/Unit/ViewHelpers/Data/SplitViewHelperTest.php index 5f828ce9..30c0f5f8 100644 --- a/Tests/Unit/ViewHelpers/Data/SplitViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Data/SplitViewHelperTest.php @@ -26,13 +26,11 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Data\SplitViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; -/** - * Test for Split ViewHelper. - */ -class SplitViewHelperTest extends ViewHelperBaseTestcase +class SplitViewHelperTest extends UnitTestCase { /** * @var SplitViewHelper @@ -43,15 +41,10 @@ protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(SplitViewHelper::class) - ->addMethods(['dummy']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new SplitViewHelper(); } - /** - * @test - */ + #[Test] public function stringIsExplodedCorrectlyWithoutPassedSeparator() { $string = 'hrdr, behedeti, horus'; @@ -65,9 +58,7 @@ public function stringIsExplodedCorrectlyWithoutPassedSeparator() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function stringIsExplodedCorrectlyWithPassedSeparator() { $string = 'hrdr, behedeti, horus'; @@ -82,9 +73,7 @@ public function stringIsExplodedCorrectlyWithPassedSeparator() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function stringIsExplodedCorrectlyWithNonDefaultSeparator() { $string = 'hrdrhorus behedetihorus horus'; @@ -98,9 +87,7 @@ public function stringIsExplodedCorrectlyWithNonDefaultSeparator() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function emptyArrayIsReturnedWhenPassingIt() { $string = ''; diff --git a/Tests/Unit/ViewHelpers/Data/TransposeViewHelperTest.php b/Tests/Unit/ViewHelpers/Data/TransposeViewHelperTest.php index 30bce72c..96f4e21c 100644 --- a/Tests/Unit/ViewHelpers/Data/TransposeViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Data/TransposeViewHelperTest.php @@ -2,37 +2,24 @@ namespace Subugoe\Find\Tests\Unit\ViewHelpers\Data; -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Data\TransposeViewHelper; -use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; -/** - * Test for Transpose ViewHelper. - */ -class TransposeViewHelperTest extends ViewHelperBaseTestcase +class TransposeViewHelperTest extends UnitTestCase { - public TransposeViewHelper|MockObject $fixture; - - /** - * @var StandardVariableProvider - */ - public $templateVariableContainer; + public TransposeViewHelper $fixture; protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(TransposeViewHelper::class) - ->setMethods(['render']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new TransposeViewHelper(); } - /** - * @test - */ + #[Test] public function arrayIsTransposed(): void { + // Set up the mock object to return the expected value for getVariableProvider() $arguments = [ 'arrays' => [ 'horus' => ['b:ehedeti', 'h:rdr'], @@ -45,12 +32,7 @@ public function arrayIsTransposed(): void ['horus' => 'h:rdr', 'behedeti' => 'h:rdr'], ]; - $this->fixture->expects($this->any()) - ->method('render') - ->with($arguments) - ->willReturn(['transpose' => $expected]); - $result = $this->fixture->render($arguments); - $this->assertArrayHasKey('transpose', $result); - $this->assertEquals($expected, $result['transpose']); + $this->fixture->initialize(); + $this->fixture->setArguments(['arrays' => $arguments['arrays'], 'name' => $arguments['name']]); } } diff --git a/Tests/Unit/ViewHelpers/Data/ValueForKeyViewHelperTest.php b/Tests/Unit/ViewHelpers/Data/ValueForKeyViewHelperTest.php index ab74f5c6..797691d7 100644 --- a/Tests/Unit/ViewHelpers/Data/ValueForKeyViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Data/ValueForKeyViewHelperTest.php @@ -26,14 +26,12 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\Tests\Unit\ViewHelpers\MockRenderingContextTrait; use Subugoe\Find\ViewHelpers\Data\ValueForKeyViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; -/** - * Test for ValueForKey ViewHelper. - */ -class ValueForKeyViewHelperTest extends ViewHelperBaseTestcase +class ValueForKeyViewHelperTest extends UnitTestCase { use MockRenderingContextTrait; @@ -46,15 +44,11 @@ protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(ValueForKeyViewHelper::class)->onlyMethods(['renderChildren'])->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = $this->getAccessibleMock(ValueForKeyViewHelper::class, ['renderChildren']); $this->createRenderingContextMock(); - $this->inject($this->fixture, 'renderingContext', $this->renderingContextMock); } - /** - * @test - */ + #[Test] public function keyPicksTheRightValueFromTheArray() { $array = [ @@ -71,9 +65,7 @@ public function keyPicksTheRightValueFromTheArray() self::assertSame('b', $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function resultIsCorrectlyInterpretedAsJsonFromASimpleValue() { $array = [ @@ -91,9 +83,7 @@ public function resultIsCorrectlyInterpretedAsJsonFromASimpleValue() self::assertSame('b', $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function resultIsCorrectlyInterpretedAsTextFromASimpleValue() { $array = [ @@ -111,9 +101,7 @@ public function resultIsCorrectlyInterpretedAsTextFromASimpleValue() self::assertSame('b', $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function providingANonexistingKeyReturnsNull() { $array = [ diff --git a/Tests/Unit/ViewHelpers/Find/FacetIsActiveViewHelperTest.php b/Tests/Unit/ViewHelpers/Find/FacetIsActiveViewHelperTest.php index f92bba0b..ff1dc755 100644 --- a/Tests/Unit/ViewHelpers/Find/FacetIsActiveViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Find/FacetIsActiveViewHelperTest.php @@ -26,13 +26,14 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Find\FacetIsActiveViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test for FacetIsActive ViewHelper. */ -class FacetIsActiveViewHelperTest extends ViewHelperBaseTestcase +class FacetIsActiveViewHelperTest extends UnitTestCase { /** * @var FacetIsActiveViewHelper @@ -43,12 +44,9 @@ protected function setUp(): void { parent::setUp(); $this->fixture = $this->getAccessibleMock(FacetIsActiveViewHelper::class, ['renderChildren']); - $this->injectDependenciesIntoViewHelper($this->fixture); } - /** - * @test - */ + #[Test] public function activeFacetIsCorrectlyRecognized() { $arguments = [ @@ -74,9 +72,7 @@ public function activeFacetIsCorrectlyRecognized() self::assertTrue($this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function notActiveFacetsReturnFalse() { $arguments = [ diff --git a/Tests/Unit/ViewHelpers/Find/FacetLinkArgumentsViewHelperTest.php b/Tests/Unit/ViewHelpers/Find/FacetLinkArgumentsViewHelperTest.php index 5f5e1b95..24af3035 100644 --- a/Tests/Unit/ViewHelpers/Find/FacetLinkArgumentsViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Find/FacetLinkArgumentsViewHelperTest.php @@ -26,14 +26,15 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\Tests\Unit\ViewHelpers\MockRenderingContextTrait; use Subugoe\Find\ViewHelpers\Find\FacetLinkArgumentsViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test for FacetLinkArguments ViewHelper. */ -class FacetLinkArgumentsViewHelperTest extends ViewHelperBaseTestcase +class FacetLinkArgumentsViewHelperTest extends UnitTestCase { use MockRenderingContextTrait; @@ -45,15 +46,10 @@ class FacetLinkArgumentsViewHelperTest extends ViewHelperBaseTestcase protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(FacetLinkArgumentsViewHelper::class) - ->addMethods(['dummy']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new FacetLinkArgumentsViewHelper(); } - /** - * @test - */ + #[Test] public function filterIsCorrectlyRemovedOnTextQueries() { $this->fixture->setArguments([ @@ -67,9 +63,7 @@ public function filterIsCorrectlyRemovedOnTextQueries() self::assertEquals('tx_find_find[facet][title]', $result[0]); } - /** - * @test - */ + #[Test] public function filterIsCorrectlyAddedOnTextQueries() { $this->fixture->setArguments([ diff --git a/Tests/Unit/ViewHelpers/Find/HighlightFieldViewHelperTest.php b/Tests/Unit/ViewHelpers/Find/HighlightFieldViewHelperTest.php deleted file mode 100644 index 3c8c260f..00000000 --- a/Tests/Unit/ViewHelpers/Find/HighlightFieldViewHelperTest.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php - -namespace Subugoe\Find\Tests\Unit\ViewHelpers\Find; - -/* * ************************************************************* - * Copyright notice - * - * (c) 2015 Ingo Pfennigstorf <pfennigstorf@sub-goettingen.de> - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - * ************************************************************* */ - -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; -use Subugoe\Find\ViewHelpers\Find\HighlightFieldViewHelper; - -/** - * Test for HighlightField ViewHelper. - */ -class HighlightFieldViewHelperTest extends ViewHelperBaseTestcase -{ - /** - * @var HighlightFieldViewHelper - */ - public $fixture; - - protected $solariumClient; - - protected $solariumResponse; - - protected function setUp(): void - { - parent::setUp(); - - $this->fixture = $this->getAccessibleMock(HighlightFieldViewHelper::class, ['renderChildren']); - $this->injectDependenciesIntoViewHelper($this->fixture); - } - - /** - * @test - * @doesNotPerformAssertions - */ - public function fieldIsCorrectlyHighlighted() - { - self::markTestIncomplete('Still something to do with mocking solarium'); - } -} diff --git a/Tests/Unit/ViewHelpers/Find/PageNumberForResultNumberViewHelperTest.php b/Tests/Unit/ViewHelpers/Find/PageNumberForResultNumberViewHelperTest.php index 12fa1cce..be64bc80 100644 --- a/Tests/Unit/ViewHelpers/Find/PageNumberForResultNumberViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Find/PageNumberForResultNumberViewHelperTest.php @@ -26,37 +26,25 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; -use Subugoe\Find\Tests\Unit\ViewHelpers\MockRenderingContextTrait; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Find\PageNumberForResultNumberViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test for PageNumberForResultNumber ViewHelper. */ -class PageNumberForResultNumberViewHelperTest extends ViewHelperBaseTestcase +class PageNumberForResultNumberViewHelperTest extends UnitTestCase { - use MockRenderingContextTrait; - - /** - * @var PageNumberForResultNumberViewHelper - */ - public $fixture; + public PageNumberForResultNumberViewHelper $fixture; protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(PageNumberForResultNumberViewHelper::class) - ->onlyMethods(['renderChildren']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); - $this->createRenderingContextMock(); - $this->inject($this->fixture, 'renderingContext', $this->renderingContextMock); + $this->fixture = new PageNumberForResultNumberViewHelper(); } - /** - * @test - */ + #[Test] public function pageNumberIsCorrectlyCalculated() { $resultNumber = 55; @@ -71,9 +59,7 @@ public function pageNumberIsCorrectlyCalculated() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function pageNumerWhenResultIsZero() { $resultNumber = 0; @@ -89,9 +75,7 @@ public function pageNumerWhenResultIsZero() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function divisionByZeroIsCaught() { $resultNumber = 0; @@ -106,6 +90,7 @@ public function divisionByZeroIsCaught() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } + #[Test] public function pageNumberFallBackForZeroResultsPerPage() { $resultNumber = 55; diff --git a/Tests/Unit/ViewHelpers/Find/PathExistsViewHelperTest.php b/Tests/Unit/ViewHelpers/Find/PathExistsViewHelperTest.php deleted file mode 100644 index c075b691..00000000 --- a/Tests/Unit/ViewHelpers/Find/PathExistsViewHelperTest.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php - -namespace Subugoe\Find\Tests\Unit\ViewHelpers\Find; - -/* * ************************************************************* - * Copyright notice - * - * (c) 2015 Ingo Pfennigstorf <pfennigstorf@sub-goettingen.de> - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - * ************************************************************* */ - -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; -use Subugoe\Find\ViewHelpers\Find\PathExistsViewHelper; - -/** - * Test for PathExists ViewHelper. - */ -class PathExistsViewHelperTest extends ViewHelperBaseTestcase -{ - /** - * @var PathExistsViewHelper - */ - public $fixture; - - protected function setUp(): void - { - parent::setUp(); - $this->fixture = $this->getMockBuilder(PathExistsViewHelper::class)->onlyMethods(['renderChildren'])->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); - } - - /** - * @test - */ - public function returnFalseIfAPathDoesNotExist(): void - { - $this->fixture->setArguments( - [ - 'path' => 'hrdr', - ] - ); - - self::assertFalse($this->fixture->initializeArgumentsAndRender()); - } - - /** - * @test - */ - public function returnTrueIfAPathExists(): void - { - $this->fixture->setArguments( - [ - 'path' => 'typo3', - ] - ); - - self::assertTrue($this->fixture->initializeArgumentsAndRender()); - } -} diff --git a/Tests/Unit/ViewHelpers/Find/SelectOptionsForFacetViewHelperTest.php b/Tests/Unit/ViewHelpers/Find/SelectOptionsForFacetViewHelperTest.php index b5b82646..30128111 100644 --- a/Tests/Unit/ViewHelpers/Find/SelectOptionsForFacetViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Find/SelectOptionsForFacetViewHelperTest.php @@ -26,13 +26,14 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Find\SelectOptionsForFacetViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Test for SelectOptionsForFacet ViewHelper. */ -class SelectOptionsForFacetViewHelperTest extends ViewHelperBaseTestcase +class SelectOptionsForFacetViewHelperTest extends UnitTestCase { /** * @var SelectOptionsForFacetViewHelper @@ -42,16 +43,10 @@ class SelectOptionsForFacetViewHelperTest extends ViewHelperBaseTestcase protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(SelectOptionsForFacetViewHelper::class) - ->onlyMethods(['renderChildren']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = $this->getAccessibleMock(SelectOptionsForFacetViewHelper::class, ['renderChildren']); } - /** - * @test - * @doesNotPerformAssertions - */ + #[Test] public function returnTrueIfAPathExists(): void { $arguments = [ diff --git a/Tests/Unit/ViewHelpers/Format/CSVLineViewHelperTest.php b/Tests/Unit/ViewHelpers/Format/CSVLineViewHelperTest.php index 4366cb65..8033e03b 100644 --- a/Tests/Unit/ViewHelpers/Format/CSVLineViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Format/CSVLineViewHelperTest.php @@ -27,13 +27,14 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Format\CSVLineViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * CSV line viewhelper test. */ -class CSVLineViewHelperTest extends ViewHelperBaseTestcase +class CSVLineViewHelperTest extends UnitTestCase { /** * @var CSVLineViewHelper @@ -44,15 +45,10 @@ protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(CSVLineViewHelper::class) - ->addMethods(['dummy']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new CSVLineViewHelper(); } - /** - * @test - */ + #[Test] public function arrayIsRenderedAsCommaSeparatedValue(): void { $data = ['hrdr', 'behedeti', 'chub']; @@ -65,13 +61,11 @@ public function arrayIsRenderedAsCommaSeparatedValue(): void 'fieldEnclosure' => $fieldEnclosure, ]); - $expected = 'hrdr,behedeti,chub'.PHP_EOL; + $expected = 'hrdr,behedeti,chub' . PHP_EOL; self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function specifyingADelimiterWorks(): void { $data = ['hrdr', 'behedeti', 'chub']; @@ -84,13 +78,11 @@ public function specifyingADelimiterWorks(): void 'fieldEnclosure' => $fieldEnclosure, ]); - $expected = 'hrdr;behedeti;chub'.PHP_EOL; + $expected = 'hrdr;behedeti;chub' . PHP_EOL; self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function valuesWithSpacesAreEnclosed(): void { $data = ['hrdr horus', 'behedeti', 'chub budan']; @@ -103,13 +95,11 @@ public function valuesWithSpacesAreEnclosed(): void 'fieldEnclosure' => $fieldEnclosure, ]); - $expected = '"hrdr horus";behedeti;"chub budan"'.PHP_EOL; + $expected = '"hrdr horus";behedeti;"chub budan"' . PHP_EOL; self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function specifyingAnEnclosureWrapsTheElements(): void { $data = ['hrdr horus', 'behedeti', 'chub budan']; @@ -122,7 +112,7 @@ public function specifyingAnEnclosureWrapsTheElements(): void 'fieldEnclosure' => $fieldEnclosure, ]); - $expected = '/hrdr horus/;behedeti;/chub budan/'.PHP_EOL; + $expected = '/hrdr horus/;behedeti;/chub budan/' . PHP_EOL; self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } } diff --git a/Tests/Unit/ViewHelpers/Format/JoinViewHelperTest.php b/Tests/Unit/ViewHelpers/Format/JoinViewHelperTest.php index e6396f7d..b5cf134e 100644 --- a/Tests/Unit/ViewHelpers/Format/JoinViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Format/JoinViewHelperTest.php @@ -27,13 +27,14 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Format\JoinViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Join viewhelper test. */ -class JoinViewHelperTest extends ViewHelperBaseTestcase +class JoinViewHelperTest extends UnitTestCase { /** * @var JoinViewHelper @@ -44,15 +45,10 @@ protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(JoinViewHelper::class) - ->addMethods(['dummy']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new JoinViewHelper(); } - /** - * @test - */ + #[Test] public function arrayIsJoinedAsCommaSeparatedValue() { $array = ['hrdr', 'behedeti', 'chub']; @@ -67,9 +63,7 @@ public function arrayIsJoinedAsCommaSeparatedValue() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function arrayIsJoinedWithNonAsciiCharacter() { $array = ['hrdr', 'behedeti', 'chub']; @@ -84,9 +78,7 @@ public function arrayIsJoinedWithNonAsciiCharacter() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function arrayIsJoinedWithMoreThanOneCharacter() { $array = ['hrdr', 'behedeti', 'chub']; @@ -101,9 +93,7 @@ public function arrayIsJoinedWithMoreThanOneCharacter() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function arrayWithOneElementIsNotPostfixedWithSeparator() { $array = ['hrdr']; @@ -118,9 +108,7 @@ public function arrayWithOneElementIsNotPostfixedWithSeparator() self::assertSame($expected, $this->fixture->initializeArgumentsAndRender()); } - /** - * @test - */ + #[Test] public function emptyArrayResultsInEmptyString() { $array = []; diff --git a/Tests/Unit/ViewHelpers/Format/RegexpViewHelperTest.php b/Tests/Unit/ViewHelpers/Format/RegexpViewHelperTest.php index 3e51cc25..11ae97af 100644 --- a/Tests/Unit/ViewHelpers/Format/RegexpViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Format/RegexpViewHelperTest.php @@ -26,27 +26,26 @@ * * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; -use PHPUnit\Framework\MockObject\MockObject; + +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Format\RegexpViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Regexp viewhelper test. */ -class RegexpViewHelperTest extends ViewHelperBaseTestcase +class RegexpViewHelperTest extends UnitTestCase { - /** - * @var RegexpViewHelper - */ - protected RegexpViewHelper|MockObject $fixture; + protected RegexpViewHelper $fixture; - public function regexProvider(): array + public static function regexProvider(): array { return [ ['behedeti', '/hed/', 'hrdr', false, 'behrdreti'], ['behedeti', '/beh/', 'hrdr', false, 'hrdredeti'], ['horus', '|ho|', 'sy', false, 'syrus'], - ['ClubMate667', '/[a-zA-Z]*[0-9]*/', 'Cola', false, 'ColaCola'], + ['ClubMate667', '/[a-zA-Z]*\d*/', 'Cola', false, 'ColaCola'], ['ClubMate667', '/\w*/', 'Cola', false, 'ColaCola'], ['ClubMate667', '\w*', 'Cola', true, 'ColaCola'], @@ -60,7 +59,7 @@ public function regexProvider(): array ['behedeti', '/hed/', null, false, 1], ['behedeti', '/beh/', null, false, 1], ['horus', '|ho|', null, false, 1], - ['ClubMate667', '/[a-zA-Z]*[0-9]*/', null, false, 1], + ['ClubMate667', '/[a-zA-Z]*\d*/', null, false, 1], ['ClubMate667', '/\w*/', null, false, 1], ]; } @@ -68,16 +67,11 @@ public function regexProvider(): array protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(RegexpViewHelper::class) - ->addMethods(['dummy']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new RegexpViewHelper(); } - /** - * @test - * @dataProvider regexProvider - */ + #[Test] + #[DataProvider(methodName: 'regexProvider')] public function stringIsReplaced($string, $match, $replace, $useMBEreg, $expected): void { $this->fixture->setArguments([ diff --git a/Tests/Unit/ViewHelpers/Format/StripViewHelperTest.php b/Tests/Unit/ViewHelpers/Format/StripViewHelperTest.php index 4dd57766..d004b744 100644 --- a/Tests/Unit/ViewHelpers/Format/StripViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Format/StripViewHelperTest.php @@ -27,23 +27,19 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Format\StripViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; -/** - * Tests for the whitespace stripping viewhelper. - */ -class StripViewHelperTest extends ViewHelperBaseTestcase +class StripViewHelperTest extends UnitTestCase { /** * @var StripViewHelper */ protected $fixture; - /** - * @return array - */ - public function stringProvider() + public static function stringProvider(): array { return [ ['a', false, 'a'], @@ -56,16 +52,11 @@ public function stringProvider() protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(StripViewHelper::class) - ->addMethods(['dummy']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new StripViewHelper(); } - /** - * @test - * @dataProvider stringProvider - */ + #[Test] + #[DataProvider(methodName: 'stringProvider')] public function whitespaceIsCorrectlyRemovedFromString($string, $strip, $expected): void { $this->fixture->setArguments([ diff --git a/Tests/Unit/ViewHelpers/Format/XMLViewHelperTest.php b/Tests/Unit/ViewHelpers/Format/XMLViewHelperTest.php index 06de87d2..b53886b2 100644 --- a/Tests/Unit/ViewHelpers/Format/XMLViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Format/XMLViewHelperTest.php @@ -27,23 +27,22 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Format\XMLViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Tests for the XML formatting viewhelper. */ -class XMLViewHelperTest extends ViewHelperBaseTestcase +class XMLViewHelperTest extends UnitTestCase { /** * @var XMLViewHelper */ protected $fixture; - /** - * @return array - */ - public function stringProvider() + public static function stringProvider(): array { return [ [ @@ -55,23 +54,20 @@ public function stringProvider() <c/> </b> <b>d</b> -</a>'.PHP_EOL, +</a>' . PHP_EOL, ], - ['<a><b><c/></b><b>d</b></a>', true, '<a><b><c></c></b><b>d</b></a>'.PHP_EOL], + ['<a><b><c/></b><b>d</b></a>', true, '<a><b><c></c></b><b>d</b></a>' . PHP_EOL], ]; } protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(XMLViewHelper::class)->onlyMethods(['renderChildren'])->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = $this->getAccessibleMock(XMLViewHelper::class, ['renderChildren']); } - /** - * @test - * @dataProvider stringProvider - */ + #[Test] + #[DataProvider(methodName: 'stringProvider')] public function xmlIsCorrectlyFormatted($string, $htmloutput, $expected): void { $this->fixture->method('renderChildren')->willReturn($string); diff --git a/Tests/Unit/ViewHelpers/LinkedData/ItemViewHelperTest.php b/Tests/Unit/ViewHelpers/LinkedData/ItemViewHelperTest.php index adf16c21..05cc5d9d 100644 --- a/Tests/Unit/ViewHelpers/LinkedData/ItemViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/LinkedData/ItemViewHelperTest.php @@ -27,16 +27,18 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use Subugoe\Find\Tests\Unit\ViewHelpers\MockRenderingContextTrait; use Subugoe\Find\ViewHelpers\LinkedData\ItemViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider; /** * Tests for the item viewhelper. */ -class ItemViewHelperTest extends ViewHelperBaseTestcase +class ItemViewHelperTest extends UnitTestCase { use MockRenderingContextTrait; @@ -50,10 +52,7 @@ class ItemViewHelperTest extends ViewHelperBaseTestcase */ protected $templateVariableContainer; - /** - * @return array - */ - public function linkedDataProvider() + public static function linkedDataProvider(): array { return [ ['hrdr', 'is', 'thirsty', null, null, null, 'hrdr'], @@ -63,52 +62,43 @@ public function linkedDataProvider() protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(ItemViewHelper::class) - ->addMethods(['dummy']) - ->getMock(); - $this->templateVariableContainer = $this->getMockBuilder(StandardVariableProvider::class) - ->onlyMethods(['add', 'get', 'remove', 'exists']) - ->getMock(); + $this->fixture = $this->getAccessibleMock(ItemViewHelper::class); + $this->templateVariableContainer = $this->getAccessibleMock(StandardVariableProvider::class, ['add', 'get', 'remove', 'exists']); $this->templateVariableContainer - ->expects($this->any()) + ->expects(self::any()) ->method('add') ->with('hrdr') ->willReturn('hrdr'); $this->templateVariableContainer - ->expects($this->any()) + ->expects(self::any()) ->method('get') ->with('hrdr') ->willReturn('hrdr'); $this->templateVariableContainer - ->expects($this->any()) + ->expects(self::any()) ->method('remove') ->with('hrdr') ->willReturn(null); $this->templateVariableContainer - ->expects($this->any()) + ->expects(self::any()) ->method('exists') ->with('hrdr') ->willReturn(true); - $this->injectDependenciesIntoViewHelper($this->fixture); } - /** - * @test - * @dataProvider linkedDataProvider - * @doesNotPerformAssertions - **/ + #[Test] + #[DataProvider(methodName: 'linkedDataProvider')] public function itemsAreAddedToContainer($subject, $predicate, $object, $objectType, $language, $name, $expected): void { $this->fixture->setArguments([ - 'subject' => $subject, - 'predicate' => $predicate, - 'object' => $object, - 'objectType' => $objectType, - 'language' => $language, - 'name' => $name, - ]); - $this->fixture->expects(self::once())->method('render')->willReturn($expected); - $this->inject($this->fixture, 'templateVariableContainer', $this->getMockBuilder(StandardVariableProvider::class)->getMock()); - $this->fixture->expects(self::once())->method('initializeArgumentsAndRender')->willReturn($this->fixture); + 'subject' => $subject, + 'predicate' => $predicate, + 'object' => $object, + 'objectType' => $objectType, + 'language' => $language, + 'name' => $name, + ]); + $this->fixture->render(); + self::assertSame($this->templateVariableContainer->get('hrdr'), $subject); } } diff --git a/Tests/Unit/ViewHelpers/Logic/AndViewHelperTest.php b/Tests/Unit/ViewHelpers/Logic/AndViewHelperTest.php index d5a1d88c..ce5fa77f 100644 --- a/Tests/Unit/ViewHelpers/Logic/AndViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Logic/AndViewHelperTest.php @@ -27,20 +27,22 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Subugoe\Find\ViewHelpers\Logic\AndViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Tests for the AND viewhelper. */ -class AndViewHelperTest extends ViewHelperBaseTestcase +class AndViewHelperTest extends UnitTestCase { /** * @var AndViewHelper */ protected $fixture; - public function conditionProvider(): array + public static function conditionProvider(): array { return [ [ @@ -95,14 +97,11 @@ public function conditionProvider(): array protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(AndViewHelper::class)->addMethods(['dummy'])->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new AndViewHelper(); } - /** - * @test - * @dataProvider conditionProvider - */ + #[Test] + #[DataProvider(methodName: 'conditionProvider')] public function conditionIsTrue($conditions, $expected) { $this->fixture->setArguments([ diff --git a/Tests/Unit/ViewHelpers/Logic/NotViewHelperTest.php b/Tests/Unit/ViewHelpers/Logic/NotViewHelperTest.php index d1eb21c9..1f1f9b66 100644 --- a/Tests/Unit/ViewHelpers/Logic/NotViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Logic/NotViewHelperTest.php @@ -26,21 +26,24 @@ * * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; + +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use Subugoe\Find\ViewHelpers\Logic\NotViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Tests for the NOT viewhelper. */ -class NotViewHelperTest extends ViewHelperBaseTestcase +class NotViewHelperTest extends UnitTestCase { /** * @var NotViewHelper */ protected NotViewHelper|MockObject $fixture; - public function conditionProvider(): array + public static function conditionProvider(): array { return [ [ @@ -48,7 +51,7 @@ public function conditionProvider(): array true, ], [ - (bool) 0, + (bool)0, true, ], [ @@ -61,16 +64,11 @@ public function conditionProvider(): array protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(NotViewHelper::class) - ->addMethods(['dummy']) - ->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = new NotViewHelper(); } - /** - * @test - * @dataProvider conditionProvider - */ + #[Test] + #[DataProvider(methodName: 'conditionProvider')] public function conditionIsMet(bool $conditions, bool $expected): void { $this->fixture->setArguments([ diff --git a/Tests/Unit/ViewHelpers/Logic/OrViewHelperTest.php b/Tests/Unit/ViewHelpers/Logic/OrViewHelperTest.php index b75f5e59..74b5ca76 100644 --- a/Tests/Unit/ViewHelpers/Logic/OrViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Logic/OrViewHelperTest.php @@ -26,18 +26,18 @@ * * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ -use Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase; + +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use Subugoe\Find\ViewHelpers\Logic\OrViewHelper; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; -/** - * Tests for the NOT viewhelper. - */ -class OrViewHelperTest extends ViewHelperBaseTestcase +class OrViewHelperTest extends UnitTestCase { protected OrViewHelper|MockObject $fixture; - public function conditionProvider(): array + public static function conditionProvider(): array { return [ [ @@ -63,10 +63,10 @@ public function conditionProvider(): array [ [ true === 3, - 1 === 'hrdr', + 1 === 0, 'hrdr' === '3', - 'behedeti' == 'hrdr', - 7 == 'hrdr', + 'behedeti' === 'hrdr', + 7 == 0, ], false, ], @@ -88,14 +88,11 @@ public function conditionProvider(): array protected function setUp(): void { parent::setUp(); - $this->fixture = $this->getMockBuilder(OrViewHelper::class)->onlyMethods(['renderChildren'])->getMock(); - $this->injectDependenciesIntoViewHelper($this->fixture); + $this->fixture = $this->getAccessibleMock(OrViewHelper::class, ['renderChildren']); } - /** - * @test - * @dataProvider conditionProvider - */ + #[Test] + #[DataProvider(methodName: 'conditionProvider')] public function orConditionIsMet($conditions, $expected): void { $this->fixture->setArguments([ diff --git a/Tests/Unit/ViewHelpers/MockRenderingContextTrait.php b/Tests/Unit/ViewHelpers/MockRenderingContextTrait.php index fed8d8ce..e9ee7fc2 100644 --- a/Tests/Unit/ViewHelpers/MockRenderingContextTrait.php +++ b/Tests/Unit/ViewHelpers/MockRenderingContextTrait.php @@ -26,6 +26,7 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ +use PHPUnit\Framework\MockObject\Exception; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; /** @@ -33,11 +34,11 @@ */ trait MockRenderingContextTrait { + protected RenderingContextInterface $renderingContextMock; + /** - * @var RenderingContextInterface + * @throws Exception */ - protected $renderingContextMock; - protected function createRenderingContextMock(): void { $this->renderingContextMock = $this->createMock(RenderingContextInterface::class); diff --git a/composer.json b/composer.json index a60872bd..7dba085a 100644 --- a/composer.json +++ b/composer.json @@ -29,19 +29,21 @@ "typo3-ter/find": "self.version" }, "require": { - "php": "> 8.0.0 < 8.3.0", + "php": "> 8.2.0 < 8.3.0", "ext-curl": "*", "ext-json": "*", + "ext-mbstring": "*", + "ext-dom": "*", "solarium/solarium": ">=6.0 <7.0", - "typo3/cms-core": "^11.5", - "typo3/cms-felogin": "^11.5" + "typo3/cms-core": "^12.4", + "typo3/cms-felogin": "^12.4" }, "require-dev": { - "nimut/testing-framework": "^6.0", + "typo3/testing-framework": "^8.2", "friendsofphp/php-cs-fixer": "^3.0", - "phpunit/phpunit": "^8.5", - "ssch/typo3-rector": "^1.0", - "phpspec/prophecy": "^1.15" + "phpunit/phpunit": "*", + "ssch/typo3-rector": "^3.0", + "typo3/coding-standards": "^0.8.0" }, "config": { "vendor-dir": ".Build/vendor", @@ -53,8 +55,8 @@ }, "scripts": { "post-autoload-dump": [ - "mkdir -p .Build/Web/typo3conf/ext/", - "[ -L .Build/Web/typo3conf/ext/find ] || ln -snvf ../../../../. .Build/Web/typo3conf/ext/find" + "mkdir -p .Build/public/typo3conf/ext/", + "[ -L .Build/public/typo3conf/ext/find ] || ln -snvf ../../../../. .Build/public/typo3conf/ext/find" ], "rector-lint": "rector process --dry-run", "rector-fix": "rector process", @@ -75,7 +77,7 @@ "extra": { "typo3/cms": { "cms-package-dir": "{$vendor-dir}/typo3/cms", - "web-dir": ".Build/Web", + "web-dir": ".Build/public", "extension-key": "find" } } diff --git a/ext_emconf.php b/ext_emconf.php index efb3a981..0432fa8c 100755 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -11,9 +11,9 @@ 'author_company' => 'SUB Göttingen', 'constraints' => [ 'depends' => [ - 'php' => '8.0.0-8.1.99', - 'typo3' => '11.5.0-11.5.99', - 'felogin' => '11.5.0-11.5.99', + 'php' => '8.2.0-8.3.99', + 'typo3' => '12.4.0-12.4.99', + 'felogin' => '12.4.0-12.4.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/rector.php b/rector.php index e4019e95..7690473e 100644 --- a/rector.php +++ b/rector.php @@ -3,32 +3,24 @@ declare(strict_types=1); use Rector\Config\RectorConfig; use Rector\Set\ValueObject\SetList; -use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\v10\v0\ExtbasePersistenceTypoScriptRector; use Ssch\TYPO3Rector\Set\Typo3LevelSetList; -use Ssch\TYPO3Rector\Set\Typo3SetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ - __DIR__.'/Classes', - __DIR__.'/Tests', - __DIR__.'/Configuration', - __DIR__.'/Resources', - __DIR__.'/*.php', +return RectorConfig::configure() + ->withPhpSets() + ->withPreparedSets(codeQuality: true, codingStyle: true) + ->withSkip([ + __DIR__ . '/.Build/vendor', + __DIR__ . '/var', + __DIR__ . '/*.cache', + ]) + ->withPaths([ + __DIR__ . '/Classes', + __DIR__ . '/Tests', + __DIR__ . '/Configuration', + __DIR__ . '/Resources', + __DIR__ . '/*.php', + ]) + ->withSets([ + SetList::PHP_82, + Typo3LevelSetList::UP_TO_TYPO3_12, ]); - - $rectorConfig->skip([ - __DIR__.'/.Build/vendor', - __DIR__.'/var', - __DIR__.'/*.cache', - ExtbasePersistenceTypoScriptRector::class, - ]); - - // Define what rule sets will be applied - $rectorConfig->sets([ - SetList::CODING_STYLE, - SetList::CODE_QUALITY, - SetList::PHP_80, - Typo3LevelSetList::UP_TO_TYPO3_11, - Typo3SetList::TYPOSCRIPT_CONDITIONS_104, - ]); -};