From 639d90a8493c8a068b4d0b2d99de57aa73c877d2 Mon Sep 17 00:00:00 2001 From: kuba-end Date: Tue, 7 Dec 2021 11:43:58 +0100 Subject: [PATCH] Bitbag ECS applied --- composer.json | 3 ++- ecs.php | 8 +----- src/Api/Serializer/CatalogNormalizer.php | 14 +++++++--- src/Checker/Rule/Doctrine/AbstractRule.php | 6 ++++- src/Checker/Rule/Doctrine/AttributeRule.php | 14 +++++++--- src/Checker/Rule/Doctrine/PriceRule.php | 27 ++++++++++++++++--- src/Checker/Rule/Doctrine/ProductCodeLike.php | 6 ++++- src/Checker/Rule/Doctrine/ProductNameRule.php | 8 ++++-- src/Checker/Rule/Doctrine/RuleInterface.php | 6 ++++- src/Checker/Rule/Doctrine/TaxonRule.php | 6 ++++- .../Compiler/CatalogRuleCheckersPass.php | 12 +++++++-- .../Compiler/CatalogSortChecker.php | 12 +++++++-- src/Fixture/Factory/CatalogFixtureFactory.php | 6 ++++- ...AbstractConfigurableCatalogElementType.php | 6 ++++- .../Type/AttributeAutocompleteChoiceType.php | 6 ++++- src/Form/Type/CatalogType.php | 6 ++++- .../AbstractConfigurationCollectionType.php | 6 ++++- src/Repository/AttributeRepository.php | 2 +- src/Repository/CatalogRepository.php | 2 +- src/Twig/Extension/RenderCatalogExtension.php | 2 +- .../RenderProductCatalogsExtension.php | 6 ++++- tests/Application/config/bootstrap.php | 2 +- .../config/sylius/1.10/bundles.php | 2 ++ .../Application/config/sylius/1.8/bundles.php | 2 ++ .../Application/config/sylius/1.9/bundles.php | 2 ++ 25 files changed, 134 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index 2dceb3b..2bad281 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "license": "MIT", "require": { "php": "^7.3 || ^7.4 || ^8.0", + "bitbag/coding-standard": "^1.0", "sylius/sylius": "~1.8.0 || ~1.9.0 || ~1.10.0" }, "require-dev": { @@ -34,7 +35,7 @@ "symfony/dotenv": "^4.4 || ^5.2", "symfony/intl": "^4.4 || ^5.2", "symfony/web-profiler-bundle": "^4.4 || ^5.2", - "vimeo/psalm": "4.6.4" + "vimeo/psalm": "^4.7" }, "config": { "sort-packages": true diff --git a/ecs.php b/ecs.php index f591833..b088160 100644 --- a/ecs.php +++ b/ecs.php @@ -2,17 +2,11 @@ declare(strict_types=1); -use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\EasyCodingStandard\ValueObject\Option; return static function (ContainerConfigurator $containerConfigurator): void { - $containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php'); - $services = $containerConfigurator->services(); - $services->set(ArraySyntaxFixer::class) - ->call('configure', [[ - 'syntax' => 'short', - ]]); + $containerConfigurator->import('vendor/bitbag/coding-standard/ecs.php'); $parameters = $containerConfigurator->parameters(); $parameters->set(Option::PATHS, [ diff --git a/src/Api/Serializer/CatalogNormalizer.php b/src/Api/Serializer/CatalogNormalizer.php index 76144a3..24a565c 100644 --- a/src/Api/Serializer/CatalogNormalizer.php +++ b/src/Api/Serializer/CatalogNormalizer.php @@ -32,7 +32,11 @@ public function __construct( $this->productResolver = $productResolver; } - public function normalize($object, $format = null, array $context = []) + public function normalize( + $object, + $format = null, + array $context = [] + ) { Assert::isInstanceOf($object, CatalogInterface::class); Assert::keyNotExists($context, self::ALREADY_CALLED); @@ -49,7 +53,11 @@ public function normalize($object, $format = null, array $context = []) return $data; } - public function supportsNormalization($data, $format = null, $context = []): bool + public function supportsNormalization( + $data, + $format = null, + $context = [] + ): bool { if (isset($context[self::ALREADY_CALLED])) { return false; @@ -60,6 +68,6 @@ public function supportsNormalization($data, $format = null, $context = []): boo private function isNotAdminGetOperation(array $context): bool { - return !isset($context['item_operation_name']) || !($context['item_operation_name'] === 'admin_get'); + return !isset($context['item_operation_name']) || !('admin_get' === $context['item_operation_name']); } } diff --git a/src/Checker/Rule/Doctrine/AbstractRule.php b/src/Checker/Rule/Doctrine/AbstractRule.php index b34063d..0c6153e 100644 --- a/src/Checker/Rule/Doctrine/AbstractRule.php +++ b/src/Checker/Rule/Doctrine/AbstractRule.php @@ -20,7 +20,11 @@ abstract class AbstractRule implements RuleInterface /** * @param Expr|Func|Comparison $rule */ - protected function addRule(string $connectingRules, QueryBuilder $queryBuilder, $rule): void + protected function addRule( + string $connectingRules, + QueryBuilder $queryBuilder, + $rule + ): void { switch ($connectingRules) { case RuleInterface::AND: diff --git a/src/Checker/Rule/Doctrine/AttributeRule.php b/src/Checker/Rule/Doctrine/AttributeRule.php index a3ca2b4..20e26bf 100644 --- a/src/Checker/Rule/Doctrine/AttributeRule.php +++ b/src/Checker/Rule/Doctrine/AttributeRule.php @@ -28,7 +28,11 @@ public function __construct(LocaleContextInterface $localeContext) $this->localeContext = $localeContext; } - public function modifyQueryBuilder(array $configuration, QueryBuilder $queryBuilder, string $connectingRules): void + public function modifyQueryBuilder( + array $configuration, + QueryBuilder $queryBuilder, + string $connectingRules + ): void { /** @var AttributeInterface $attribute */ $attribute = $configuration['attribute']; @@ -42,7 +46,11 @@ public function modifyQueryBuilder(array $configuration, QueryBuilder $queryBuil $this->addRule($connectingRules, $queryBuilder, $rule); } - private function buildRule(QueryBuilder $queryBuilder, AttributeInterface $attribute, string $value): Andx + private function buildRule( + QueryBuilder $queryBuilder, + AttributeInterface $attribute, + string $value + ): Andx { $valueFieldName = self::PRODUCT_ATTRIBUTES_ALIAS . '.' . $this->getAttributeStorageFieldName($attribute->getType()); @@ -53,7 +61,7 @@ private function buildRule(QueryBuilder $queryBuilder, AttributeInterface $attri $conditions->add($queryBuilder->expr()->eq(self::PRODUCT_ATTRIBUTES_ALIAS . '.localeCode', ":{$localeCodeParameterName}")); - if ($attribute->getType() !== SelectAttributeType::TYPE) { + if (SelectAttributeType::TYPE !== $attribute->getType()) { $conditions->add($queryBuilder->expr()->eq($valueFieldName, ":{$attributeValueParamName}")); $queryBuilder->setParameter($attributeValueParamName, $value); diff --git a/src/Checker/Rule/Doctrine/PriceRule.php b/src/Checker/Rule/Doctrine/PriceRule.php index 02f559d..82e0724 100644 --- a/src/Checker/Rule/Doctrine/PriceRule.php +++ b/src/Checker/Rule/Doctrine/PriceRule.php @@ -28,7 +28,11 @@ public function __construct(ChannelContextInterface $channelContext) $this->channelContext = $channelContext; } - public function modifyQueryBuilder(array $configuration, QueryBuilder $queryBuilder, string $connectingRules): void + public function modifyQueryBuilder( + array $configuration, + QueryBuilder $queryBuilder, + string $connectingRules + ): void { $priceParameter = $this->generateParameterName(); $channelCodeParameter = $this->generateParameterName(); @@ -53,7 +57,12 @@ private function generateParameterName(): string return 'productPriceHigher' . $this->i++; } - private function anyVariantRule(QueryBuilder $queryBuilder, string $channelCodeParameter, string $subqueryOperator, string $priceParameter): Func + private function anyVariantRule( + QueryBuilder $queryBuilder, + string $channelCodeParameter, + string $subqueryOperator, + string $priceParameter + ): Func { $productVariantAlias = sprintf('pv%d', $this->i++); $channelPricingAlias = sprintf('cp%d', $this->i++); @@ -70,7 +79,12 @@ private function anyVariantRule(QueryBuilder $queryBuilder, string $channelCodeP return $queryBuilder->expr()->exists($subquery->getDQL()); } - private function allVariantsRule(QueryBuilder $queryBuilder, string $channelCodeParameter, string $subqueryOperator, string $priceParameter): Func + private function allVariantsRule( + QueryBuilder $queryBuilder, + string $channelCodeParameter, + string $subqueryOperator, + string $priceParameter + ): Func { $productVariantAlias = sprintf('pv%d', $this->i++); $channelPricingAlias = sprintf('cp%d', $this->i++); @@ -87,7 +101,12 @@ private function allVariantsRule(QueryBuilder $queryBuilder, string $channelCode ->not($queryBuilder->expr()->exists($subquery->getDQL())); } - private function createFromFromOperator(string $operator, QueryBuilder $queryBuilder, string $channelCodeParameter, string $priceParameter): Func + private function createFromFromOperator( + string $operator, + QueryBuilder $queryBuilder, + string $channelCodeParameter, + string $priceParameter + ): Func { switch ($operator) { case PriceConfigurationType::OPERATOR_ALL_GT: diff --git a/src/Checker/Rule/Doctrine/ProductCodeLike.php b/src/Checker/Rule/Doctrine/ProductCodeLike.php index 6719138..5ad82f0 100644 --- a/src/Checker/Rule/Doctrine/ProductCodeLike.php +++ b/src/Checker/Rule/Doctrine/ProductCodeLike.php @@ -26,7 +26,11 @@ final class ProductCodeLike extends AbstractRule implements RuleInterface private int $i = 0; - public function modifyQueryBuilder(array $configuration, QueryBuilder $queryBuilder, string $connectingRules): void + public function modifyQueryBuilder( + array $configuration, + QueryBuilder $queryBuilder, + string $connectingRules + ): void { $parameterName = $this->generateParameterName(); diff --git a/src/Checker/Rule/Doctrine/ProductNameRule.php b/src/Checker/Rule/Doctrine/ProductNameRule.php index 5852984..d1439cf 100644 --- a/src/Checker/Rule/Doctrine/ProductNameRule.php +++ b/src/Checker/Rule/Doctrine/ProductNameRule.php @@ -24,13 +24,17 @@ public function __construct(LocaleContextInterface $localeContext) $this->localeContext = $localeContext; } - public function modifyQueryBuilder(array $configuration, QueryBuilder $queryBuilder, string $connectingRules): void + public function modifyQueryBuilder( + array $configuration, + QueryBuilder $queryBuilder, + string $connectingRules + ): void { $parameterName = 'configurationName' . $this->i; $locale = $this->localeContext->getLocaleCode(); ++$this->i; - if ($connectingRules === self::OR) { + if (self::OR === $connectingRules) { $queryBuilder ->andWhere('name.locale =:locale') ->orWhere('name.name like :' . $parameterName); diff --git a/src/Checker/Rule/Doctrine/RuleInterface.php b/src/Checker/Rule/Doctrine/RuleInterface.php index 214b2dc..0dcc8f8 100644 --- a/src/Checker/Rule/Doctrine/RuleInterface.php +++ b/src/Checker/Rule/Doctrine/RuleInterface.php @@ -18,5 +18,9 @@ interface RuleInterface public const AND = 'And'; - public function modifyQueryBuilder(array $configuration, QueryBuilder $queryBuilder, string $connectingRules): void; + public function modifyQueryBuilder( + array $configuration, + QueryBuilder $queryBuilder, + string $connectingRules + ): void; } diff --git a/src/Checker/Rule/Doctrine/TaxonRule.php b/src/Checker/Rule/Doctrine/TaxonRule.php index cfd30ef..61f754f 100644 --- a/src/Checker/Rule/Doctrine/TaxonRule.php +++ b/src/Checker/Rule/Doctrine/TaxonRule.php @@ -24,7 +24,11 @@ public function __construct(ChannelContextInterface $channelContext) $this->channelContext = $channelContext; } - public function modifyQueryBuilder(array $configuration, QueryBuilder $queryBuilder, string $connectingRules): void + public function modifyQueryBuilder( + array $configuration, + QueryBuilder $queryBuilder, + string $connectingRules + ): void { $taxonsParameterName = $this->generateParameterName(); diff --git a/src/DependencyInjection/Compiler/CatalogRuleCheckersPass.php b/src/DependencyInjection/Compiler/CatalogRuleCheckersPass.php index eb3c898..ab3b7ed 100644 --- a/src/DependencyInjection/Compiler/CatalogRuleCheckersPass.php +++ b/src/DependencyInjection/Compiler/CatalogRuleCheckersPass.php @@ -30,12 +30,20 @@ public function process(ContainerBuilder $container): void } } - private function serviceImplementsInterface(ContainerBuilder $container, string $id, string $ruleInterface): bool + private function serviceImplementsInterface( + ContainerBuilder $container, + string $id, + string $ruleInterface + ): bool { return isset(class_implements($container->getDefinition($id)->getClass())[$ruleInterface]); } - private function addDriverRulesToRegistries(string $driver, ContainerBuilder $container, string $ruleInterface): void + private function addDriverRulesToRegistries( + string $driver, + ContainerBuilder $container, + string $ruleInterface + ): void { $driverRuleRegistry = sprintf('bitbag_sylius_catalog_plugin.registry_catalog_rule_checker.%s', $driver); $driverFormRegistry = sprintf('bitbag_sylius_catalog_plugin.form_registry.catalog_rule_checker.%s', $driver); diff --git a/src/DependencyInjection/Compiler/CatalogSortChecker.php b/src/DependencyInjection/Compiler/CatalogSortChecker.php index 5806b77..ec0e5a3 100644 --- a/src/DependencyInjection/Compiler/CatalogSortChecker.php +++ b/src/DependencyInjection/Compiler/CatalogSortChecker.php @@ -30,12 +30,20 @@ public function process(ContainerBuilder $container): void } } - private function serviceImplementsInterface(ContainerBuilder $container, string $id, string $sortInterface): bool + private function serviceImplementsInterface( + ContainerBuilder $container, + string $id, + string $sortInterface + ): bool { return isset(class_implements($container->getDefinition($id)->getClass())[$sortInterface]); } - private function addDriverSortsToRegistries(string $driver, ContainerBuilder $container, string $sortInterface): void + private function addDriverSortsToRegistries( + string $driver, + ContainerBuilder $container, + string $sortInterface + ): void { $driverSortRegistry = sprintf('bitbag_sylius_catalog_plugin.registry_catalog_sort_checker.%s', $driver); diff --git a/src/Fixture/Factory/CatalogFixtureFactory.php b/src/Fixture/Factory/CatalogFixtureFactory.php index f70b2bb..5804bb7 100644 --- a/src/Fixture/Factory/CatalogFixtureFactory.php +++ b/src/Fixture/Factory/CatalogFixtureFactory.php @@ -89,7 +89,11 @@ private function createCatalog(string $code, array $catalogData): void $this->catalogRepository->add($catalog); } - private function createRule($rule, string $ruleTarget, CatalogInterface $catalog): void + private function createRule( + $rule, + string $ruleTarget, + CatalogInterface $catalog + ): void { /** @var CatalogRuleInterface $catalogRule */ $catalogRule = $this->catalogRuleFactory->createNew(); diff --git a/src/Form/Type/AbstractConfigurableCatalogElementType.php b/src/Form/Type/AbstractConfigurableCatalogElementType.php index 0940684..af5baee 100644 --- a/src/Form/Type/AbstractConfigurableCatalogElementType.php +++ b/src/Form/Type/AbstractConfigurableCatalogElementType.php @@ -23,7 +23,11 @@ abstract class AbstractConfigurableCatalogElementType extends AbstractResourceTy { private FormTypeRegistryInterface $formTypeRegistry; - public function __construct(string $dataClass, array $validationGroups = [], FormTypeRegistryInterface $formTypeRegistry) + public function __construct( + string $dataClass, + array $validationGroups = [], + FormTypeRegistryInterface $formTypeRegistry + ) { parent::__construct($dataClass, $validationGroups); diff --git a/src/Form/Type/AttributeAutocompleteChoiceType.php b/src/Form/Type/AttributeAutocompleteChoiceType.php index 5c0feac..4b65fe5 100644 --- a/src/Form/Type/AttributeAutocompleteChoiceType.php +++ b/src/Form/Type/AttributeAutocompleteChoiceType.php @@ -27,7 +27,11 @@ public function configureOptions(OptionsResolver $resolver): void ]); } - public function buildView(FormView $view, FormInterface $form, array $options): void + public function buildView( + FormView $view, + FormInterface $form, + array $options + ): void { $view->vars['remote_criteria_type'] = 'contains'; $view->vars['remote_criteria_name'] = 'code'; diff --git a/src/Form/Type/CatalogType.php b/src/Form/Type/CatalogType.php index 6b91bcd..37a5806 100644 --- a/src/Form/Type/CatalogType.php +++ b/src/Form/Type/CatalogType.php @@ -25,7 +25,11 @@ final class CatalogType extends AbstractResourceType { private array $attributeChoices; - public function __construct(string $dataClass, array $attributeChoices, array $validationGroups = []) + public function __construct( + string $dataClass, + array $attributeChoices, + array $validationGroups = [] + ) { parent::__construct($dataClass, $validationGroups); diff --git a/src/Form/Type/Core/AbstractConfigurationCollectionType.php b/src/Form/Type/Core/AbstractConfigurationCollectionType.php index d4ba993..9863ec6 100644 --- a/src/Form/Type/Core/AbstractConfigurationCollectionType.php +++ b/src/Form/Type/Core/AbstractConfigurationCollectionType.php @@ -49,7 +49,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void /** * @psalm-suppress MissingPropertyType */ - public function buildView(FormView $view, FormInterface $form, array $options): void + public function buildView( + FormView $view, + FormInterface $form, + array $options + ): void { $view->vars['prototypes'] = []; diff --git a/src/Repository/AttributeRepository.php b/src/Repository/AttributeRepository.php index 2a9ae82..1ad472d 100644 --- a/src/Repository/AttributeRepository.php +++ b/src/Repository/AttributeRepository.php @@ -12,7 +12,7 @@ use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; -final class AttributeRepository extends EntityRepository implements AttributeRepositoryInterface +class AttributeRepository extends EntityRepository implements AttributeRepositoryInterface { public function findByCodePart(string $code, ?int $limit = null): array { diff --git a/src/Repository/CatalogRepository.php b/src/Repository/CatalogRepository.php index c0e9d00..6bb35a4 100644 --- a/src/Repository/CatalogRepository.php +++ b/src/Repository/CatalogRepository.php @@ -12,7 +12,7 @@ use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; -final class CatalogRepository extends EntityRepository implements CatalogRepositoryInterface +class CatalogRepository extends EntityRepository implements CatalogRepositoryInterface { /** * @return Catalog[] diff --git a/src/Twig/Extension/RenderCatalogExtension.php b/src/Twig/Extension/RenderCatalogExtension.php index 3c03da8..6b27cdb 100644 --- a/src/Twig/Extension/RenderCatalogExtension.php +++ b/src/Twig/Extension/RenderCatalogExtension.php @@ -52,7 +52,7 @@ public function renderProductCatalog(?string $code): string $products = $this->productResolver->findMatchingProducts($catalog); } - if (empty($products) !== null && $catalog !== null) { + if (null !== empty($products) && null !== $catalog) { $template = $catalog->getTemplate() ?? '@BitBagSyliusCatalogPlugin/Catalog/Templates/showProducts.html.twig'; return $this->engine->render($template, ['products' => $products, 'catalog' => $catalog]); diff --git a/src/Twig/Extension/RenderProductCatalogsExtension.php b/src/Twig/Extension/RenderProductCatalogsExtension.php index 8c4c256..d8202d6 100644 --- a/src/Twig/Extension/RenderProductCatalogsExtension.php +++ b/src/Twig/Extension/RenderProductCatalogsExtension.php @@ -37,7 +37,11 @@ public function getFunctions(): array ]; } - public function renderProductCatalogs(ProductInterface $product, ?string $date = null, ?string $template = null): string + public function renderProductCatalogs( + ProductInterface $product, + ?string $date = null, + ?string $template = null + ): string { return $this->engine->render( $template ?? '@BitBagSyliusCatalogPlugin/Product/showCatalogs.html.twig', diff --git a/tests/Application/config/bootstrap.php b/tests/Application/config/bootstrap.php index e23eca0..d7ac51d 100644 --- a/tests/Application/config/bootstrap.php +++ b/tests/Application/config/bootstrap.php @@ -4,7 +4,7 @@ use Symfony\Component\Dotenv\Dotenv; -require dirname(__DIR__).'../../../vendor/autoload.php'; +require dirname(__DIR__) . '../../../vendor/autoload.php'; // Load cached env vars if the .env.local.php file exists // Run "composer dump-env prod" to create it (requires symfony/flex >=1.2) diff --git a/tests/Application/config/sylius/1.10/bundles.php b/tests/Application/config/sylius/1.10/bundles.php index bd33f4a..d50639f 100644 --- a/tests/Application/config/sylius/1.10/bundles.php +++ b/tests/Application/config/sylius/1.10/bundles.php @@ -1,5 +1,7 @@ ['all' => true], SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], diff --git a/tests/Application/config/sylius/1.8/bundles.php b/tests/Application/config/sylius/1.8/bundles.php index c3c8ea4..161339d 100644 --- a/tests/Application/config/sylius/1.8/bundles.php +++ b/tests/Application/config/sylius/1.8/bundles.php @@ -1,5 +1,7 @@ ['all' => true], WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true], diff --git a/tests/Application/config/sylius/1.9/bundles.php b/tests/Application/config/sylius/1.9/bundles.php index bd33f4a..d50639f 100644 --- a/tests/Application/config/sylius/1.9/bundles.php +++ b/tests/Application/config/sylius/1.9/bundles.php @@ -1,5 +1,7 @@ ['all' => true], SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],