Skip to content

Commit

Permalink
Fix config standard
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreGauthier committed Jan 22, 2024
1 parent 2fd51a7 commit a7e3f92
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Api/GraphQlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/Api/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions src/Indexer/CategoryIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;

/**
* Class CategoryIndexer
* Class CategoryIndexer.
*
* @package Gally
* @author Stephan Hochdörfer <[email protected]>, Gally Team <[email protected]>
* @copyright 2022-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
Expand Down
7 changes: 3 additions & 4 deletions src/Indexer/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
use Sylius\Component\Resource\Repository\RepositoryInterface;

/**
* Class ProductIndexer
* Class ProductIndexer.
*
* @package Gally
* @author Stephan Hochdörfer <[email protected]>, Gally Team <[email protected]>
* @copyright 2022-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
Expand Down Expand Up @@ -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[] = [
Expand Down
9 changes: 5 additions & 4 deletions src/Synchronizer/AbstractSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
Expand All @@ -178,6 +178,7 @@ protected function runBulk(): void
protected function getAllEntityCodes(): array
{
$this->fetchEntities();

return array_keys($this->entityByCode);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Synchronizer/CatalogSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/Synchronizer/LocalizedCatalogSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function getLocalizedCatalogByLocale(string $localeCode): array
public function getByIdentity(string $identifier): ?ModelInterface
{
$this->fetchEntities();

return $this->entityByCode[$identifier] ?? null;
}
}
4 changes: 2 additions & 2 deletions src/Synchronizer/MetadataSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
3 changes: 1 addition & 2 deletions src/Synchronizer/SourceFieldOptionSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);

Expand Down
5 changes: 2 additions & 3 deletions src/Synchronizer/SourceFieldSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Synchronizer/Subscriber/ProductAttributeSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = [];
Expand Down

0 comments on commit a7e3f92

Please sign in to comment.