Skip to content

Commit

Permalink
Merge pull request #27 from kuba-end/ECS/Bitbag-standard
Browse files Browse the repository at this point in the history
Bitbag ECS applied
  • Loading branch information
er1z authored Dec 7, 2021
2 parents d239fb7 + 639d90a commit 2d5b7d1
Show file tree
Hide file tree
Showing 25 changed files with 134 additions and 38 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down
14 changes: 11 additions & 3 deletions src/Api/Serializer/CatalogNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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']);
}
}
6 changes: 5 additions & 1 deletion src/Checker/Rule/Doctrine/AbstractRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 11 additions & 3 deletions src/Checker/Rule/Doctrine/AttributeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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());

Expand All @@ -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);
Expand Down
27 changes: 23 additions & 4 deletions src/Checker/Rule/Doctrine/PriceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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++);
Expand All @@ -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++);
Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion src/Checker/Rule/Doctrine/ProductCodeLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
8 changes: 6 additions & 2 deletions src/Checker/Rule/Doctrine/ProductNameRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/Checker/Rule/Doctrine/RuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 5 additions & 1 deletion src/Checker/Rule/Doctrine/TaxonRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 10 additions & 2 deletions src/DependencyInjection/Compiler/CatalogRuleCheckersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions src/DependencyInjection/Compiler/CatalogSortChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion src/Fixture/Factory/CatalogFixtureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/Form/Type/AbstractConfigurableCatalogElementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion src/Form/Type/AttributeAutocompleteChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 5 additions & 1 deletion src/Form/Type/CatalogType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion src/Form/Type/Core/AbstractConfigurationCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Repository/AttributeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/CatalogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/Extension/RenderCatalogExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
6 changes: 5 additions & 1 deletion src/Twig/Extension/RenderProductCatalogsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/Application/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/config/sylius/1.10/bundles.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
Expand Down
Loading

0 comments on commit 2d5b7d1

Please sign in to comment.