Skip to content

Commit b2323e0

Browse files
authored
Merge pull request #69 from SzymonKostrubiec/op-266
OP-266 - Sylius 1.13 support
2 parents 0853cf3 + 0a0b5fc commit b2323e0

34 files changed

+193
-154
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,20 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
php: [8.0 ]
25-
symfony: [^5.4, ^6.0]
26-
sylius: [~1.11.0, ~1.12.0]
27-
node: [14.19]
28-
mysql: [5.7, 8.0]
24+
php: ["8.1", "8.2", "8.3"]
25+
symfony: ["^5.4", "^6.0"]
26+
sylius: ["~1.12.0", "~1.13.0"]
27+
node: ["18.x", "20.x"]
28+
mysql: ["5.7", "8.0"]
2929

30-
exclude:
31-
-
32-
sylius: ~1.11.0
33-
symfony: ^6.0
3430

3531
env:
3632
APP_ENV: test
3733
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}"
3834

3935
steps:
4036
-
41-
uses: actions/checkout@v2
37+
uses: actions/checkout@v3
4238

4339
-
4440
name: Setup PHP
@@ -51,7 +47,7 @@ jobs:
5147

5248
-
5349
name: Setup Node
54-
uses: actions/setup-node@v1
50+
uses: actions/setup-node@v4
5551
with:
5652
node-version: "${{ matrix.node }}"
5753

@@ -89,7 +85,7 @@ jobs:
8985

9086
-
9187
name: Cache Composer
92-
uses: actions/cache@v2
88+
uses: actions/cache@v4
9389
with:
9490
path: ${{ steps.composer-cache.outputs.dir }}
9591
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
@@ -114,7 +110,7 @@ jobs:
114110
-
115111
name: Get Yarn cache directory
116112
id: yarn-cache
117-
run: echo "::set-output name=dir::$(yarn cache dir)"
113+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
118114

119115
-
120116
name: Cache Yarn
@@ -154,6 +150,10 @@ jobs:
154150
name: Validate database schema
155151
run: (cd tests/Application && bin/console doctrine:schema:validate)
156152

153+
-
154+
name: Run ECS
155+
run: vendor/bin/ecs check src
156+
157157
-
158158
name: Run PHPStan
159159
run: vendor/bin/phpstan analyse -c phpstan.neon -l 7 src/
@@ -166,20 +166,20 @@ jobs:
166166
-
167167
name: Run Behat
168168
env:
169-
MAIL_CHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_TOKEN }}
170-
MAIL_CHIMP_LIST_ID: ${{ secrets.MAIL_CHIMP_LIST_ID }}
169+
MAIL_CHIMP_API_KEY: "mailchimp-api-key"
170+
MAIL_CHIMP_LIST_ID: "mailchimp-list-id"
171171
MAIL_CHIMP_WEBHOOK_SECRET: ${{ secrets.MAIL_CHIMP_WEBHOOK_SECRET }}
172172
run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun
173173

174174
-
175175
name: Upload Behat logs
176-
uses: actions/upload-artifact@v2
176+
uses: actions/upload-artifact@v3
177177
if: failure()
178178
with:
179179
name: Behat logs
180180
path: etc/build/
181181
if-no-files-found: ignore
182-
182+
183183
-
184184
name: Failed build Slack notification
185185
uses: rtCamp/action-slack-notify@v2

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"description": "MailChimp plugin for Sylius.",
66
"license": "MIT",
77
"require": {
8-
"php": " ^8.0",
9-
"sylius/sylius": "~1.11.0 || ~1.12.0",
10-
"drewm/mailchimp-api": "^v2.5.4",
8+
"php": " ^8.1",
9+
"sylius/sylius": "~1.12.0 || ~1.13.0",
10+
"drewm/mailchimp-api": "^2.5.4",
1111
"ext-json": "*",
1212
"symfony/webpack-encore-bundle": "^1.16"
1313
},
1414
"require-dev": {
15-
"behat/behat": "^3.6.1",
16-
"behat/mink-selenium2-driver": "^1.4",
15+
"behat/behat": "^3.7",
16+
"behat/mink-selenium2-driver": "~1.6.0",
1717
"dmore/behat-chrome-extension": "^1.3",
1818
"dmore/chrome-mink-driver": "^2.7",
1919
"friends-of-behat/mink": "^1.8",
@@ -39,8 +39,8 @@
3939
"bitbag/coding-standard": "^1.0.0 || ^2.0.0"
4040
},
4141
"conflict": {
42-
"doctrine/orm": ">=2.15.2"
43-
},
42+
"doctrine/orm": ">=2.15.2"
43+
},
4444
"prefer-stable": true,
4545
"autoload": {
4646
"psr-4": {

doc/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Add these javascripts to the layout template that includes your subscription for
105105

106106
Clear project cache:
107107
```php
108-
bin/console cache:clear
108+
bin/console cache:clear # if there is an issue with translations displaying correctly, clear the cache again.
109109
```
110110

111111
Update your webpack build:

ecs.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
declare(strict_types=1);
44

5-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
5+
use Symplify\EasyCodingStandard\Config\ECSConfig;
66

7-
return static function (ContainerConfigurator $containerConfigurator): void {
8-
$containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php');
7+
return static function (ECSConfig $config): void {
8+
9+
putenv('ALLOW_BITBAG_OS_HEADER=1');
10+
11+
$config->import('vendor/bitbag/coding-standard/ecs.php');
12+
$config->paths(['src', 'tests']);
913
};

src/Controller/MailchimpController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ final class MailchimpController
3131
public function __construct(
3232
WebhookValidator $validator,
3333
NewsletterSubscriptionInterface $handler,
34-
TranslatorInterface $translator
35-
) {
34+
TranslatorInterface $translator,
35+
) {
3636
$this->validator = $validator;
3737
$this->handler = $handler;
3838
$this->translator = $translator;
@@ -43,7 +43,7 @@ public function webhookAction(Request $request): JsonResponse
4343
$webhookData = WebhookData::createFromRequest($request);
4444
$errors = $this->validateRequest($webhookData, $request);
4545

46-
if (count($errors) === 0) {
46+
if (0 === count($errors)) {
4747
$this->handler->unsubscribeCustomerFromLocalDatabase($webhookData->getData()['email']);
4848

4949
return new JsonResponse([

src/Controller/NewsletterController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function __construct(
3838
NewsletterValidator $validator,
3939
TranslatorInterface $translator,
4040
NewsletterSubscriptionInterface $handler,
41-
CsrfTokenManager $tokenManager
42-
) {
41+
CsrfTokenManager $tokenManager,
42+
) {
4343
$this->validator = $validator;
4444
$this->translator = $translator;
4545
$this->handler = $handler;
@@ -65,7 +65,7 @@ public function subscribeAction(Request $request): JsonResponse
6565
$errors[] = $this->translator->trans('bitbag_sylius_mailchimp_plugin.ui.invalid_csrf_token');
6666
}
6767

68-
if (count($errors) === 0) {
68+
if (0 === count($errors)) {
6969
$this->handler->subscribe($email);
7070

7171
return new JsonResponse([

src/EventListener/CustomerNewsletterListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public function customerCreateEvent(GenericEvent $event): void
3939
if (!$customer instanceof CustomerInterface) {
4040
throw new UnexpectedTypeException(
4141
$customer,
42-
CustomerInterface::class
42+
CustomerInterface::class,
4343
);
4444
}
4545

46-
$customer->isSubscribedToNewsletter() === false ? $this->unsubscribe($customer) : $this->subscribe($customer);
46+
false === $customer->isSubscribedToNewsletter() ? $this->unsubscribe($customer) : $this->subscribe($customer);
4747
}
4848

4949
public function customerPostUpdateEvent(GenericEvent $event): void
@@ -62,7 +62,7 @@ public function customerPreUpdateEvent(GenericEvent $event): void
6262
if (!$customer instanceof CustomerInterface) {
6363
throw new UnexpectedTypeException(
6464
$customer,
65-
CustomerInterface::class
65+
CustomerInterface::class,
6666
);
6767
}
6868

src/Handler/NewsletterSubscriptionHandler.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public function __construct(
4646
FactoryInterface $customerFactory,
4747
EntityManagerInterface $customerManager,
4848
MailChimp $mailChimp,
49-
string $listId
50-
) {
49+
string $listId,
50+
) {
5151
$this->customerRepository = $customerRepository;
5252
$this->customerFactory = $customerFactory;
5353
$this->customerManager = $customerManager;
@@ -128,14 +128,14 @@ private function exportNewEmail(string $email): void
128128
throw new BadRequestHttpException(
129129
sprintf(
130130
'Mailchimp returned false instead of response array, last error : %s',
131-
$this->mailChimp->getLastError()
132-
)
131+
$this->mailChimp->getLastError(),
132+
),
133133
);
134134
}
135135

136136
Assert::keyExists($response, 'status');
137137

138-
if ($response['status'] === Response::HTTP_NOT_FOUND) {
138+
if (Response::HTTP_NOT_FOUND === $response['status']) {
139139
$validListIds = $this->getValidMailchimpListIds();
140140
$concatenatedList = implode(',', $validListIds);
141141

@@ -144,13 +144,13 @@ private function exportNewEmail(string $email): void
144144
'Mailchimp returned %1$d code, is the MAIL_CHIMP_LIST_ID [ %2$s ] one of available ones: [ %3$s ] ?',
145145
Response::HTTP_NOT_FOUND,
146146
$this->listId,
147-
$concatenatedList
148-
)
147+
$concatenatedList,
148+
),
149149
);
150150
}
151-
if ($response['status'] !== 'subscribed') {
151+
if ('subscribed' !== $response['status']) {
152152
throw new BadRequestHttpException(
153-
sprintf('Response status is %s instead of %s', $response['status'], 'subscribed')
153+
sprintf('Response status is %s instead of %s', $response['status'], 'subscribed'),
154154
);
155155
}
156156
}
@@ -174,8 +174,8 @@ protected function addMailchimpData(string $email): void
174174
throw new BadRequestHttpException(
175175
sprintf(
176176
'Mailchimp returned false instead of response array, last error : %s',
177-
$this->mailChimp->getLastError()
178-
)
177+
$this->mailChimp->getLastError(),
178+
),
179179
);
180180
}
181181

src/Model/WebhookData.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ final class WebhookData
4141
public function __construct(
4242
string $type,
4343
string $firedAt,
44-
array $data
45-
) {
44+
array $data,
45+
) {
4646
$this->type = $type;
4747
$this->firedAt = $firedAt;
4848
$this->data = $data;
@@ -55,7 +55,7 @@ public static function createFromRequest(Request $request): self
5555
return new self(
5656
$request->get('type', self::TYPE_UNSUBSCRIBE),
5757
$request->get('fired_at', $dateString),
58-
$request->get('data', [])
58+
$request->get('data', []),
5959
);
6060
}
6161

src/Validator/Constraints/UniqueNewsletterEmailValidator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function validate($value, Constraint $constraint): void
3434
{
3535
Assert::isInstanceOf($constraint, UniqueNewsletterEmail::class);
3636

37-
if ($this->isEmailValid($value) === false) {
37+
if (false === $this->isEmailValid($value)) {
3838
$this->context->addViolation($constraint->message);
3939
}
4040
}
@@ -43,11 +43,11 @@ private function isEmailValid(?string $email): bool
4343
{
4444
$customer = $this->customerRepository->findOneBy(['email' => $email]);
4545

46-
if ($customer instanceof CustomerInterface === false) {
46+
if (false === $customer instanceof CustomerInterface) {
4747
return true;
4848
}
4949

50-
if ($customer->isSubscribedToNewsletter() === true) {
50+
if (true === $customer->isSubscribedToNewsletter()) {
5151
return false;
5252
}
5353

0 commit comments

Comments
 (0)