Skip to content

Commit

Permalink
Merge pull request #62 from BitBagCommerce/OPSRC-496/Add_bitbag_codin…
Browse files Browse the repository at this point in the history
…g_standard_to_every_plugin

OPSRC-496/Add bitbag coding standard and ecs fix
  • Loading branch information
fabulousPuppet authored Jul 29, 2022
2 parents 84044c4 + 852db80 commit 0fc0a54
Show file tree
Hide file tree
Showing 32 changed files with 96 additions and 69 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
10 changes: 5 additions & 5 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
use SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff;
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');
$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',
]);
};
1 change: 1 addition & 0 deletions src/BitBagSyliusBlacklistPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

declare(strict_types=1);

namespace BitBag\SyliusBlacklistPlugin;

use BitBag\SyliusBlacklistPlugin\DependencyInjection\Compiler\RegisterAutomaticBlacklistingRuleCheckersPass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function canAddFraudSuspicion(
$date
);

if (intval($lastFraudSuspicionsOfCustomer) >= $automaticBlacklistingConfiguration->getPermittedFraudSuspicionsNumber()) {
if ((int) $lastFraudSuspicionsOfCustomer >= $automaticBlacklistingConfiguration->getPermittedFraudSuspicionsNumber()) {
$this->customerStateResolver->changeStateOnBlacklisted($customer);

return false;
Expand Down
2 changes: 2 additions & 0 deletions src/Entity/Customer/FraudStatusInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace BitBag\SyliusBlacklistPlugin\Entity\Customer;

interface FraudStatusInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class AutomaticBlacklistingConfiguration implements AutomaticBlacklistingConfigurationInterface
{
use ToggleableTrait;

use TimestampableTrait;

/** @var int|null */
Expand Down
5 changes: 3 additions & 2 deletions src/Entity/FraudPrevention/BlacklistingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class BlacklistingRule implements BlacklistingRuleInterface
{
use ToggleableTrait;

use TimestampableTrait;

/** @var int|null */
Expand Down Expand Up @@ -89,7 +90,7 @@ public function removeAttribute(string $attribute): void
{
$index = array_search($attribute, $this->attributes);

if ($index !== false) {
if (false !== $index) {
unset($this->attributes[$index]);
}
}
Expand Down Expand Up @@ -149,7 +150,7 @@ public function removeCustomerGroup(CustomerGroupInterface $customerGroup): void

public function hasCustomerGroup(?CustomerGroupInterface $customerGroup): bool
{
if ($customerGroup === null) {
if (null === $customerGroup) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Entity/FraudPrevention/FraudSuspicion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/FraudPrevention/FraudSuspicionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/EntityListener/FraudSuspicionEntityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use BitBag\SyliusBlacklistPlugin\StateResolver\CustomerStateResolverInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;

final class FraudSuspicionEntityListener
class FraudSuspicionEntityListener
{
/** @var SuspiciousOrderResolverInterface */
private $suspiciousOrderResolver;
Expand Down Expand Up @@ -45,5 +45,4 @@ public function prePersist(FraudSuspicionInterface $newFraudSuspicion, Lifecycle
$this->customerStateResolver->changeStateOnBlacklisted($newFraudSuspicion->getCustomer());
}
}

}
1 change: 0 additions & 1 deletion src/Factory/FraudSuspicionCommonModelFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ interface FraudSuspicionCommonModelFactoryInterface extends FactoryInterface
{
public function createNew(): FraudSuspicionCommonModelInterface;
}

1 change: 0 additions & 1 deletion src/Factory/FraudSuspicionFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ public function createForOrder(OrderInterface $order): FraudSuspicionInterface;

public function createForAutomaticBlacklistingConfiguration(OrderInterface $order): FraudSuspicionInterface;
}

2 changes: 1 addition & 1 deletion src/Form/Rule/AutomaticBlacklistingRuleSettingsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;'],
])
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions src/Form/Type/AutomaticBlacklistingConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand All @@ -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',
Expand Down
8 changes: 3 additions & 5 deletions src/Form/Type/BlacklistingRuleType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
13 changes: 8 additions & 5 deletions src/Form/Type/FraudSuspicionOrderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
19 changes: 11 additions & 8 deletions src/Form/Type/FraudSuspicionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,31 +40,31 @@ 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)
->add('email', TextType::class)
->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,
])
;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/FraudSuspicionCommonModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Model/FraudSuspicionCommonModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading

0 comments on commit 0fc0a54

Please sign in to comment.