diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d1be73b..9d032fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -172,6 +172,10 @@ jobs: name: Validate database schema run: (cd tests/Application && bin/console doctrine:schema:validate) + - + name: Run ECS + run: vendor/bin/ecs check src + - name: Run PHPSpec run: vendor/bin/phpspec run --ansi -f progress --no-interaction diff --git a/composer.json b/composer.json index 51e2f0e..89a7073 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "behat/behat": "^3.7", "behat/mink": "^1.8", "behat/mink-selenium2-driver": "^1.4", + "bitbag/coding-standard": "^1.0.1", "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", "friends-of-behat/mink": "^1.8", @@ -31,16 +32,15 @@ "phpstan/phpstan-strict-rules": "^0.12.0", "phpstan/phpstan-webmozart-assert": "0.12.12", "phpunit/phpunit": "^9.5", + "polishsymfonycommunity/symfony-mocker-container": "^1.0", "sensiolabs/security-checker": "^6.0", - "sylius-labs/coding-standard": "^4.0", "symfony/browser-kit": "^4.4 || ^5.2", "symfony/debug-bundle": "^4.4 || ^5.2", "symfony/dotenv": "^4.4 || ^5.2", "symfony/intl": "^4.4 || ^5.2", "symfony/web-profiler-bundle": "^4.4 || ^5.2", "symfony/webpack-encore-bundle": "^1.14", - "vimeo/psalm": "4.7.1", - "polishsymfonycommunity/symfony-mocker-container": "^1.0" + "vimeo/psalm": "4.7.1" }, "autoload": { "psr-4": { diff --git a/ecs.php b/ecs.php index bf40cc9..34cb6c5 100644 --- a/ecs.php +++ b/ecs.php @@ -1,14 +1,14 @@ import('vendor/sylius-labs/coding-standard/ecs.php'); + $containerConfigurator->import('vendor/bitbag/coding-standard/ecs.php'); - $containerConfigurator->parameters()->set(Option::SKIP, [ - VisibilityRequiredFixer::class => ['*Spec.php'], + $parameters = $containerConfigurator->parameters(); + $parameters->set(Option::PATHS, [ + __DIR__ . '/src', + __DIR__ . '/tests', ]); }; diff --git a/src/BitBagSyliusBlacklistPlugin.php b/src/BitBagSyliusBlacklistPlugin.php index 259adcc..ccb6575 100644 --- a/src/BitBagSyliusBlacklistPlugin.php +++ b/src/BitBagSyliusBlacklistPlugin.php @@ -7,6 +7,7 @@ */ declare(strict_types=1); + namespace BitBag\SyliusBlacklistPlugin; use BitBag\SyliusBlacklistPlugin\DependencyInjection\Compiler\RegisterAutomaticBlacklistingRuleCheckersPass; diff --git a/src/Checker/BlacklistingRule/BlacklistingRuleEligibilityChecker.php b/src/Checker/BlacklistingRule/BlacklistingRuleEligibilityChecker.php index 7d733f6..2dc37a7 100644 --- a/src/Checker/BlacklistingRule/BlacklistingRuleEligibilityChecker.php +++ b/src/Checker/BlacklistingRule/BlacklistingRuleEligibilityChecker.php @@ -17,7 +17,7 @@ final class BlacklistingRuleEligibilityChecker implements BlacklistingRuleEligib { public function isEligible(BlacklistingRuleInterface $blacklistingRule, CustomerInterface $customer): bool { - if ($blacklistingRule->isOnlyForGuests() && $customer->getUser() !== null) { + if ($blacklistingRule->isOnlyForGuests() && null !== $customer->getUser()) { return false; } @@ -33,8 +33,8 @@ public function isEligible(BlacklistingRuleInterface $blacklistingRule, Customer } return true; - } else { - return !$blacklistingRule->getCustomerGroups()->isEmpty() && !$blacklistingRule->isForUnassignedCustomers() ? false : true; } + + return !$blacklistingRule->getCustomerGroups()->isEmpty() && !$blacklistingRule->isForUnassignedCustomers() ? false : true; } } diff --git a/src/Checker/FraudSuspicion/FraudSuspicionActionEligibilityChecker.php b/src/Checker/FraudSuspicion/FraudSuspicionActionEligibilityChecker.php index 7c4730f..00975e5 100644 --- a/src/Checker/FraudSuspicion/FraudSuspicionActionEligibilityChecker.php +++ b/src/Checker/FraudSuspicion/FraudSuspicionActionEligibilityChecker.php @@ -50,7 +50,7 @@ public function canAddFraudSuspicion( $date ); - if (intval($lastFraudSuspicionsOfCustomer) >= $automaticBlacklistingConfiguration->getPermittedFraudSuspicionsNumber()) { + if ((int) $lastFraudSuspicionsOfCustomer >= $automaticBlacklistingConfiguration->getPermittedFraudSuspicionsNumber()) { $this->customerStateResolver->changeStateOnBlacklisted($customer); return false; diff --git a/src/Entity/Customer/FraudStatusInterface.php b/src/Entity/Customer/FraudStatusInterface.php index 8809cf9..e268a39 100644 --- a/src/Entity/Customer/FraudStatusInterface.php +++ b/src/Entity/Customer/FraudStatusInterface.php @@ -1,5 +1,7 @@ attributes); - if ($index !== false) { + if (false !== $index) { unset($this->attributes[$index]); } } @@ -149,7 +150,7 @@ public function removeCustomerGroup(CustomerGroupInterface $customerGroup): void public function hasCustomerGroup(?CustomerGroupInterface $customerGroup): bool { - if ($customerGroup === null) { + if (null === $customerGroup) { return false; } diff --git a/src/Entity/FraudPrevention/FraudSuspicion.php b/src/Entity/FraudPrevention/FraudSuspicion.php index 65a90a3..2ea401d 100644 --- a/src/Entity/FraudPrevention/FraudSuspicion.php +++ b/src/Entity/FraudPrevention/FraudSuspicion.php @@ -10,8 +10,8 @@ namespace BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention; -use Sylius\Component\Order\Model\OrderInterface; use Sylius\Component\Customer\Model\CustomerInterface; +use Sylius\Component\Order\Model\OrderInterface; use Sylius\Component\Resource\Model\TimestampableTrait; class FraudSuspicion implements FraudSuspicionInterface diff --git a/src/Entity/FraudPrevention/FraudSuspicionInterface.php b/src/Entity/FraudPrevention/FraudSuspicionInterface.php index ead9f74..98883fa 100644 --- a/src/Entity/FraudPrevention/FraudSuspicionInterface.php +++ b/src/Entity/FraudPrevention/FraudSuspicionInterface.php @@ -10,9 +10,9 @@ namespace BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention; +use Sylius\Component\Customer\Model\CustomerInterface; use Sylius\Component\Order\Model\OrderInterface; use Sylius\Component\Resource\Model\ResourceInterface; -use Sylius\Component\Customer\Model\CustomerInterface; use Sylius\Component\Resource\Model\TimestampableInterface; interface FraudSuspicionInterface extends ResourceInterface, TimestampableInterface diff --git a/src/EntityListener/FraudSuspicionEntityListener.php b/src/EntityListener/FraudSuspicionEntityListener.php index 4def1e3..990b86d 100644 --- a/src/EntityListener/FraudSuspicionEntityListener.php +++ b/src/EntityListener/FraudSuspicionEntityListener.php @@ -16,7 +16,7 @@ use BitBag\SyliusBlacklistPlugin\StateResolver\CustomerStateResolverInterface; use Doctrine\ORM\Event\LifecycleEventArgs; -final class FraudSuspicionEntityListener +class FraudSuspicionEntityListener { /** @var SuspiciousOrderResolverInterface */ private $suspiciousOrderResolver; @@ -45,5 +45,4 @@ public function prePersist(FraudSuspicionInterface $newFraudSuspicion, Lifecycle $this->customerStateResolver->changeStateOnBlacklisted($newFraudSuspicion->getCustomer()); } } - } diff --git a/src/Factory/FraudSuspicionCommonModelFactoryInterface.php b/src/Factory/FraudSuspicionCommonModelFactoryInterface.php index 10e68eb..e671e0c 100644 --- a/src/Factory/FraudSuspicionCommonModelFactoryInterface.php +++ b/src/Factory/FraudSuspicionCommonModelFactoryInterface.php @@ -17,4 +17,3 @@ interface FraudSuspicionCommonModelFactoryInterface extends FactoryInterface { public function createNew(): FraudSuspicionCommonModelInterface; } - diff --git a/src/Factory/FraudSuspicionFactoryInterface.php b/src/Factory/FraudSuspicionFactoryInterface.php index 0a07f8b..0dbe507 100644 --- a/src/Factory/FraudSuspicionFactoryInterface.php +++ b/src/Factory/FraudSuspicionFactoryInterface.php @@ -20,4 +20,3 @@ public function createForOrder(OrderInterface $order): FraudSuspicionInterface; public function createForAutomaticBlacklistingConfiguration(OrderInterface $order): FraudSuspicionInterface; } - diff --git a/src/Form/Rule/AutomaticBlacklistingRuleSettingsType.php b/src/Form/Rule/AutomaticBlacklistingRuleSettingsType.php index b393db4..16240e6 100644 --- a/src/Form/Rule/AutomaticBlacklistingRuleSettingsType.php +++ b/src/Form/Rule/AutomaticBlacklistingRuleSettingsType.php @@ -40,7 +40,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'bitbag_sylius_blacklist_plugin.form.automatic_blacklisting_rule.per_week' => AutomaticBlacklistingRuleInterface::PER_WEEK, 'bitbag_sylius_blacklist_plugin.form.automatic_blacklisting_rule.per_month' => AutomaticBlacklistingRuleInterface::PER_MONTH, ], - 'attr' => ['style' => 'margin-bottom: 10px;'] + 'attr' => ['style' => 'margin-bottom: 10px;'], ]) ; } diff --git a/src/Form/Type/AbstractConfigurableAutomaticBlacklistingConfigurationElementType.php b/src/Form/Type/AbstractConfigurableAutomaticBlacklistingConfigurationElementType.php index af70096..f4075d3 100644 --- a/src/Form/Type/AbstractConfigurableAutomaticBlacklistingConfigurationElementType.php +++ b/src/Form/Type/AbstractConfigurableAutomaticBlacklistingConfigurationElementType.php @@ -24,8 +24,11 @@ abstract class AbstractConfigurableAutomaticBlacklistingConfigurationElementType /** @var FormTypeRegistryInterface */ private $formTypeRegistry; - public function __construct(string $dataClass, FormTypeRegistryInterface $formTypeRegistry, array $validationGroups = []) - { + public function __construct( + string $dataClass, + FormTypeRegistryInterface $formTypeRegistry, + array $validationGroups = [] + ) { parent::__construct($dataClass, $validationGroups); $this->formTypeRegistry = $formTypeRegistry; diff --git a/src/Form/Type/AutomaticBlacklistingConfigurationType.php b/src/Form/Type/AutomaticBlacklistingConfigurationType.php index ac76474..37aa51a 100644 --- a/src/Form/Type/AutomaticBlacklistingConfigurationType.php +++ b/src/Form/Type/AutomaticBlacklistingConfigurationType.php @@ -25,8 +25,11 @@ final class AutomaticBlacklistingConfigurationType extends AbstractResourceType /** @var array */ private $attributeChoices; - public function __construct(string $dataClass, array $attributeChoices, array $validationGroups = []) - { + public function __construct( + string $dataClass, + array $attributeChoices, + array $validationGroups = [] + ) { parent::__construct($dataClass, $validationGroups); $this->attributeChoices = $attributeChoices; } @@ -44,18 +47,18 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ]) ->add('enabled', CheckboxType::class, [ 'label' => 'sylius.ui.enabled', - 'required' => false + 'required' => false, ]) ->add('addFraudSuspicion', CheckboxType::class, [ 'label' => 'bitbag_sylius_blacklist_plugin.ui.add_fraud_suspicion_row_after_exceed_limit', - 'required' => false + 'required' => false, ]) ->add('permittedFraudSuspicionsNumber', NumberType::class, [ 'label' => 'bitbag_sylius_blacklist_plugin.ui.permitted_fraud_suspicions_number', 'required' => false, 'constraints' => [ - new GreaterThanOrEqual(['value' => 1, 'groups' => ['bitbag']]) - ] + new GreaterThanOrEqual(['value' => 1, 'groups' => ['bitbag']]), + ], ]) ->add('permittedFraudSuspicionsTime', ChoiceType::class, [ 'label' => false, @@ -66,7 +69,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'bitbag_sylius_blacklist_plugin.form.automatic_blacklisting_rule.per_week' => AutomaticBlacklistingRuleInterface::PER_WEEK, 'bitbag_sylius_blacklist_plugin.form.automatic_blacklisting_rule.per_month' => AutomaticBlacklistingRuleInterface::PER_MONTH, ], - 'placeholder' => 'bitbag_sylius_blacklist_plugin.ui.choose_time_range' + 'placeholder' => 'bitbag_sylius_blacklist_plugin.ui.choose_time_range', ]) ->add('rules', AutomaticBlacklistingRuleCollectionType::class, [ 'label' => 'bitbag_sylius_blacklist_plugin.form.automatic_blacklisting_rule.rules', diff --git a/src/Form/Type/BlacklistingRuleType.php b/src/Form/Type/BlacklistingRuleType.php index 127bcd7..1707e72 100644 --- a/src/Form/Type/BlacklistingRuleType.php +++ b/src/Form/Type/BlacklistingRuleType.php @@ -12,7 +12,6 @@ use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Component\Customer\Model\CustomerGroup; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -50,8 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'label' => 'bitbag_sylius_blacklist_plugin.form.blacklisting_rule.attribute', 'multiple' => true, 'expanded' => true, - 'choices' => $this->attributeChoices - + 'choices' => $this->attributeChoices, ]) ->add('permittedStrikes', NumberType::class, [ 'label' => 'bitbag_sylius_blacklist_plugin.form.blacklisting_rule.permitted_strikes', @@ -69,11 +67,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ]) ->add('forUnassignedCustomers', CheckboxType::class, [ 'label' => 'bitbag_sylius_blacklist_plugin.form.blacklisting_rule.for_unassigned_customers', - 'required' => false + 'required' => false, ]) ->add('onlyForGuests', CheckboxType::class, [ 'label' => 'bitbag_sylius_blacklist_plugin.form.blacklisting_rule.only_for_guests', - 'required' => false + 'required' => false, ]) ->add('enabled', CheckboxType::class, [ 'label' => 'sylius.ui.enabled', diff --git a/src/Form/Type/FraudSuspicionOrderType.php b/src/Form/Type/FraudSuspicionOrderType.php index 287b638..350e498 100644 --- a/src/Form/Type/FraudSuspicionOrderType.php +++ b/src/Form/Type/FraudSuspicionOrderType.php @@ -24,8 +24,11 @@ final class FraudSuspicionOrderType extends AbstractResourceType /** @var AddressTypeResolver */ private $addressTypeResolver; - public function __construct(string $dataClass, AddressTypeResolver $addressTypeResolver, array $validationGroups = []) - { + public function __construct( + string $dataClass, + AddressTypeResolver $addressTypeResolver, + array $validationGroups = [] + ) { parent::__construct($dataClass, $validationGroups); $this->addressTypeResolver = $addressTypeResolver; @@ -38,12 +41,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'label' => 'bitbag_sylius_blacklist_plugin.ui.address_type', 'choices' => [ 'sylius.ui.shipping_address' => FraudSuspicionInterface::SHIPPING_ADDRESS_TYPE, - 'sylius.ui.billing_address' => FraudSuspicionInterface::BILLING_ADDRESS_TYPE - ] + 'sylius.ui.billing_address' => FraudSuspicionInterface::BILLING_ADDRESS_TYPE, + ], ]) ->add('comment', TextareaType::class, [ 'label' => 'bitbag_sylius_blacklist_plugin.form.fraud_suspicion.comment', - 'required' => false + 'required' => false, ]) ->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event): void { $this->addressTypeResolver->resolveAndUpdateFraudSuspicion($event->getData()); diff --git a/src/Form/Type/FraudSuspicionType.php b/src/Form/Type/FraudSuspicionType.php index d2d03ce..247129e 100644 --- a/src/Form/Type/FraudSuspicionType.php +++ b/src/Form/Type/FraudSuspicionType.php @@ -23,8 +23,11 @@ final class FraudSuspicionType extends AbstractResourceType /** @var string */ private $customerClass; - public function __construct(string $dataClass, string $customerClass, array $validationGroups = []) - { + public function __construct( + string $dataClass, + string $customerClass, + array $validationGroups = [] + ) { parent::__construct($dataClass, $validationGroups); $this->customerClass = $customerClass; @@ -37,7 +40,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'class' => $this->customerClass, ]) ->add('company', TextType::class, [ - 'required' => false + 'required' => false, ]) ->add('firstName', TextType::class) ->add('lastName', TextType::class) @@ -45,23 +48,23 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('street', TextType::class) ->add('city', TextType::class) ->add('province', TextType::class, [ - 'required' => false + 'required' => false, ]) ->add('country', TextType::class) ->add('postcode', TextType::class) ->add('customerIp', TextType::class, [ - 'required' => false + 'required' => false, ]) ->add('addressType', ChoiceType::class, [ 'label' => 'bitbag_sylius_blacklist_plugin.ui.address_type', 'choices' => [ 'sylius.ui.shipping_address' => FraudSuspicionInterface::SHIPPING_ADDRESS_TYPE, - 'sylius.ui.billing_address' => FraudSuspicionInterface::BILLING_ADDRESS_TYPE - ] + 'sylius.ui.billing_address' => FraudSuspicionInterface::BILLING_ADDRESS_TYPE, + ], ]) ->add('comment', TextareaType::class, [ 'label' => 'bitbag_sylius_blacklist_plugin.form.fraud_suspicion.comment', - 'required' => false + 'required' => false, ]) ; } diff --git a/src/Model/FraudSuspicionCommonModel.php b/src/Model/FraudSuspicionCommonModel.php index 8e3eed6..b68529d 100644 --- a/src/Model/FraudSuspicionCommonModel.php +++ b/src/Model/FraudSuspicionCommonModel.php @@ -10,8 +10,8 @@ namespace BitBag\SyliusBlacklistPlugin\Model; -use Sylius\Component\Order\Model\OrderInterface; use Sylius\Component\Customer\Model\CustomerInterface; +use Sylius\Component\Order\Model\OrderInterface; class FraudSuspicionCommonModel implements FraudSuspicionCommonModelInterface { diff --git a/src/Model/FraudSuspicionCommonModelInterface.php b/src/Model/FraudSuspicionCommonModelInterface.php index c47f89d..c6588f7 100644 --- a/src/Model/FraudSuspicionCommonModelInterface.php +++ b/src/Model/FraudSuspicionCommonModelInterface.php @@ -10,8 +10,8 @@ namespace BitBag\SyliusBlacklistPlugin\Model; -use Sylius\Component\Order\Model\OrderInterface; use Sylius\Component\Customer\Model\CustomerInterface; +use Sylius\Component\Order\Model\OrderInterface; interface FraudSuspicionCommonModelInterface { diff --git a/src/Processor/AutomaticBlacklistingRulesProcessor.php b/src/Processor/AutomaticBlacklistingRulesProcessor.php index ad614b9..045e910 100644 --- a/src/Processor/AutomaticBlacklistingRulesProcessor.php +++ b/src/Processor/AutomaticBlacklistingRulesProcessor.php @@ -18,7 +18,6 @@ use BitBag\SyliusBlacklistPlugin\Repository\FraudSuspicionRepositoryInterface; use BitBag\SyliusBlacklistPlugin\Repository\OrderRepositoryInterface; use BitBag\SyliusBlacklistPlugin\StateResolver\CustomerStateResolverInterface; -use Doctrine\Persistence\ObjectManager; use Sylius\Component\Order\Model\OrderInterface; use Sylius\Component\Registry\ServiceRegistryInterface; @@ -69,14 +68,13 @@ public function process(OrderInterface $order): bool $allAutomaticBlacklistingConfiguration = $this->automaticBlacklistingConfigurationRepository->findActiveByChannel($channel); - if (\count($allAutomaticBlacklistingConfiguration) === 0) { + if (0 === \count($allAutomaticBlacklistingConfiguration)) { return false; } /** @var AutomaticBlacklistingConfigurationInterface $automaticBlacklistingConfiguration */ foreach ($allAutomaticBlacklistingConfiguration as $automaticBlacklistingConfiguration) { if ($this->shouldOrderBeBlocked($automaticBlacklistingConfiguration, $order)) { - return true; } } diff --git a/src/Repository/FraudSuspicionRepository.php b/src/Repository/FraudSuspicionRepository.php index 31e6a40..6db5010 100644 --- a/src/Repository/FraudSuspicionRepository.php +++ b/src/Repository/FraudSuspicionRepository.php @@ -26,7 +26,6 @@ public function __construct(EntityRepository $decoratedRepository) $this->decoratedRepository = $decoratedRepository; } - public function createListQueryBuilder(): QueryBuilder { return $this->decoratedRepository->createQueryBuilder('o') @@ -70,8 +69,11 @@ public function findOneByOrderNumber(string $orderNumber): ?FraudSuspicionInterf ; } - public function countByCustomerAndCommentAndDate(CustomerInterface $customer, string $status, \DateTime $date): string - { + public function countByCustomerAndCommentAndDate( + CustomerInterface $customer, + string $status, + \DateTime $date + ): string { return $this->decoratedRepository->createQueryBuilder('o') ->select(['COUNT(o.id)']) ->innerJoin('o.customer', 'customer') @@ -96,8 +98,12 @@ public function findAll() return $this->decoratedRepository->findAll(); } - public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null) - { + public function findBy( + array $criteria, + ?array $orderBy = null, + $limit = null, + $offset = null + ) { return $this->decoratedRepository->findBy($criteria, $orderBy, $limit, $offset); } diff --git a/src/Repository/FraudSuspicionRepositoryInterface.php b/src/Repository/FraudSuspicionRepositoryInterface.php index 14b9e70..a481004 100644 --- a/src/Repository/FraudSuspicionRepositoryInterface.php +++ b/src/Repository/FraudSuspicionRepositoryInterface.php @@ -26,5 +26,9 @@ public function findOneByOrder(OrderInterface $order): ?FraudSuspicionInterface; public function findOneByOrderNumber(string $orderNumber): ?FraudSuspicionInterface; - public function countByCustomerAndCommentAndDate(CustomerInterface $customer, string $comment, \DateTime $date): string; + public function countByCustomerAndCommentAndDate( + CustomerInterface $customer, + string $comment, + \DateTime $date + ): string; } diff --git a/src/Repository/OrderRepository.php b/src/Repository/OrderRepository.php index 2e926d6..8872e32 100644 --- a/src/Repository/OrderRepository.php +++ b/src/Repository/OrderRepository.php @@ -12,9 +12,9 @@ use Doctrine\ORM\EntityRepository; use Sylius\Component\Core\Model\OrderInterface; -use Sylius\Component\Payment\Model\PaymentInterface; -use Sylius\Component\Customer\Model\CustomerInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface as BaseOrderRepositoryInterface; +use Sylius\Component\Customer\Model\CustomerInterface; +use Sylius\Component\Payment\Model\PaymentInterface; final class OrderRepository implements OrderRepositoryInterface { diff --git a/src/Repository/OrderRepositoryInterface.php b/src/Repository/OrderRepositoryInterface.php index 35cb9cf..fee7733 100644 --- a/src/Repository/OrderRepositoryInterface.php +++ b/src/Repository/OrderRepositoryInterface.php @@ -10,7 +10,6 @@ namespace BitBag\SyliusBlacklistPlugin\Repository; -use Sylius\Component\Core\Repository\OrderRepositoryInterface as BaseOrderRepositoryInterface; use Sylius\Component\Customer\Model\CustomerInterface; interface OrderRepositoryInterface diff --git a/src/Resolver/SuspiciousOrderResolver.php b/src/Resolver/SuspiciousOrderResolver.php index ce61926..12bb484 100644 --- a/src/Resolver/SuspiciousOrderResolver.php +++ b/src/Resolver/SuspiciousOrderResolver.php @@ -61,7 +61,7 @@ public function resolve(FraudSuspicionCommonModelInterface $fraudSuspicionCommon { $blacklistingRules = $this->blacklistingRuleRepository->findActiveByChannel($this->getChannel()); - if (\count($blacklistingRules) === 0) { + if (0 === \count($blacklistingRules)) { return false; } @@ -79,7 +79,7 @@ public function resolve(FraudSuspicionCommonModelInterface $fraudSuspicionCommon $this->checkIfCustomerIsBlacklisted($builder, $fraudSuspicionCommonModel, $attribute); } - if (\intval($builder->getQuery()->getSingleScalarResult()) >= $blacklistingRule->getPermittedStrikes()) { + if ((int) ($builder->getQuery()->getSingleScalarResult()) >= $blacklistingRule->getPermittedStrikes()) { return true; } } diff --git a/src/Validator/Constraints/AutomaticBlacklistingConfiguration/AddFraudSuspicionWithSettingsValidator.php b/src/Validator/Constraints/AutomaticBlacklistingConfiguration/AddFraudSuspicionWithSettingsValidator.php index 9e53f5a..eea3dd1 100644 --- a/src/Validator/Constraints/AutomaticBlacklistingConfiguration/AddFraudSuspicionWithSettingsValidator.php +++ b/src/Validator/Constraints/AutomaticBlacklistingConfiguration/AddFraudSuspicionWithSettingsValidator.php @@ -8,7 +8,6 @@ declare(strict_types=1); - namespace BitBag\SyliusBlacklistPlugin\Validator\Constraints\AutomaticBlacklistingConfiguration; use BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention\AutomaticBlacklistingConfigurationInterface; diff --git a/src/Validator/Constraints/BlacklistingRule/BlacklistingRuleCustomerGroupsValidator.php b/src/Validator/Constraints/BlacklistingRule/BlacklistingRuleCustomerGroupsValidator.php index 2c7e314..9f56c96 100644 --- a/src/Validator/Constraints/BlacklistingRule/BlacklistingRuleCustomerGroupsValidator.php +++ b/src/Validator/Constraints/BlacklistingRule/BlacklistingRuleCustomerGroupsValidator.php @@ -7,6 +7,7 @@ */ declare(strict_types=1); + namespace BitBag\SyliusBlacklistPlugin\Validator\Constraints\BlacklistingRule; use BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention\BlacklistingRuleInterface; diff --git a/src/Validator/Constraints/Checkout/CheckoutAddressType.php b/src/Validator/Constraints/Checkout/CheckoutAddressType.php index f19d0ad..c08c104 100644 --- a/src/Validator/Constraints/Checkout/CheckoutAddressType.php +++ b/src/Validator/Constraints/Checkout/CheckoutAddressType.php @@ -7,6 +7,7 @@ */ declare(strict_types=1); + namespace BitBag\SyliusBlacklistPlugin\Validator\Constraints\Checkout; use Symfony\Component\Validator\Constraint; diff --git a/src/Validator/Constraints/Checkout/CheckoutAddressTypeValidator.php b/src/Validator/Constraints/Checkout/CheckoutAddressTypeValidator.php index 23bdd34..e3f5578 100644 --- a/src/Validator/Constraints/Checkout/CheckoutAddressTypeValidator.php +++ b/src/Validator/Constraints/Checkout/CheckoutAddressTypeValidator.php @@ -7,6 +7,7 @@ */ declare(strict_types=1); + namespace BitBag\SyliusBlacklistPlugin\Validator\Constraints\Checkout; use BitBag\SyliusBlacklistPlugin\Converter\FraudSuspicionCommonModelConverterInterface; @@ -14,10 +15,10 @@ use BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention\FraudSuspicionInterface; use BitBag\SyliusBlacklistPlugin\Processor\AutomaticBlacklistingRulesProcessorInterface; use BitBag\SyliusBlacklistPlugin\Resolver\SuspiciousOrderResolverInterface; +use Sylius\Component\Customer\Model\CustomerInterface; use Sylius\Component\Order\Model\OrderInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; -use Sylius\Component\Customer\Model\CustomerInterface; use Webmozart\Assert\Assert; class CheckoutAddressTypeValidator extends ConstraintValidator @@ -43,23 +44,24 @@ public function __construct( public function validate($order, Constraint $constraint): void { - /** @var OrderInterface $order */ Assert::isInstanceOf($order, OrderInterface::class); /** @var CustomerInterface $customer */ $customer = $order->getCustomer(); - if ($customer->getFraudStatus() === FraudStatusInterface::FRAUD_STATUS_WHITELISTED) { + if (FraudStatusInterface::FRAUD_STATUS_WHITELISTED === $customer->getFraudStatus()) { return; } - if ($customer->getFraudStatus() === FraudStatusInterface::FRAUD_STATUS_BLACKLISTED) { + if (FraudStatusInterface::FRAUD_STATUS_BLACKLISTED === $customer->getFraudStatus()) { $this->buildViolation($constraint); + return; } if ($this->automaticBlacklistingRulesProcessor->process($order)) { $this->buildViolation($constraint); + return; } @@ -71,6 +73,7 @@ public function validate($order, Constraint $constraint): void $this->suspiciousOrderResolver->resolve($fraudSuspicionCommonModelWithShippingAddressType) ) { $this->buildViolation($constraint); + return; } }