Skip to content

Commit

Permalink
OP-263 Add ecs and phpStan + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Kostrubiec committed Apr 12, 2024
1 parent 47a792e commit d638475
Show file tree
Hide file tree
Showing 27 changed files with 750 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@
# Symfony CLI https://symfony.com/doc/current/setup/symfony_server.html#different-php-settings-per-project
/.php-version
/php.ini

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

262 changes: 262 additions & 0 deletions .idea/SyliusImojePaywallPlugin.iml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions .idea/codeception.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/php-test-framework.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

303 changes: 303 additions & 0 deletions .idea/php.xml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions .idea/phpspec.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/phpunit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude('var')
;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
])
->setFinder($finder)
;
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"require-dev": {
"behat/behat": "^3.6.1",
"behat/mink-selenium2-driver": "^1.4",
"bitbag/coding-standard": "^3.0",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
Expand All @@ -28,7 +29,7 @@
"friends-of-behat/variadic-extension": "^1.3",
"phpspec/phpspec": "^7.5",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.8.1",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "1.3.40",
"phpstan/phpstan-strict-rules": "^1.3.0",
"phpstan/phpstan-webmozart-assert": "^1.2.0",
Expand Down
2 changes: 2 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
__DIR__ . '/ecs.php',
]);

putenv('ALLOW_BITBAG_OS_HEADER=0');

$ecsConfig->import('vendor/sylius-labs/coding-standard/ecs.php');

$ecsConfig->skip([
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
level: max
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
- src
- tests/Behat
Expand Down
14 changes: 7 additions & 7 deletions src/Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(private readonly SignatureResolverInterface $signatu
$this->apiClass = ImojeApi::class;
}

public function execute($request)
public function execute($request): void
{
RequestNotSupportedException::assertSupports($this, $request);
$model = $request->getModel();
Expand All @@ -50,15 +50,15 @@ public function execute($request)

throw new HttpPostRedirect(
$this->api->getApiUrl(),
$orderData
$orderData,
);
}

public function supports($request): bool
{
return
$request instanceof Capture
&& $request->getModel() instanceof ArrayObject;
$request instanceof Capture &&
$request->getModel() instanceof ArrayObject;
}

private function prepareOrderData(OrderInterface $order, PaymentSecurityTokenInterface $token): array
Expand All @@ -73,10 +73,10 @@ private function prepareOrderData(OrderInterface $order, PaymentSecurityTokenInt
$orderData['amount'] = $order->getTotal();
$orderData['currency'] = $order->getCurrencyCode();
$orderData['orderId'] = $order->getNumber();
$orderData['customerFirstName'] = $billingAddress->getFirstName();
$orderData['customerLastName'] = $billingAddress->getLastName();
$orderData['customerFirstName'] = $billingAddress?->getFirstName();
$orderData['customerLastName'] = $billingAddress?->getLastName();
$orderData['urlReturn'] = $token->getAfterUrl();
$orderData['customerEmail'] = $customer->getEmail();
$orderData['customerEmail'] = $customer?->getEmail();
$orderData['signature'] = $this->signatureResolver->createSignature($orderData, $this->api->getServiceKey());

return $orderData;
Expand Down
2 changes: 1 addition & 1 deletion src/Action/ConvertPaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function execute($request): void
$request->setResult((array) $details);
}

public function supports($request)
public function supports($request): bool
{
return
$request instanceof Convert &&
Expand Down
10 changes: 5 additions & 5 deletions src/Action/NotifyAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ final class NotifyAction implements ActionInterface, ApiAwareInterface
private Request $request;

public function __construct(
private readonly RequestStack $requestStack,
protected RequestStack $requestStack,
private readonly SignatureResolverInterface $signatureResolver,
) {
$this->request = $requestStack->getCurrentRequest();
$this->request = $requestStack->getCurrentRequest() ?? new Request();
$this->apiClass = ImojeApi::class;
}

Expand All @@ -45,8 +45,8 @@ public function execute($request): void
public function supports($request): bool
{
return
$request instanceof Notify
&& $request->getModel() instanceof ArrayObject
&& $this->signatureResolver->verifySignature($this->request, $this->api->getServiceKey());
$request instanceof Notify &&
$request->getModel() instanceof ArrayObject &&
$this->signatureResolver->verifySignature($this->request, $this->api->getServiceKey());
}
}
2 changes: 1 addition & 1 deletion src/Action/StatusAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public function supports($request): bool
{
return $request instanceof GetStatusInterface &&
$request->getModel() instanceof ArrayAccess
;
;
}
}
3 changes: 2 additions & 1 deletion src/Api/ImojeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public function __construct(
private readonly string $serviceId,
private readonly string $serviceKey,
private readonly string $authorizationToken,
) {}
) {
}

public function getApiUrl(): string
{
Expand Down
9 changes: 8 additions & 1 deletion src/Api/ImojeApiInterface.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<?php

declare(strict_types=1);

namespace BitBag\SyliusImojePlugin\Api;

interface ImojeApiInterface
{
public const SANDBOX_ENVIRONMENT = 'sandbox';

public const PRODUCTION_ENVIRONMENT = 'production';

public const SANDBOX_PAYWALL_URL = 'https://sandbox.paywall.imoje.pl/payment';

public const PRODUCTION_PAYWALL_URL = 'https://paywall.imoje.pl/payment';

public const NEW_STATUS = 'new';

public const PENDING_STATUS = 'pending';

public const SETTLED_STATUS = 'settled';

public const REJECTED_STATUS = 'rejected';

public const CANCELLED_STATUS = 'cancelled';

public const HASHING_ALGORITHM = 'sha256';
Expand All @@ -27,5 +35,4 @@ public function getServiceId(): string;
public function getServiceKey(): string;

public function getAuthorizationToken(): string;

}
15 changes: 9 additions & 6 deletions src/Controller/NotifyController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace BitBag\SyliusImojePlugin\Controller;

use BitBag\SyliusImojePlugin\Provider\PaymentTokenProviderInterface;
Expand All @@ -16,7 +18,8 @@ final class NotifyController
public function __construct(
private readonly Payum $payum,
private readonly PaymentTokenProviderInterface $paymentTokenProvider,
) {}
) {
}

public function verifyImojeNotification(Request $request): Response
{
Expand All @@ -33,14 +36,14 @@ public function verifyImojeNotification(Request $request): Response
$gateway->execute(new Notify($notifyToken));

return new JsonResponse(['status' => 'ok']);
} else {
throw new NotFoundHttpException('Payment token not found');
}

throw new NotFoundHttpException('Payment token not found');
}

private function createRequestWithToken(
Request $request,
PaymentSecurityTokenInterface $token
PaymentSecurityTokenInterface $token,
): Request {
$request = Request::create(
$token->getTargetUrl(),
Expand All @@ -49,11 +52,11 @@ private function createRequestWithToken(
$request->cookies->all(),
$request->files->all(),
$request->server->all(),
$request->getContent()
$request->getContent(),
);

$request->attributes->add([
'payum_token' => $token->getHash()
'payum_token' => $token->getHash(),
]);

return $request;
Expand Down
Loading

0 comments on commit d638475

Please sign in to comment.