Skip to content

Commit

Permalink
Add CI definition
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreGauthier committed Jan 11, 2024
1 parent cf21a45 commit 2b303a3
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 12 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
@@ -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 .
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
parameters:
level: max
level: 5
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
paths:
- src
- tests/Behat
Expand All @@ -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\./'
1 change: 1 addition & 0 deletions src/Api/AuthenticationTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion src/Api/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,7 +63,6 @@ private function addResourcesSection(ArrayNodeDefinition $node): void
->scalarNode('form')->defaultValue(GallyConfigurationType::class)->cannotBeEmpty()->end()
->end()
->end()

->end()
->end()
->end()
Expand Down
5 changes: 5 additions & 0 deletions src/Entity/GallyConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/Indexer/CategoryIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down
7 changes: 5 additions & 2 deletions src/Indexer/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [];
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/Model/GallyChannelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

namespace Gally\SyliusPlugin\Model;

interface GallyChannelInterface
use Sylius\Component\Core\Model\ChannelInterface;

interface GallyChannelInterface extends ChannelInterface
{
public function getGallyActive(): bool;

Expand Down
20 changes: 20 additions & 0 deletions src/Search/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 4 additions & 2 deletions src/Synchronizer/SourceFieldSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 = [];
Expand Down

0 comments on commit 2b303a3

Please sign in to comment.