From a7e3f928272e732eaa4730b3bf5d7873c3e3cd67 Mon Sep 17 00:00:00 2001 From: Pierre Gauthier Date: Mon, 22 Jan 2024 12:07:37 +0100 Subject: [PATCH] Fix config standard --- .github/workflows/qa.yml | 1 + src/Api/GraphQlClient.php | 2 +- src/Api/RestClient.php | 2 +- src/Indexer/CategoryIndexer.php | 3 +-- src/Indexer/ProductIndexer.php | 7 +++---- src/Synchronizer/AbstractSynchronizer.php | 9 +++++---- src/Synchronizer/CatalogSynchronizer.php | 4 ++-- src/Synchronizer/LocalizedCatalogSynchronizer.php | 1 + src/Synchronizer/MetadataSynchronizer.php | 4 ++-- src/Synchronizer/SourceFieldOptionSynchronizer.php | 3 +-- src/Synchronizer/SourceFieldSynchronizer.php | 5 ++--- .../Subscriber/ProductAttributeSubscriber.php | 3 +-- 12 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index 3529410..181b007 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -18,6 +18,7 @@ jobs: with: php_version: "8.1" php_extensions: ctype curl dom hash iconv intl gd json mbstring openssl session simplexml xml zip zlib pdo_mysql exif + args: --no-plugins - name: Php cs fixer run: php ./vendor/bin/php-cs-fixer fix --dry-run src - name: Phpstan diff --git a/src/Api/GraphQlClient.php b/src/Api/GraphQlClient.php index 75a6357..ff9bece 100644 --- a/src/Api/GraphQlClient.php +++ b/src/Api/GraphQlClient.php @@ -50,7 +50,7 @@ public function query(string $query, array $variables): ?ResponseInterface $this->logger->info(print_r($result, true)); } } catch (\Exception $e) { - $this->logger->info(\get_class($e) . ': ' . $e->getMessage()); + $this->logger->info($e::class . ': ' . $e->getMessage()); $this->logger->info($e->getTraceAsString()); $this->logger->info('Input was'); $this->logger->info(print_r($query, true)); diff --git a/src/Api/RestClient.php b/src/Api/RestClient.php index af0d7f2..6fa2415 100644 --- a/src/Api/RestClient.php +++ b/src/Api/RestClient.php @@ -40,7 +40,7 @@ public function query(string $endpoint, string $operation, mixed ...$input): mix $this->logger->info(print_r($result, true)); } } catch (\Exception|ApiException $e) { - $this->logger->info(\get_class($e) . " when calling {$endpoint}->{$operation}: " . $e->getMessage()); + $this->logger->info($e::class . " when calling {$endpoint}->{$operation}: " . $e->getMessage()); $this->logger->info($e->getTraceAsString()); $this->logger->info('Input was'); $this->logger->info(print_r($input, true)); diff --git a/src/Indexer/CategoryIndexer.php b/src/Indexer/CategoryIndexer.php index 81d3307..15adb22 100644 --- a/src/Indexer/CategoryIndexer.php +++ b/src/Indexer/CategoryIndexer.php @@ -23,9 +23,8 @@ use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; /** - * Class CategoryIndexer + * Class CategoryIndexer. * - * @package Gally * @author Stephan Hochdörfer , Gally Team * @copyright 2022-present Smile * @license Open Software License v. 3.0 (OSL-3.0) diff --git a/src/Indexer/ProductIndexer.php b/src/Indexer/ProductIndexer.php index c73b61d..a48e2d2 100644 --- a/src/Indexer/ProductIndexer.php +++ b/src/Indexer/ProductIndexer.php @@ -26,9 +26,8 @@ use Sylius\Component\Resource\Repository\RepositoryInterface; /** - * Class ProductIndexer + * Class ProductIndexer. * - * @package Gally * @author Stephan Hochdörfer , Gally Team * @copyright 2022-present Smile * @license Open Software License v. 3.0 (OSL-3.0) @@ -186,8 +185,8 @@ private function formatPrice(ProductVariantInterface $variant, ChannelInterface $originalPrice = $this->productVariantPriceCalculator->calculateOriginal($variant, $context); // fix price rendering in Gally - $price = $price / 100; - $originalPrice = $originalPrice / 100; + $price /= 100; + $originalPrice /= 100; $prices = []; $prices[] = [ diff --git a/src/Synchronizer/AbstractSynchronizer.php b/src/Synchronizer/AbstractSynchronizer.php index 6732841..eb44aeb 100644 --- a/src/Synchronizer/AbstractSynchronizer.php +++ b/src/Synchronizer/AbstractSynchronizer.php @@ -132,7 +132,7 @@ protected function createOrUpdateEntity(ModelInterface $entity): ModelInterface protected function getEntityFromApi(ModelInterface|string $entity): ?ModelInterface { if ($this->allEntityHasBeenFetch) { - return $this->entityByCode[is_string($entity) ? $entity : $this->getIdentity($entity)] ?? null; + return $this->entityByCode[\is_string($entity) ? $entity : $this->getIdentity($entity)] ?? null; } return $this->fetchEntity($entity); @@ -146,18 +146,18 @@ protected function addEntityByIdentity(ModelInterface $entity): void protected function validateEntity(ModelInterface $entity): void { if (!$entity->valid()) { - throw new \LogicException('Missing properties for ' . \get_class($entity) . ' : ' . implode(',', $entity->listInvalidProperties())); + throw new \LogicException('Missing properties for ' . $entity::class . ' : ' . implode(',', $entity->listInvalidProperties())); } } protected function addEntityToBulk(ModelInterface $entity): void { - if ($this->bulkEntityMethod === null) { + if (null === $this->bulkEntityMethod) { throw new \Exception(sprintf('The entity %s doesn\'t have a bulk method.', $this->getEntityClass())); } $this->currentBatch[] = $entity; - $this->currentBatchSize++; + ++$this->currentBatchSize; if ($this->currentBatchSize >= self::BATCH_SIZE) { $this->runBulk(); } @@ -178,6 +178,7 @@ protected function runBulk(): void protected function getAllEntityCodes(): array { $this->fetchEntities(); + return array_keys($this->entityByCode); } diff --git a/src/Synchronizer/CatalogSynchronizer.php b/src/Synchronizer/CatalogSynchronizer.php index 4d33b5c..85fb6fc 100644 --- a/src/Synchronizer/CatalogSynchronizer.php +++ b/src/Synchronizer/CatalogSynchronizer.php @@ -57,7 +57,7 @@ public function __construct( public function getIdentity(ModelInterface $entity): string { /** @var Catalog $entity */ - return "catalog" . $entity->getCode(); + return 'catalog' . $entity->getCode(); } public function synchronizeAll(): void @@ -78,7 +78,7 @@ public function synchronizeAll(): void foreach (array_flip($this->localizedCatalogCodes) as $localizedCatalogCode) { /** @var LocalizedCatalogCatalogRead $localizedCatalog */ $localizedCatalog = $this->localizedCatalogSynchronizer->getEntityFromApi($localizedCatalogCode); - $this->localizedCatalogSynchronizer->deleteEntity($localizedCatalog->getId() ); + $this->localizedCatalogSynchronizer->deleteEntity($localizedCatalog->getId()); } foreach (array_flip($this->catalogCodes) as $catalogCode) { diff --git a/src/Synchronizer/LocalizedCatalogSynchronizer.php b/src/Synchronizer/LocalizedCatalogSynchronizer.php index afaf7b6..ecf9189 100644 --- a/src/Synchronizer/LocalizedCatalogSynchronizer.php +++ b/src/Synchronizer/LocalizedCatalogSynchronizer.php @@ -84,6 +84,7 @@ public function getLocalizedCatalogByLocale(string $localeCode): array public function getByIdentity(string $identifier): ?ModelInterface { $this->fetchEntities(); + return $this->entityByCode[$identifier] ?? null; } } diff --git a/src/Synchronizer/MetadataSynchronizer.php b/src/Synchronizer/MetadataSynchronizer.php index 9f6dd17..03d65db 100644 --- a/src/Synchronizer/MetadataSynchronizer.php +++ b/src/Synchronizer/MetadataSynchronizer.php @@ -14,7 +14,6 @@ namespace Gally\SyliusPlugin\Synchronizer; -use Gally\Rest\Model\Metadata; use Gally\Rest\Model\MetadataMetadataRead; use Gally\Rest\Model\MetadataMetadataWrite; use Gally\Rest\Model\ModelInterface; @@ -28,12 +27,13 @@ public function synchronizeAll(): void public function synchronizeItem(array $params): ?ModelInterface { $this->fetchEntities(); + return $this->createOrUpdateEntity(new MetadataMetadataWrite(['entity' => $params['entity']])); } public function getIdentity(ModelInterface $entity): string { - /** @var MetadataMetadataRead $entity */ + /** @var MetadataMetadataRead $entity */ return $entity->getEntity(); } } diff --git a/src/Synchronizer/SourceFieldOptionSynchronizer.php b/src/Synchronizer/SourceFieldOptionSynchronizer.php index 05e3d2a..7f52f79 100644 --- a/src/Synchronizer/SourceFieldOptionSynchronizer.php +++ b/src/Synchronizer/SourceFieldOptionSynchronizer.php @@ -23,7 +23,6 @@ use Gally\Rest\Model\SourceFieldSourceFieldRead; use Gally\SyliusPlugin\Api\RestClient; use Gally\SyliusPlugin\Repository\GallyConfigurationRepository; -use ReflectionClass; use Sylius\Component\Product\Model\Product; use Sylius\Component\Product\Model\ProductAttribute; use Sylius\Component\Product\Model\ProductOption; @@ -76,7 +75,7 @@ public function synchronizeAll(): void $this->sourceFieldOptionCodes = array_flip($this->getAllEntityCodes()); $this->sourceFieldSynchronizer->fetchEntities(); - $metadataName = strtolower((new ReflectionClass(Product::class))->getShortName()); + $metadataName = strtolower((new \ReflectionClass(Product::class))->getShortName()); /** @var MetadataMetadataRead $metadata */ $metadata = $this->metadataSynchronizer->synchronizeItem(['entity' => $metadataName]); diff --git a/src/Synchronizer/SourceFieldSynchronizer.php b/src/Synchronizer/SourceFieldSynchronizer.php index 7df7add..e02a332 100644 --- a/src/Synchronizer/SourceFieldSynchronizer.php +++ b/src/Synchronizer/SourceFieldSynchronizer.php @@ -16,14 +16,12 @@ use Doctrine\Common\Collections\Collection; use Gally\Rest\Model\LocalizedCatalog; -use Gally\Rest\Model\Metadata; use Gally\Rest\Model\MetadataMetadataRead; use Gally\Rest\Model\ModelInterface; use Gally\Rest\Model\SourceFieldSourceFieldRead; use Gally\Rest\Model\SourceFieldSourceFieldWrite; use Gally\SyliusPlugin\Api\RestClient; use Gally\SyliusPlugin\Repository\GallyConfigurationRepository; -use ReflectionClass; use Sylius\Component\Product\Model\Product; use Sylius\Component\Product\Model\ProductAttribute; use Sylius\Component\Product\Model\ProductOption; @@ -74,7 +72,7 @@ public function synchronizeAll(): void { $this->sourceFieldCodes = array_flip($this->getAllEntityCodes()); - $metadataName = strtolower((new ReflectionClass(Product::class))->getShortName()); + $metadataName = strtolower((new \ReflectionClass(Product::class))->getShortName()); $metadata = $this->metadataSynchronizer->synchronizeItem(['entity' => $metadataName]); /** @var ProductAttribute[] $attributes */ @@ -224,6 +222,7 @@ public static function getGallyType(string $type): string public function getEntityByCode(MetadataMetadataRead $metadata, string $code): ?ModelInterface { $key = '/metadata/' . $metadata->getId() . $code; + return $this->entityByCode[$key] ?? null; } diff --git a/src/Synchronizer/Subscriber/ProductAttributeSubscriber.php b/src/Synchronizer/Subscriber/ProductAttributeSubscriber.php index 6c144ab..c90fb83 100644 --- a/src/Synchronizer/Subscriber/ProductAttributeSubscriber.php +++ b/src/Synchronizer/Subscriber/ProductAttributeSubscriber.php @@ -16,7 +16,6 @@ use Gally\SyliusPlugin\Synchronizer\MetadataSynchronizer; use Gally\SyliusPlugin\Synchronizer\SourceFieldSynchronizer; -use ReflectionClass; use Sylius\Component\Product\Model\Product; use Sylius\Component\Product\Model\ProductAttributeInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -42,7 +41,7 @@ public function onProductUpdate(GenericEvent $event): void { $attribute = $event->getSubject(); if ($attribute instanceof ProductAttributeInterface) { - $metadataName = strtolower((new ReflectionClass(Product::class))->getShortName()); + $metadataName = strtolower((new \ReflectionClass(Product::class))->getShortName()); $metadata = $this->metadataSynchronizer->synchronizeItem(['entity' => $metadataName]); $options = [];