Skip to content

Commit

Permalink
[TASK] Bump typo3/coding-standards & align code-style (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
twoldanski authored Sep 23, 2024
1 parent 73c0eb9 commit 9dfec77
Show file tree
Hide file tree
Showing 25 changed files with 91 additions and 40 deletions.
7 changes: 6 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->getFinder()->in('Classes')->in('Configuration')->in('Tests');
$rules = $config->getRules();
$rules['global_namespace_import'] = [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true
];
$rules['ordered_imports'] = [
'imports_order' => [
'class',
Expand All @@ -26,4 +31,4 @@
];

$config->setRules($rules);
return $config;
return $config;
6 changes: 4 additions & 2 deletions Classes/DataProcessing/DatabaseQueryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;

use function json_decode;

/**
* Fetch records from the database, using the default .select syntax from TypoScript.
*
Expand Down Expand Up @@ -109,13 +111,13 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
$objConf = $this->typoScriptService->convertPlainArrayToTypoScriptArray(['fields' => $fields, '_typoScriptNodeValue' => 'JSON']);
}

$processedRecordVariables[$key] = $objConf !== [] ? \json_decode($recordContentObjectRenderer->cObjGetSingle($objName, $objConf), true) : $record;
$processedRecordVariables[$key] = $objConf !== [] ? json_decode($recordContentObjectRenderer->cObjGetSingle($objName, $objConf), true) : $record;
$processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $processedRecordVariables[$key]);

if (isset($processorConfiguration['overrideFields.'])) {
$overrideFields = $this->typoScriptService->convertTypoScriptArrayToPlainArray($processorConfiguration['overrideFields.']);
$jsonCE = $this->typoScriptService->convertPlainArrayToTypoScriptArray(['fields' => $overrideFields, '_typoScriptNodeValue' => 'JSON']);
$record = \json_decode($recordContentObjectRenderer->cObjGetSingle('JSON', $jsonCE), true);
$record = json_decode($recordContentObjectRenderer->cObjGetSingle('JSON', $jsonCE), true);

foreach ($record as $fieldName => $overrideData) {
$processedRecordVariables[$key][$fieldName] = $overrideData;
Expand Down
5 changes: 3 additions & 2 deletions Classes/DataProcessing/ExtractPropertyProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\DataProcessing;

use Exception;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
Expand Down Expand Up @@ -49,11 +50,11 @@ public function process(
array $processedData
) {
if (empty($processorConfiguration['as'])) {
throw new \Exception('Please specify property \'as\'');
throw new Exception('Please specify property \'as\'');
}

if (empty($processorConfiguration['key'])) {
throw new \Exception('Please specify property \'key\'');
throw new Exception('Please specify property \'key\'');
}

$targetFieldName = (string)$cObj->stdWrapValue(
Expand Down
10 changes: 7 additions & 3 deletions Classes/DataProcessing/FlexFormProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;

use function is_array;
use function is_string;
use function json_decode;

/**
* Basic TypoScript configuration:
* Processing the field pi_flexform and overrides the values stored in data
Expand Down Expand Up @@ -106,9 +110,9 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
// processing the flexform data
$originalValue = $processedData['data'][$fieldName] ?? $processedData[$fieldName];

if (\is_array($originalValue)) {
if (is_array($originalValue)) {
$flexformData = $originalValue;
} elseif (\is_string($originalValue)) {
} elseif (is_string($originalValue)) {
$flexformData = $this->flexFormService->convertFlexFormContentToArray($originalValue);
} else {
return $processedData;
Expand Down Expand Up @@ -149,7 +153,7 @@ public function processOverrideFields(array $data, array $flexformData, array $p
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$overrideFields = $typoScriptService->convertTypoScriptArrayToPlainArray($processorConfiguration['overrideFields.']);
$jsonCE = $typoScriptService->convertPlainArrayToTypoScriptArray(['fields' => $overrideFields, '_typoScriptNodeValue' => 'JSON']);
$record = \json_decode($recordContentObjectRenderer->cObjGetSingle('JSON', $jsonCE), true);
$record = json_decode($recordContentObjectRenderer->cObjGetSingle('JSON', $jsonCE), true);

foreach ($record as $fieldName => $overrideData) {
$flexformData[$fieldName] = $overrideData;
Expand Down
6 changes: 4 additions & 2 deletions Classes/DataProcessing/MenuProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

use function is_array;

/**
* This menu processor utilizes HMENU to generate a json encoded menu
* string that will be decoded again and assigned to JSON as
Expand Down Expand Up @@ -143,15 +145,15 @@ public function buildConfiguration()
{
// Before rendering the actual menu via HMENU we want to update $this->menuLevelConfig
$overwriteMenuLevelConfig = $this->getConfigurationValue('overwriteMenuLevelConfig.');
if (\is_array($overwriteMenuLevelConfig)) {
if (is_array($overwriteMenuLevelConfig)) {
ArrayUtility::mergeRecursiveWithOverrule($this->menuLevelConfig, $overwriteMenuLevelConfig);
}

parent::buildConfiguration();

// override built configuration
$overwriteMenuConfig = $this->getConfigurationValue('overwriteMenuConfig.');
if (\is_array($overwriteMenuConfig)) {
if (is_array($overwriteMenuConfig)) {
ArrayUtility::mergeRecursiveWithOverrule($this->menuConfig, $overwriteMenuConfig);
}
}
Expand Down
7 changes: 5 additions & 2 deletions Classes/DataProcessing/RootSiteProcessing/SiteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
namespace FriendsOfTYPO3\Headless\DataProcessing\RootSiteProcessing;

use Doctrine\DBAL\Driver\Exception;
use InvalidArgumentException;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\SiteFinder;

use TYPO3\CMS\Core\Utility\GeneralUtility;

use function array_filter;
use function array_map;
use function array_values;
use function count;
use function in_array;
use function is_a;
use function usort;

class SiteProvider implements SiteProviderInterface
Expand Down Expand Up @@ -84,8 +87,8 @@ public function prepare(array $config, int $siteUid): self
$pages = $this->fetchPageData($sites, $config);

if ($customSorting !== null) {
if (!\is_a($customSorting, SiteSortingInterface::class, true)) {
throw new \InvalidArgumentException('Invalid implementation of SiteSortingInterface');
if (!is_a($customSorting, SiteSortingInterface::class, true)) {
throw new InvalidArgumentException('Invalid implementation of SiteSortingInterface');
}
/**
* @var SiteSortingInterface $sorting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use FriendsOfTYPO3\Headless\Seo\MetaHandler;
use FriendsOfTYPO3\Headless\Utility\HeadlessMode;
use FriendsOfTYPO3\Headless\Utility\HeadlessUserInt;
use Throwable;
use TYPO3\CMS\Core\Utility\GeneralUtility;

use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;

use function json_decode;
Expand Down Expand Up @@ -51,7 +53,7 @@ public function __invoke(AfterCacheableContentIsGeneratedEvent $event)
$content = $this->metaHandler->process($event->getRequest(), $event->getController(), $content);

$event->getController()->content = $this->encoder->encode($content);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\Event\Listener;

use Exception;
use FriendsOfTYPO3\Headless\Event\RedirectUrlEvent;
use FriendsOfTYPO3\Headless\Utility\HeadlessFrontendUrlInterface;
use Psr\Log\LoggerAwareInterface;
Expand All @@ -22,6 +23,7 @@
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Routing\PageRouter;
use TYPO3\CMS\Core\Site\Entity\Site;

use TYPO3\CMS\Core\Utility\GeneralUtility;

use function parse_str;
Expand Down Expand Up @@ -82,7 +84,7 @@ public function __invoke(RedirectUrlEvent $event): void
);

$event->setTargetUrl($frontendUrl);
} catch (\Exception $exception) {
} catch (Exception $exception) {
$this->logError(
'Error during action redirect',
['record' => $event->getRedirectRecord(), 'uri' => $url]
Expand Down
3 changes: 2 additions & 1 deletion Classes/Seo/MetaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\Seo;

use InvalidArgumentException;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
Expand Down Expand Up @@ -121,7 +122,7 @@ private function setMetaTag(string $type, string $name, string $content, array $
$type = strtolower($type);
$name = strtolower($name);
if (!in_array($type, ['property', 'name', 'http-equiv'], true)) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
'When setting a meta tag the only types allowed are property, name or http-equiv. "' . $type . '" given.',
1496402460
);
Expand Down
6 changes: 5 additions & 1 deletion Classes/Utility/FileUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use FriendsOfTYPO3\Headless\Event\EnrichFileDataEvent;
use FriendsOfTYPO3\Headless\Event\FileDataAfterCropVariantProcessingEvent;
use FriendsOfTYPO3\Headless\Utility\File\ProcessingConfiguration;
use InvalidArgumentException;
use Psr\EventDispatcher\EventDispatcherInterface;
use RuntimeException;
use Throwable;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Http\NormalizedParams;
Expand All @@ -26,8 +28,10 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ImageService;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Typolink\LinkResultInterface;
use UnexpectedValueException;

use function array_key_exists;
use function array_merge;
Expand Down Expand Up @@ -309,7 +313,7 @@ public function processImageFile(
}

return $this->imageService->applyProcessingInstructions($fileReference, $instructions);
} catch (\UnexpectedValueException|\RuntimeException|\InvalidArgumentException $e) {
} catch (UnexpectedValueException|RuntimeException|InvalidArgumentException $e) {
$type = lcfirst(get_class($fileReference));
$status = get_class($e);
$this->errors['processImageFile'][$type . '-' . $fileReference->getUid()] = $status;
Expand Down
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/DomainViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\ViewHelpers;

use Closure;
use FriendsOfTYPO3\Headless\Utility\UrlUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
Expand All @@ -25,7 +26,7 @@ public function initializeArguments()

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$urlUtility = GeneralUtility::makeInstance(UrlUtility::class);
Expand Down
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/Form/RegisterFieldViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\ViewHelpers\Form;

use Traversable;
use TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;

Expand Down Expand Up @@ -59,7 +60,7 @@ public function render()
$propertyValue = $this->getPropertyValue();
}

if ($propertyValue instanceof \Traversable) {
if ($propertyValue instanceof Traversable) {
$propertyValue = iterator_to_array($propertyValue);
}
if (is_array($propertyValue)) {
Expand Down
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/Format/Json/DecodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace FriendsOfTYPO3\Headless\ViewHelpers\Format\Json;

use Exception;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
Expand Down Expand Up @@ -45,7 +46,7 @@ public function render()
return $object;
}
if ($GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] ?? false) {
throw new \Exception(sprintf(
throw new Exception(sprintf(
'Failure "%s" occured when running json_decode() for string: %s',
json_last_error_msg(),
$json
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/Iterator/ExplodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function resolveGlue(): string
$glue = $this->arguments['glue'];
if (str_contains($glue, ':') && strlen($glue) > 1) {
// glue contains a special type identifier, resolve the actual glue
list($type, $value) = explode(':', $glue);
[$type, $value] = explode(':', $glue);
switch ($type) {
case 'constant':
$glue = constant($value);
Expand Down
11 changes: 7 additions & 4 deletions Classes/ViewHelpers/LoginFormViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@

namespace FriendsOfTYPO3\Headless\ViewHelpers;

use LogicException;
use Psr\Http\Message\RequestInterface;
use RuntimeException;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\SecurityAspect;
use TYPO3\CMS\Core\Security\RequestToken;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject;

use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;

use TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper;

use function base64_encode;

use function is_int;
use function is_object;
use function is_string;
Expand Down Expand Up @@ -84,7 +87,7 @@ public function render(): string
$renderingContext = $this->renderingContext;
$request = $renderingContext->getRequest();
if (!$request instanceof RequestInterface) {
throw new \RuntimeException(
throw new RuntimeException(
'ViewHelper f:form can be used only in extbase context and needs a request implementing extbase RequestInterface.',
1639821904
);
Expand Down Expand Up @@ -271,7 +274,7 @@ protected function renderRequestTokenHiddenField(): string
return '';
}
if (strtolower((string)($this->arguments['method'] ?? '')) === 'get') {
throw new \LogicException('Cannot apply request token for forms sent via HTTP GET', 1651775963);
throw new LogicException('Cannot apply request token for forms sent via HTTP GET', 1651775963);
}

$context = GeneralUtility::makeInstance(Context::class);
Expand All @@ -280,7 +283,7 @@ protected function renderRequestTokenHiddenField(): string
$signingType = $signingType ?: 'nonce';
$signingProvider = $securityAspect->getSigningSecretResolver()->findByType($signingType);
if ($signingProvider === null) {
throw new \LogicException(sprintf('Cannot find request token signing type "%s"', $signingType), 1664260307);
throw new LogicException(sprintf('Cannot find request token signing type "%s"', $signingType), 1664260307);
}

$signingSecret = $signingProvider->provideSigningSecret();
Expand Down
3 changes: 2 additions & 1 deletion Classes/XClass/Preview/PreviewUriBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FriendsOfTYPO3\Headless\Utility\HeadlessMode;
use FriendsOfTYPO3\Headless\Utility\UrlUtility;
use InvalidArgumentException;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Routing\InvalidRouteArgumentsException;
use TYPO3\CMS\Core\Routing\UnableToLinkToPageException;
Expand Down Expand Up @@ -43,7 +44,7 @@ public function buildUriForPage(int $uid, int $languageId = 0): string
$site = $siteFinder->getSiteByPageId($uid);
try {
$language = $site->getLanguageById($languageId);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
$language = $site->getDefaultLanguage();
}

Expand Down
4 changes: 3 additions & 1 deletion Classes/XClass/TemplateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
namespace FriendsOfTYPO3\Headless\XClass;

use FriendsOfTYPO3\Headless\Utility\HeadlessMode;
use Throwable;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

use TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;

use function extract;
Expand Down Expand Up @@ -63,7 +65,7 @@ private function loadTemplate(string $templateFile, RenderingContextInterface $r
ob_start();
include $templateFile;
$__jsonContent = ob_get_clean();
} catch (\Throwable $e) {
} catch (Throwable $e) {
ob_end_clean();
throw $e;
}
Expand Down
Loading

0 comments on commit 9dfec77

Please sign in to comment.