Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jul 1, 2024
1 parent c2311ab commit 470cf36
Show file tree
Hide file tree
Showing 33 changed files with 91 additions and 89 deletions.
18 changes: 9 additions & 9 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php');
$containerConfigurator->parameters()->set(Option::PATHS, [
'src', 'tests'
return static function (ECSConfig $config): void {
$config->import('vendor/sylius-labs/coding-standard/ecs.php');
$config->paths([
'src',
'tests',
]);
$containerConfigurator->parameters()->set(Option::SKIP, [
'tests/Application/**',
$config->skip([
'tests/Application/node_modules/**',
'tests/Application/var/**',
]);
};
5 changes: 2 additions & 3 deletions src/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

#[AsCommand(
name: 'setono:sylius-meilisearch:index',
description: 'Will index all configured indexes'
description: 'Will index all configured indexes',
)]
final class IndexCommand extends Command
{

public function __construct(
private readonly MessageBusInterface $commandBus,
private readonly IndexRegistry $indexRegistry
private readonly IndexRegistry $indexRegistry,
) {
parent::__construct();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Config/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public function __construct(
string $document,
IndexerInterface $indexer,
array $resources,
string $prefix = null
string $prefix = null,
) {
Assert::stringNotEmpty($name);

if (!is_a($document, Document::class, true)) {
throw new \InvalidArgumentException(sprintf(
'The document class %s MUST be an instance of %s',
$document,
Document::class
Document::class,
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Config/IndexRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function add(Index $index): void
throw new \InvalidArgumentException(sprintf(
'The resource "%s" is already defined on the index "%s"',
$resource->name,
$existingIndex->name
$existingIndex->name,
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Config/IndexableResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(string $name, string $class)
throw new \InvalidArgumentException(sprintf(
'The document class %s MUST be an instance of %s',
$class,
IndexableInterface::class
IndexableInterface::class,
));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Action/SearchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
LocaleContextInterface $localeContext,
EventDispatcherInterface $eventDispatcher,
IndexRegistry $indexableResourceRegistry,
SortByResolverInterface $sortByResolver
SortByResolverInterface $sortByResolver,
) {
$this->twig = $twig;
$this->indexNameResolver = $indexNameResolver;
Expand All @@ -59,7 +59,7 @@ public function __invoke(string $slug): Response
throw new NotFoundHttpException(sprintf(
'The taxon with slug "%s" does not exist, is not enabled or is not translated in locale "%s"',
$slug,
$locale
$locale,
));
}

Expand Down
10 changes: 5 additions & 5 deletions src/DataMapper/ImageUrlsDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ImageUrlsDataMapper implements DataMapperInterface
public function __construct(
CacheManager $cacheManager,
array $resourceToFilterSetMapping = [], // todo add this to the plugin configuration
string $defaultFilterSet = 'sylius_large'
string $defaultFilterSet = 'sylius_large',
) {
$this->cacheManager = $cacheManager;
$this->resourceToFilterSetMapping = $resourceToFilterSetMapping;
Expand All @@ -39,11 +39,11 @@ public function map(
ResourceInterface $source,
Document $target,
IndexScope $indexScope,
array $context = []
array $context = [],
): void {
Assert::true(
$this->supports($source, $target, $indexScope, $context),
'The given $source and $target is not supported'
'The given $source and $target is not supported',
);

$imageUrls = [];
Expand All @@ -54,7 +54,7 @@ public function map(
$this->resourceToFilterSetMapping[get_class($source)] ?? $this->defaultFilterSet,
[],
null,
UrlGeneratorInterface::ABSOLUTE_PATH
UrlGeneratorInterface::ABSOLUTE_PATH,
);
}

Expand All @@ -69,7 +69,7 @@ public function supports(
ResourceInterface $source,
Document $target,
IndexScope $indexScope,
array $context = []
array $context = [],
): bool {
return $source instanceof ImagesAwareInterface && $target instanceof ImageUrlsAwareInterface;
}
Expand Down
6 changes: 3 additions & 3 deletions src/DataMapper/IndexableDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public function map(
ResourceInterface $source,
Document $target,
IndexScope $indexScope,
array $context = []
array $context = [],
): void {
Assert::true(
$this->supports($source, $target, $indexScope, $context),
'The given $source and $target is not supported'
'The given $source and $target is not supported',
);

$target->objectId = $source->getObjectId();
Expand All @@ -38,7 +38,7 @@ public function supports(
ResourceInterface $source,
Document $target,
IndexScope $indexScope,
array $context = []
array $context = [],
): bool {
return $source instanceof IndexableInterface;
}
Expand Down
6 changes: 3 additions & 3 deletions src/DataMapper/Product/PriceDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public function map(ResourceInterface $source, Document $target, IndexScope $ind
*/
public function supports(ResourceInterface $source, Document $target, IndexScope $indexScope, array $context = []): bool
{
return $source instanceof ProductInterface
&& $target instanceof ProductDocument
&& $indexScope->channelCode !== null
return $source instanceof ProductInterface &&
$target instanceof ProductDocument &&
$indexScope->channelCode !== null
;
}
}
10 changes: 5 additions & 5 deletions src/DataMapper/Product/ProductDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function map(ResourceInterface $source, Document $target, IndexScope $ind
{
Assert::true(
$this->supports($source, $target, $indexScope, $context),
'The given $source and $target is not supported'
'The given $source and $target is not supported',
);

$sourceTranslation = $source->getTranslation($indexScope->localeCode);
Expand All @@ -45,10 +45,10 @@ public function supports(
ResourceInterface $source,
Document $target,
IndexScope $indexScope,
array $context = []
array $context = [],
): bool {
return $source instanceof ProductInterface
&& $target instanceof Product
&& null !== $indexScope->localeCode;
return $source instanceof ProductInterface &&
$target instanceof Product &&
null !== $indexScope->localeCode;
}
}
2 changes: 1 addition & 1 deletion src/DataMapper/ResourceNameDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function supports(
ResourceInterface $source,
Document $target,
IndexScope $indexScope,
array $context = []
array $context = [],
): bool {
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/DataMapper/Taxon/TaxonDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function map(ResourceInterface $source, Document $target, IndexScope $ind
{
Assert::true(
$this->supports($source, $target, $indexScope, $context),
'The given $source and $target is not supported'
'The given $source and $target is not supported',
);

$target->name = $source->getTranslation($indexScope->localeCode)->getName();
Expand All @@ -38,10 +38,10 @@ public function supports(
ResourceInterface $source,
Document $target,
IndexScope $indexScope,
array $context = []
array $context = [],
): bool {
return $source instanceof TaxonInterface
&& $target instanceof Taxon
&& null !== $indexScope->localeCode;
return $source instanceof TaxonInterface &&
$target instanceof Taxon &&
null !== $indexScope->localeCode;
}
}
6 changes: 3 additions & 3 deletions src/DataMapper/UrlDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function map(
ResourceInterface $source,
Document $target,
IndexScope $indexScope,
array $context = []
array $context = [],
): void {
Assert::true(
$this->supports($source, $target, $indexScope, $context),
'The given $source and $target is not supported'
'The given $source and $target is not supported',
);

$target->setUrl($this->urlGenerator->generate($source, ['localeCode' => $indexScope->localeCode]));
Expand All @@ -45,7 +45,7 @@ public function supports(
ResourceInterface $source,
Document $target,
IndexScope $indexScope,
array $context = []
array $context = [],
): bool {
return $target instanceof UrlAwareInterface && null !== $indexScope->localeCode;
}
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/Compiler/RegisterIndexesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ final class RegisterIndexesPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('setono_sylius_meilisearch.config.index_registry')
|| !$container->hasParameter('setono_sylius_meilisearch.indexes')
|| !$container->hasParameter('sylius.resources')
if (!$container->hasDefinition('setono_sylius_meilisearch.config.index_registry') ||
!$container->hasParameter('setono_sylius_meilisearch.indexes') ||
!$container->hasParameter('sylius.resources')
) {
return;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Event/ProductIndexEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public function __construct(
public Response $response,
/** This is the name of the Meilisearch search index */
public readonly string $index,
public readonly TaxonInterface $taxon, public readonly string $slug, public readonly string $locale)
{
public readonly TaxonInterface $taxon,
public readonly string $slug,
public readonly string $locale,
) {
}
}
14 changes: 7 additions & 7 deletions src/EventSubscriber/InjectConfigurationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ public function addTags(ProductIndexEvent $event): void
{
$this->tags[] = sprintf(
'<div id="algolia-index" data-value="%s" style="display: none"></div>',
$event->index
$event->index,
);

$this->tags[] = sprintf(
'<div id="algolia-taxon" data-value="%s" style="display: none"></div>',
(string) $event->taxon->getCode()
(string) $event->taxon->getCode(),
);

$this->tags[] = sprintf(
'<script id="algolia-hit-template" type="text/template">%s</script>',
$this->twig->render('@SetonoSyliusMeilisearchPlugin/shop/product/_item.html.twig')
$this->twig->render('@SetonoSyliusMeilisearchPlugin/shop/product/_item.html.twig'),
);
}

Expand All @@ -62,10 +62,10 @@ public function inject(ResponseEvent $event): void
$response = $event->getResponse();

// this 'if' has been copied from \Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse()
if ($response->isRedirection()
|| 'html' !== $request->getRequestFormat()
|| false !== stripos($response->headers->get('Content-Disposition', ''), 'attachment;')
|| ($response->headers->has('Content-Type') && strpos($response->headers->get('Content-Type', ''), 'html') === false)
if ($response->isRedirection() ||
'html' !== $request->getRequestFormat() ||
false !== stripos($response->headers->get('Content-Disposition', ''), 'attachment;') ||
($response->headers->has('Content-Type') && strpos($response->headers->get('Content-Type', ''), 'html') === false)
) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Indexer/DefaultIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(
IndexRegistry $indexRegistry,
DoctrineFilterInterface $doctrineFilter,
ObjectFilterInterface $objectFilter,
array $normalizationGroups = ['setono:sylius-meilisearch:document']
array $normalizationGroups = ['setono:sylius-meilisearch:document'],
) {
$this->managerRegistry = $managerRegistry;
$this->indexScopeProvider = $indexScopeProvider;
Expand Down Expand Up @@ -122,7 +122,7 @@ public function indexEntitiesWithIds(array $ids, string $type): void
foreach ($this->indexScopeProvider->getAll($index) as $indexScope) {
$algoliaIndex = $this->prepareIndex(
$this->indexNameResolver->resolveFromIndexScope($indexScope),
$this->indexSettingsProvider->getSettings($indexScope)
$this->indexSettingsProvider->getSettings($indexScope),
);

foreach ($this->getObjects($ids, $type, $indexScope) as $obj) {
Expand All @@ -149,7 +149,7 @@ public function removeEntitiesWithIds(array $ids, string $type): void
foreach ($this->indexScopeProvider->getAll($index) as $indexScope) {
$algoliaIndex = $this->prepareIndex(
$this->indexNameResolver->resolveFromIndexScope($indexScope),
$this->indexSettingsProvider->getSettings($indexScope)
$this->indexSettingsProvider->getSettings($indexScope),
);

foreach ($this->getObjects($ids, $type, $indexScope) as $obj) {
Expand All @@ -170,7 +170,7 @@ protected function getIdBatches(IndexableResource $resource): \Generator
Assert::isInstanceOf($repository, IndexableResourceRepositoryInterface::class, sprintf(
'The repository for resource "%s" must implement the interface %s',
$resource->name,
IndexableResourceRepositoryInterface::class
IndexableResourceRepositoryInterface::class,
));

$firstResult = 0;
Expand Down Expand Up @@ -221,7 +221,7 @@ protected function getObjects(array $ids, string $type, IndexScope $indexScope):
Assert::isInstanceOf($repository, IndexableResourceRepositoryInterface::class, sprintf(
'The repository for resource "%s" must implement the interface %s',
$type,
IndexableResourceRepositoryInterface::class
IndexableResourceRepositoryInterface::class,
));

return $repository->findFromIndexScopeAndIds($indexScope, $ids);
Expand Down
2 changes: 0 additions & 2 deletions src/Indexer/IndexerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
namespace Setono\SyliusMeilisearchPlugin\Indexer;

use Setono\SyliusMeilisearchPlugin\Config\Index;
use Setono\SyliusMeilisearchPlugin\Config\IndexableResource;
use Setono\SyliusMeilisearchPlugin\Exception\NonExistingIndexException;
use Setono\SyliusMeilisearchPlugin\Exception\NonExistingResourceException;
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface;
use Sylius\Component\Resource\Model\ResourceInterface;

interface IndexerInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/EventContext/EventContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
ClientIdProviderInterface $clientIdProvider,
ChannelContextInterface $channelContext,
LocaleContextInterface $localeContext,
CurrencyContextInterface $currencyContext
CurrencyContextInterface $currencyContext,
) {
$this->clientIdProvider = $clientIdProvider;
$this->channelContext = $channelContext;
Expand All @@ -38,7 +38,7 @@ public function getEventContext(): EventContext
$this->clientIdProvider->getClientId(),
$this->channelContext->getChannel(),
$this->localeContext->getLocaleCode(),
$this->currencyContext->getCurrencyCode()
$this->currencyContext->getCurrencyCode(),
);
}
}
2 changes: 1 addition & 1 deletion src/Provider/IndexScope/CompositeIndexScopeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getFromChannelAndLocaleAndCurrency(
Index $index,
string $channelCode = null,
string $localeCode = null,
string $currencyCode = null
string $currencyCode = null,
): IndexScope {
foreach ($this->providers as $provider) {
if ($provider->supports($index)) {
Expand Down
Loading

0 comments on commit 470cf36

Please sign in to comment.