From 2b303a3c9f52bd518574fe23864d164135b33c3b Mon Sep 17 00:00:00 2001 From: Pierre Gauthier Date: Thu, 11 Jan 2024 11:43:26 +0100 Subject: [PATCH] Add CI definition --- .github/workflows/qa.yml | 24 ++++++++++++++++++++ composer.json | 1 + phpstan.neon | 6 ++--- src/Api/AuthenticationTokenProvider.php | 1 + src/Api/RestClient.php | 2 +- src/DependencyInjection/Configuration.php | 2 +- src/Entity/GallyConfiguration.php | 5 ++++ src/Indexer/CategoryIndexer.php | 9 ++++++-- src/Indexer/ProductIndexer.php | 7 ++++-- src/Model/GallyChannelInterface.php | 4 +++- src/Search/Result.php | 20 ++++++++++++++++ src/Synchronizer/SourceFieldSynchronizer.php | 6 +++-- 12 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/qa.yml diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml new file mode 100644 index 0000000..a67aa12 --- /dev/null +++ b/.github/workflows/qa.yml @@ -0,0 +1,24 @@ +name: QA + +on: + push: + branches: + - master + - '[1-9].[0-9]+.x' + - 'feature-[a-z]+' + pull_request: ~ + +jobs: + qa: + name: Code-Quality-Checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: php-actions/composer@v6 + with: + php_version: "8.1" + php_extensions: ctype curl dom hash iconv intl gd json mbstring openssl session simplexml xml zip zlib pdo_mysql + - name: Php cs fixer + run: php ./vendor/bin/php-cs-fixer fix src + - name: Phpstan + run: php ./vendor/bin/phpstan --memory-limit=1G analyse . diff --git a/composer.json b/composer.json index dc683ec..0e70eb2 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "friends-of-behat/suite-settings-extension": "^1.0", "friends-of-behat/symfony-extension": "^2.1", "friends-of-behat/variadic-extension": "^1.3", + "friendsofphp/php-cs-fixer": "*", "phpspec/phpspec": "^7.2", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1.8.1", diff --git a/phpstan.neon b/phpstan.neon index 2235744..a9c707c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,8 @@ parameters: - level: max + level: 5 reportUnmatchedIgnoredErrors: false checkMissingIterableValueType: false + treatPhpDocTypesAsCertain: false paths: - src - tests/Behat @@ -11,8 +12,7 @@ parameters: - 'src/DependencyInjection/Configuration.php' # Test dependencies - - 'tests/Application/app/**.php' - - 'tests/Application/src/**.php' + - 'tests/Application/**/**.php' ignoreErrors: - '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./' diff --git a/src/Api/AuthenticationTokenProvider.php b/src/Api/AuthenticationTokenProvider.php index 495ebd0..2704df0 100644 --- a/src/Api/AuthenticationTokenProvider.php +++ b/src/Api/AuthenticationTokenProvider.php @@ -53,6 +53,7 @@ public function getAuthenticationToken(string $baseUrl, string $user, string $pa } try { + /** @var array $response */ $response = json_decode($responseJson->getBody()->getContents(), true, 512, \JSON_THROW_ON_ERROR); return (string) $response['token']; diff --git a/src/Api/RestClient.php b/src/Api/RestClient.php index 75f4288..af0d7f2 100644 --- a/src/Api/RestClient.php +++ b/src/Api/RestClient.php @@ -20,7 +20,7 @@ final class RestClient extends AbstractClient { - public function query(string $endpoint, string $operation, ...$input): mixed + public function query(string $endpoint, string $operation, mixed ...$input): mixed { $config = Configuration::getDefaultConfiguration() ->setApiKey('Authorization', $this->getAuthorizationToken()) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 6d0582c..4ae726e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -30,6 +30,7 @@ final class Configuration implements ConfigurationInterface public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('gally_sylius'); + /** @var ArrayNodeDefinition $rootNode */ $rootNode = $treeBuilder->getRootNode(); $rootNode @@ -62,7 +63,6 @@ private function addResourcesSection(ArrayNodeDefinition $node): void ->scalarNode('form')->defaultValue(GallyConfigurationType::class)->cannotBeEmpty()->end() ->end() ->end() - ->end() ->end() ->end() diff --git a/src/Entity/GallyConfiguration.php b/src/Entity/GallyConfiguration.php index e3b88a2..eda467f 100644 --- a/src/Entity/GallyConfiguration.php +++ b/src/Entity/GallyConfiguration.php @@ -28,6 +28,11 @@ public function getId(): ?int return $this->id; } + public function setId(int $id = null): void + { + $this->id = $id; + } + public function getBaseUrl(): string { return $this->baseUrl; diff --git a/src/Indexer/CategoryIndexer.php b/src/Indexer/CategoryIndexer.php index c09d1bd..3557cee 100644 --- a/src/Indexer/CategoryIndexer.php +++ b/src/Indexer/CategoryIndexer.php @@ -15,6 +15,8 @@ namespace Gally\SyliusPlugin\Indexer; use Gally\SyliusPlugin\Service\IndexOperation; +use Sylius\Bundle\ResourceBundle\Doctrine\ORM\ResourceRepositoryTrait; +use Sylius\Bundle\TaxonomyBundle\Doctrine\ORM\TaxonRepository; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\TaxonInterface; use Sylius\Component\Locale\Model\LocaleInterface; @@ -24,14 +26,16 @@ class CategoryIndexer extends AbstractIndexer { + private TaxonRepositoryInterface $taxonRepository; private $pathCache = []; public function __construct( RepositoryInterface $channelRepository, IndexOperation $indexOperation, - private TaxonRepositoryInterface $taxonRepository + TaxonRepositoryInterface $taxonRepository ) { parent::__construct($channelRepository, $indexOperation); + $this->taxonRepository = $taxonRepository; } public function getEntityType(): string @@ -63,7 +67,8 @@ public function getDocumentsToIndex( } } else { $menuTaxon = $channel->getMenuTaxon(); - $taxons = $this->taxonRepository->createQueryBuilder('o') + + $taxons = $this->taxonRepository->createQueryBuilder('o') /* @phpstan-ignore-line */ ->where('o.root = :taxon_id') ->andWhere('o.left >= :taxon_left') ->orderBy('o.left', 'ASC') diff --git a/src/Indexer/ProductIndexer.php b/src/Indexer/ProductIndexer.php index f887db4..a145de3 100644 --- a/src/Indexer/ProductIndexer.php +++ b/src/Indexer/ProductIndexer.php @@ -123,7 +123,8 @@ private function formatProduct(ProductInterface $product, ChannelInterface $chan while ($variants->current()) { if ($variants->current()->isEnabled()) { /** @var ProductVariantInterface $variant */ - $variantData = $this->formatVariant($variants->current(), $channel, $locale); + $variant = $variants->current(); + $variantData = $this->formatVariant($variant, $channel, $locale); foreach ($variantData as $field => $value) { if (!isset($data[$field])) { $data[$field] = []; @@ -146,10 +147,12 @@ private function formatProduct(ProductInterface $product, ChannelInterface $chan private function formatVariant(ProductVariantInterface $variant, ChannelInterface $channel, LocaleInterface $locale): array { + /** @var ProductInterface $parent */ + $parent = $variant->getProduct(); $data = [ 'children.sku' => [$variant->getCode()], 'children.name' => [$variant->getTranslation($locale->getCode())->getName()], - 'childen.image' => [$this->formatMedia($variant->getProduct()) ?: null], + 'childen.image' => [$parent ? $this->formatMedia($parent) : null], ]; foreach ($variant->getOptionValues() as $optionValue) { diff --git a/src/Model/GallyChannelInterface.php b/src/Model/GallyChannelInterface.php index d34ad43..ffcdd4f 100644 --- a/src/Model/GallyChannelInterface.php +++ b/src/Model/GallyChannelInterface.php @@ -14,7 +14,9 @@ namespace Gally\SyliusPlugin\Model; -interface GallyChannelInterface +use Sylius\Component\Core\Model\ChannelInterface; + +interface GallyChannelInterface extends ChannelInterface { public function getGallyActive(): bool; diff --git a/src/Search/Result.php b/src/Search/Result.php index 35bce83..58a0287 100644 --- a/src/Search/Result.php +++ b/src/Search/Result.php @@ -52,4 +52,24 @@ public function getAggregations(): array { return $this->aggregations; } + + public function getCurrentPage(): int + { + return $this->currentPage; + } + + public function getItemPerPage(): int + { + return $this->itemPerPage; + } + + public function getSortField(): string + { + return $this->sortField; + } + + public function getSortDirection(): string + { + return $this->sortDirection; + } } diff --git a/src/Synchronizer/SourceFieldSynchronizer.php b/src/Synchronizer/SourceFieldSynchronizer.php index 87e2871..92ae8c4 100644 --- a/src/Synchronizer/SourceFieldSynchronizer.php +++ b/src/Synchronizer/SourceFieldSynchronizer.php @@ -176,6 +176,7 @@ public function synchronizeItem(array $params): ?ModelInterface ]; foreach ($translations as $translation) { + /** @var SourceFieldSourceFieldRead $tempSourceField */ $tempSourceField = $this->getEntityFromApi(new SourceFieldSourceFieldWrite($data)); $locale = $translation->getLocale(); @@ -205,8 +206,9 @@ public function synchronizeItem(array $params): ?ModelInterface } } + /** @var SourceFieldSourceFieldRead $sourceField */ $sourceField = $this->createOrUpdateEntity(new SourceFieldSourceFieldWrite($data)); - $this->addOptions($sourceField, $options ?? []); + $this->addOptions($sourceField, $options); return $sourceField; } @@ -240,7 +242,7 @@ public static function getGallyType(string $type): string } } - protected function addOptions(ModelInterface $sourceField, iterable $options) + protected function addOptions(SourceFieldSourceFieldRead $sourceField, iterable $options) { $currentBulkSize = 0; $currentBulk = [];