From e167d2d71aa388ae17a280bf69fd406b5c5ee8ec Mon Sep 17 00:00:00 2001 From: DACHCOM Bot Date: Thu, 5 Dec 2024 10:26:54 +0000 Subject: [PATCH] [CS] Refactor --- src/Command/QueuedIndexDataCommand.php | 11 ++++++++ src/Controller/Admin/MetaDataController.php | 13 +++++++++- .../Compiler/IndexWorkerPass.php | 11 ++++++++ .../Compiler/MetaDataExtractorPass.php | 11 ++++++++ .../Compiler/MetaDataIntegratorPass.php | 11 ++++++++ .../Compiler/MetaMiddlewareAdapterPass.php | 11 ++++++++ .../Compiler/ResourceProcessorPass.php | 11 ++++++++ .../RemoveCoreShopExtractorListenerPass.php | 11 ++++++++ .../RemoveNewsMetaDataListenerPass.php | 11 ++++++++ src/DependencyInjection/Configuration.php | 11 ++++++++ src/DependencyInjection/SeoExtension.php | 17 ++++++++++--- src/EventListener/Admin/AssetListener.php | 11 ++++++++ .../Admin/SeoDocumentEditorListener.php | 13 ++++++++-- src/EventListener/Admin/XliffListener.php | 12 ++++++++- .../AutoMetaDataAttachListener.php | 15 +++++++++-- src/EventListener/ElementMetaDataListener.php | 15 +++++++++-- .../Maintenance/QueuedIndexDataTask.php | 11 ++++++++ src/EventListener/PimcoreElementListener.php | 11 ++++++++ .../WorkerResponseInterceptException.php | 11 ++++++++ src/Helper/ArrayHelper.php | 23 ++++++++++------- src/Logger/Logger.php | 11 ++++++++ src/Logger/LoggerInterface.php | 11 ++++++++ src/Manager/ElementMetaDataManager.php | 20 ++++++++------- .../ElementMetaDataManagerInterface.php | 11 ++++++++ src/Manager/QueueManager.php | 13 +++++++++- src/Manager/QueueManagerInterface.php | 11 ++++++++ src/MetaData/Extractor/ExtractorInterface.php | 11 ++++++++ .../Extractor/IntegratorExtractor.php | 11 ++++++++ .../ThirdParty/CoreShop/OGExtractor.php | 13 +++++++++- .../CoreShop/TitleDescriptionExtractor.php | 11 ++++++++ .../ThirdParty/News/EntryMetaExtractor.php | 13 +++++++++- .../Integrator/AbstractIntegrator.php | 12 ++++++++- src/MetaData/Integrator/HtmlTagIntegrator.php | 11 ++++++++ .../Integrator/IntegratorInterface.php | 11 ++++++++ .../Integrator/OpenGraphIntegrator.php | 14 ++++++++--- src/MetaData/Integrator/SchemaIntegrator.php | 14 +++++++++-- .../Integrator/TitleDescriptionIntegrator.php | 13 +++++++++- .../Integrator/TwitterCardIntegrator.php | 13 ++++++++-- .../XliffAwareIntegratorInterface.php | 11 ++++++++ src/MetaData/MetaDataProvider.php | 13 +++++++++- src/MetaData/MetaDataProviderInterface.php | 11 ++++++++ src/Middleware/Middleware.php | 11 ++++++++ src/Middleware/MiddlewareAdapterInterface.php | 11 ++++++++ src/Middleware/MiddlewareDispatcher.php | 11 ++++++++ .../MiddlewareDispatcherInterface.php | 11 ++++++++ src/Middleware/MiddlewareInterface.php | 11 ++++++++ src/Migrations/Version20230809105540.php | 11 ++++++++ src/Migrations/Version20240809095425.php | 11 ++++++++ src/Migrations/Version20240827080929.php | 11 ++++++++ src/Model/ElementMetaData.php | 11 ++++++++ src/Model/ElementMetaDataInterface.php | 11 ++++++++ src/Model/QueueEntry.php | 11 ++++++++ src/Model/QueueEntryInterface.php | 11 ++++++++ src/Model/SeoMetaData.php | 12 ++++++++- src/Model/SeoMetaDataInterface.php | 13 ++++++++++ src/Queue/QueueDataProcessor.php | 15 +++++++++-- src/Queue/QueueDataProcessorInterface.php | 11 ++++++++ src/Registry/IndexWorkerRegistry.php | 11 ++++++++ src/Registry/IndexWorkerRegistryInterface.php | 11 ++++++++ src/Registry/MetaDataExtractorRegistry.php | 11 ++++++++ .../MetaDataExtractorRegistryInterface.php | 13 +++++++++- src/Registry/MetaDataIntegratorRegistry.php | 11 ++++++++ .../MetaDataIntegratorRegistryInterface.php | 11 ++++++++ src/Registry/ResourceProcessorRegistry.php | 11 ++++++++ .../ResourceProcessorRegistryInterface.php | 11 ++++++++ src/Repository/ElementMetaDataRepository.php | 11 ++++++++ .../ElementMetaDataRepositoryInterface.php | 11 ++++++++ src/Repository/QueueEntryRepository.php | 11 ++++++++ .../QueueEntryRepositoryInterface.php | 11 ++++++++ .../ResourceProcessorInterface.php | 11 ++++++++ src/SeoBundle.php | 25 +++++++++++++------ src/Tool/Install.php | 13 +++++++++- src/Tool/LocaleProvider.php | 14 +++++++++-- src/Tool/LocaleProviderInterface.php | 12 ++++++++- src/Tool/UrlGenerator.php | 11 ++++++++ src/Tool/UrlGeneratorInterface.php | 11 ++++++++ src/Twig/Extension/SeoExtension.php | 11 ++++++++ src/Worker/GoogleIndexWorker.php | 17 ++++++++++--- src/Worker/IndexWorkerInterface.php | 12 ++++++++- src/Worker/WorkerResponse.php | 11 ++++++++ src/Worker/WorkerResponseInterface.php | 11 ++++++++ 81 files changed, 924 insertions(+), 62 deletions(-) diff --git a/src/Command/QueuedIndexDataCommand.php b/src/Command/QueuedIndexDataCommand.php index ca92bed..b0b9f70 100644 --- a/src/Command/QueuedIndexDataCommand.php +++ b/src/Command/QueuedIndexDataCommand.php @@ -1,5 +1,16 @@ hasExtension('core_shop_seo'); foreach ($configs as $config) { - $thirdPartyConfig = $config['meta_data_configuration']['meta_data_provider']['third_party'] ?? null; if ($thirdPartyConfig === null) { @@ -81,7 +91,6 @@ public function prepend(ContainerBuilder $container): void } $container->setParameter('seo.third_party.enabled', array_keys($enabledThirdPartyConfigs)); - } private function validateConfiguration(array $config): void diff --git a/src/EventListener/Admin/AssetListener.php b/src/EventListener/Admin/AssetListener.php index 4dda5ca..b05c5d1 100644 --- a/src/EventListener/Admin/AssetListener.php +++ b/src/EventListener/Admin/AssetListener.php @@ -1,5 +1,16 @@ getArgument('list'); foreach ($list['data'] as $listIndex => $item) { - if ($item['type'] !== 'page') { continue; } @@ -98,6 +108,5 @@ public function updateData(DocumentEvent $event): void 'title_description', $integratorData ); - } } diff --git a/src/EventListener/Admin/XliffListener.php b/src/EventListener/Admin/XliffListener.php index 168a766..a3972a1 100644 --- a/src/EventListener/Admin/XliffListener.php +++ b/src/EventListener/Admin/XliffListener.php @@ -1,5 +1,16 @@ getAttributes() as $attribute) { - if ($attribute->getType() !== self::XLIFF_TYPE) { continue; } diff --git a/src/EventListener/AutoMetaDataAttachListener.php b/src/EventListener/AutoMetaDataAttachListener.php index a817c88..7dc9deb 100644 --- a/src/EventListener/AutoMetaDataAttachListener.php +++ b/src/EventListener/AutoMetaDataAttachListener.php @@ -1,15 +1,26 @@ cleanEmptyLocaleRows($data, $dataIdentifier); // nothing to merge @@ -56,12 +65,12 @@ public function mergeLocaleAwareArrays( } foreach ($cleanedRows as $row) { - $previousRowIndex = array_search($row[$rowIdentifier], array_column($previousData, $rowIdentifier), true); if ($previousRowIndex === false) { $newData[$newDataIndex] = $row; $newDataIndex++; + continue; } @@ -74,6 +83,7 @@ public function mergeLocaleAwareArrays( if (!is_array($currentValue) || $this->isAssocArray($currentValue)) { $newData[$dataIndex] = $row; $newDataIndex++; + continue; } @@ -112,24 +122,20 @@ public function rebuildLocaleValueRow(array $values, array $rebuildRow, bool $me $cleanedRebuildRow = array_values($cleanedRebuildRow); foreach ($values as $currentRow) { - $locale = $currentRow['locale']; $value = $currentRow['value']; $index = array_search($locale, array_column($cleanedRebuildRow, 'locale'), true); if ($index !== false) { - if ($value === null) { unset($cleanedRebuildRow[$index]); } else { $cleanedRebuildRow[$index] = $currentRow; } - } elseif ($value !== null) { $cleanedRebuildRow[] = $currentRow; } - } return array_values($cleanedRebuildRow); @@ -139,7 +145,6 @@ public function cleanEmptyLocaleRows(array $field, string $dataIdentifier = 'val { $cleanData = []; foreach ($field as $row) { - if ($row[$dataIdentifier] === null) { continue; } diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index 062b952..ba2f9b5 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -1,5 +1,16 @@ getElementData($elementType, $elementId, true); foreach ($data as $element) { - if ($element->getReleaseType() === ElementMetaDataInterface::RELEASE_TYPE_DRAFT) { $isDraft = true; } @@ -87,7 +97,6 @@ public function getElementDataForXliffExport(string $elementType, int $elementId $data = $this->getElementData($elementType, $elementId); foreach ($data as $element) { - $metaDataIntegrator = $this->metaDataIntegratorRegistry->get($element->getIntegrator()); if (!$metaDataIntegrator instanceof XliffAwareIntegratorInterface) { continue; @@ -109,7 +118,6 @@ public function saveElementDataFromXliffImport(string $elementType, int $element $integratorValues = []; foreach ($rawData as $integrator => $integratorRawData) { - if (!is_array($integratorRawData)) { continue; } @@ -136,7 +144,6 @@ public function saveElementData( bool $merge = false, string $releaseType = ElementMetaDataInterface::RELEASE_TYPE_PUBLIC ): void { - $elementMetaData = $this->determinateElementMetaEntity($elementType, $elementId, $integratorName, $releaseType); if (!$elementMetaData instanceof ElementMetaDataInterface) { @@ -152,9 +159,7 @@ public function saveElementData( // remove empty meta data if ($sanitizedData === null) { - if ($releaseType === ElementMetaDataInterface::RELEASE_TYPE_DRAFT) { - // if draft, we still persist an empty element // to determinate reset when publish state is incoming @@ -318,11 +323,9 @@ private function determinateElementMetaEntity( string $integratorName, string $releaseType = ElementMetaDataInterface::RELEASE_TYPE_PUBLIC ): ?ElementMetaDataInterface { - $hasDraft = $this->elementMetaDataExistsWithReleaseType($elementType, $elementId, ElementMetaDataInterface::RELEASE_TYPE_DRAFT); if ($releaseType === ElementMetaDataInterface::RELEASE_TYPE_PUBLIC && $hasDraft === true) { - // delete draft $this->deleteElementData($elementType, $elementId, ElementMetaDataInterface::RELEASE_TYPE_DRAFT); @@ -355,5 +358,4 @@ private function elementMetaDataExistsWithReleaseType(string $elementType, int $ ->getQuery() ->getSingleScalarResult() > 0; } - } diff --git a/src/Manager/ElementMetaDataManagerInterface.php b/src/Manager/ElementMetaDataManagerInterface.php index 1127c3a..07bbf88 100644 --- a/src/Manager/ElementMetaDataManagerInterface.php +++ b/src/Manager/ElementMetaDataManagerInterface.php @@ -1,5 +1,16 @@ getImage())) { $path = $element->getImage()->getThumbnail('coreshop_seo'); - $ogImage = (str_starts_with('http', $path) ? '' : Tool::getHostUrl()).$path; + $ogImage = (str_starts_with('http', $path) ? '' : Tool::getHostUrl()) . $path; $seoMetadata->addExtraProperty('og:image', $ogImage); } } diff --git a/src/MetaData/Extractor/ThirdParty/CoreShop/TitleDescriptionExtractor.php b/src/MetaData/Extractor/ThirdParty/CoreShop/TitleDescriptionExtractor.php index 96c6bbc..b7c7625 100644 --- a/src/MetaData/Extractor/ThirdParty/CoreShop/TitleDescriptionExtractor.php +++ b/src/MetaData/Extractor/ThirdParty/CoreShop/TitleDescriptionExtractor.php @@ -1,5 +1,16 @@ configuration['properties'], 0), true); @@ -143,7 +153,6 @@ public function updateMetaData($element, array $data, ?string $locale, SeoMetaDa $addedItems = 0; foreach ($data as $ogItem) { - if (empty($ogItem['value']) || empty($ogItem['property'])) { continue; } @@ -163,7 +172,6 @@ public function updateMetaData($element, array $data, ?string $locale, SeoMetaDa $addedItems++; $seoMetadata->addExtraProperty($propertyName, $value); - } if ($addedItems > 0 && null !== $elementUrl = $this->urlGenerator->generate($element)) { diff --git a/src/MetaData/Integrator/SchemaIntegrator.php b/src/MetaData/Integrator/SchemaIntegrator.php index 38c9372..adf658b 100644 --- a/src/MetaData/Integrator/SchemaIntegrator.php +++ b/src/MetaData/Integrator/SchemaIntegrator.php @@ -1,5 +1,16 @@ configuration['properties'], 0), true); @@ -133,7 +143,6 @@ public function updateMetaData(mixed $element, array $data, ?string $locale, Seo } foreach ($data as $twitterItem) { - if (empty($twitterItem['value']) || empty($twitterItem['name'])) { continue; } diff --git a/src/MetaData/Integrator/XliffAwareIntegratorInterface.php b/src/MetaData/Integrator/XliffAwareIntegratorInterface.php index 40e6e12..6f0eb99 100644 --- a/src/MetaData/Integrator/XliffAwareIntegratorInterface.php +++ b/src/MetaData/Integrator/XliffAwareIntegratorInterface.php @@ -1,5 +1,16 @@ getCode(); foreach ($response->getErrors() as $error) { - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ $formattedMessages[] = $error['message']; } @@ -182,12 +193,12 @@ protected function buildSuccessResponse(PublishUrlNotificationResponse $response $latestUpdateInfo = $notificationMetaData->getLatestUpdate(); $latestRemoveInfo = $notificationMetaData->getLatestRemove(); - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ if ($latestUpdateInfo instanceof UrlNotification) { $formattedMessageMeta[] = sprintf('Latest Update Info: %s %s', $latestUpdateInfo->getType(), $latestUpdateInfo->getNotifyTime()); } - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ if ($latestRemoveInfo instanceof UrlNotification) { $formattedMessageMeta[] = sprintf('Latest Remove Info: %s %s', $latestRemoveInfo->getType(), $latestRemoveInfo->getNotifyTime()); } diff --git a/src/Worker/IndexWorkerInterface.php b/src/Worker/IndexWorkerInterface.php index a021cf0..e79e6ad 100644 --- a/src/Worker/IndexWorkerInterface.php +++ b/src/Worker/IndexWorkerInterface.php @@ -1,5 +1,16 @@