Skip to content

Commit

Permalink
Merge pull request #5 from PAYONE-GmbH/refactor/initial-sonarcloud-an…
Browse files Browse the repository at this point in the history
…alysis

Refactor/initial sonarcloud analysis
  • Loading branch information
lrosenfeldt authored Jul 30, 2024
2 parents 7ac1e5e + b52d76d commit e1d3712
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 61 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" bootstrap="tests/bootstrap.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd">
<testsuites>
<testsuite name="PAYONE Commerce Platform Sdk testsuite">
<directory>tests/PayoneCommercePlatform/Sdk</directory>
Expand Down
3 changes: 0 additions & 3 deletions src/PayoneCommercePlatform/Sdk/ApiClient/BaseApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public function __construct(
CommunicatorConfiguration $config,
ClientInterface $client = null,
) {
$normalizers = [new GetSetMethodNormalizer(), new DateTimeNormalizer()];
$encoders = [new JsonEncoder()];

$this->config = $config;
$this->client = $client ?: new Client();
$this->requestHeaderGenerator = new RequestHeaderGenerator($this->config);
Expand Down
18 changes: 8 additions & 10 deletions src/PayoneCommercePlatform/Sdk/ApiClient/CheckoutApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

class CheckoutApiClient extends BaseApiClient
{
protected const CHECKOUT_BY_ID_URI = '/v1/{merchantId}/commerce-cases/{commerceCaseId}/checkouts/{checkoutId}';

/**
* Operation createCheckout
*
Expand All @@ -30,8 +32,7 @@ public function createCheckout(string $merchantId, string $commerceCaseId, Creat
{
$request = $this->createCheckoutRequest($merchantId, $commerceCaseId, $createCheckoutRequest);

list($response) = $this->makeApiCall($request, CreateCheckoutResponse::class);
return $response;
return $this->makeApiCall($request, CreateCheckoutResponse::class)[0];
}

/**
Expand Down Expand Up @@ -108,8 +109,7 @@ public function deleteCheckout(string $merchantId, string $commerceCaseId, strin
*/
protected function deleteCheckoutRequest(string $merchantId, string $commerceCaseId, string $checkoutId): Request
{
$resourcePath = '/v1/{merchantId}/commerce-cases/{commerceCaseId}/checkouts/{checkoutId}';
$contentType = 'application/json';
$resourcePath = self::CHECKOUT_BY_ID_URI;

// path params
$resourcePath = str_replace(
Expand Down Expand Up @@ -156,8 +156,7 @@ public function getCheckout(string $merchantId, string $commerceCaseId, string $
{
$request = $this->getCheckoutRequest($merchantId, $commerceCaseId, $checkoutId);

list($response) = $this->makeApiCall($request, CheckoutResponse::class);
return $response;
return $this->makeApiCall($request, CheckoutResponse::class)[0];
}

/**
Expand All @@ -172,7 +171,7 @@ public function getCheckout(string $merchantId, string $commerceCaseId, string $
protected function getCheckoutRequest(string $merchantId, string $commerceCaseId, string $checkoutId): Request
{

$resourcePath = '/v1/{merchantId}/commerce-cases/{commerceCaseId}/checkouts/{checkoutId}';
$resourcePath = self::CHECKOUT_BY_ID_URI;

$resourcePath = str_replace(
'{' . 'merchantId' . '}',
Expand Down Expand Up @@ -218,8 +217,7 @@ public function getCheckouts(
GetCheckoutsQuery $query = new GetCheckoutsQuery(),
): CheckoutsResponse {
$request = $this->getCheckoutsRequest($merchantId, $query);
list($response) = $this->makeApiCall($request, CheckoutsResponse::class);
return $response;
return $this->makeApiCall($request, CheckoutsResponse::class)[0];
}

/**
Expand Down Expand Up @@ -285,7 +283,7 @@ public function updateCheckout(string $merchantId, string $commerceCaseId, strin
*/
protected function updateCheckoutRequest(string $merchantId, string $commerceCaseId, string $checkoutId, PatchCheckoutRequest $patchCheckoutRequest): Request
{
$resourcePath = '/v1/{merchantId}/commerce-cases/{commerceCaseId}/checkouts/{checkoutId}';
$resourcePath = self::CHECKOUT_BY_ID_URI;
$httpBody = '';

// path params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class CommerceCaseApiClient extends BaseApiClient
public function createCommerceCase($merchantId, $createCommerceCaseRequest): CreateCommerceCaseResponse
{
$request = $this->createCommerceCaseRequest($merchantId, $createCommerceCaseRequest);
list($response) = $this->makeApiCall($request, CreateCommerceCaseResponse::class);
return $response;
return $this->makeApiCall($request, CreateCommerceCaseResponse::class)[0];
}

/**
Expand All @@ -44,7 +43,6 @@ protected function createCommerceCaseRequest(string $merchantId, CreateCommerceC
{
$resourcePath = '/v1/{merchantId}/commerce-cases';
$httpBody = '';
$multipart = false;

$resourcePath = str_replace(
'{' . 'merchantId' . '}',
Expand Down Expand Up @@ -80,8 +78,7 @@ protected function createCommerceCaseRequest(string $merchantId, CreateCommerceC
public function getCommerceCase(string $merchantId, string $commerceCaseId): CommerceCaseResponse
{
$request = $this->getCommerceCaseRequest($merchantId, $commerceCaseId);
list($response) = $this->makeApiCall($request, CommerceCaseResponse::class);
return $response;
return $this->makeApiCall($request, CommerceCaseResponse::class)[0];
}

/**
Expand Down Expand Up @@ -139,9 +136,7 @@ public function getCommerceCases(
// The underlying of `makeApiCall` is to strict as it has to be an resolvable class name
// but the underlying call to symfony/serialize also allows for an array of classes
// @phpstan-ignore-next-line
list($response) = $this->makeApiCall($request, CommerceCaseResponse::class . '[]');
/** @var \PayoneCommercePlatform\Sdk\Models\CommerceCaseResponse[] */
return $response;
return $this->makeApiCall($request, CommerceCaseResponse::class . '[]')[0];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class OrderManagementCheckoutActionsApiClient extends BaseApiClient
public function cancelOrder(string $merchantId, string $commerceCaseId, string $checkoutId, ?CancelRequest $cancelRequest = null): CancelResponse
{
$request = $this->cancelOrderRequest($merchantId, $commerceCaseId, $checkoutId, $cancelRequest);
list($response) = $this->makeApiCall($request, CancelResponse::class);
return $response;
return $this->makeApiCall($request, CancelResponse::class)[0];
}

/**
Expand Down Expand Up @@ -105,8 +104,7 @@ protected function cancelOrderRequest(
public function createOrder(string $merchantId, string $commerceCaseId, string $checkoutId, OrderRequest $orderRequest): OrderResponse
{
$request = $this->createOrderRequest($merchantId, $commerceCaseId, $checkoutId, $orderRequest);
list($response) = $this->makeApiCall($request, OrderResponse::class);
return $response;
return $this->makeApiCall($request, OrderResponse::class)[0];
}

/**
Expand Down Expand Up @@ -180,8 +178,7 @@ public function deliverOrder(
DeliverRequest $deliverRequest
): DeliverResponse {
$request = $this->deliverOrderRequest($merchantId, $commerceCaseId, $checkoutId, $deliverRequest);
list($response) = $this->makeApiCall($request, DeliverResponse::class);
return $response;
return $this->makeApiCall($request, DeliverResponse::class)[0];
}

/**
Expand Down Expand Up @@ -251,8 +248,7 @@ protected function deliverOrderRequest(
public function returnOrder(string $merchantId, string $commerceCaseId, string $checkoutId, ?ReturnRequest $returnRequest = null): ReturnResponse
{
$request = $this->returnOrderRequest($merchantId, $commerceCaseId, $checkoutId, $returnRequest);
list($response) = $this->makeApiCall($request, ReturnResponse::class);
return $response;
return $this->makeApiCall($request, ReturnResponse::class)[0];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function cancelPaymentExecution(
CancelPaymentRequest $cancelPaymentRequest
): CancelPaymentResponse {
$request = $this->cancelPaymentExecutionRequest($merchantId, $commerceCaseId, $checkoutId, $paymentExecutionId, $cancelPaymentRequest);
list($response) = $this->makeApiCall($request, CancelPaymentResponse::class);
return $response;
return $this->makeApiCall($request, CancelPaymentResponse::class)[0];
}

/**
Expand Down Expand Up @@ -123,8 +122,7 @@ public function capturePaymentExecution(
CapturePaymentRequest $capturePaymentRequest
): CapturePaymentResponse {
$request = $this->capturePaymentExecutionRequest($merchantId, $commerceCaseId, $checkoutId, $paymentExecutionId, $capturePaymentRequest);
list($response) = $this->makeApiCall($request, CapturePaymentResponse::class);
return $response;
return $this->makeApiCall($request, CapturePaymentResponse::class)[0];
}

/**
Expand Down Expand Up @@ -200,8 +198,7 @@ protected function capturePaymentExecutionRequest(
public function completePayment(string $merchantId, string $commerceCaseId, string $checkoutId, string $paymentExecutionId, CompletePaymentRequest $completePaymentRequest): CompletePaymentResponse
{
$request = $this->completePaymentRequest($merchantId, $commerceCaseId, $checkoutId, $paymentExecutionId, $completePaymentRequest);
list($response) = $this->makeApiCall($request, CompletePaymentResponse::class);
return $response;
return $this->makeApiCall($request, CompletePaymentResponse::class)[0];
}

/**
Expand Down Expand Up @@ -271,8 +268,7 @@ protected function completePaymentRequest(string $merchantId, string $commerceCa
public function createPayment(string $merchantId, string $commerceCaseId, string $checkoutId, PaymentExecutionRequest $paymentExecutionRequest): CreatePaymentResponse
{
$request = $this->createPaymentRequest($merchantId, $commerceCaseId, $checkoutId, $paymentExecutionRequest);
list($response) = $this->makeApiCall($request, CreatePaymentResponse::class);
return $response;
return $this->makeApiCall($request, CreatePaymentResponse::class)[0];
}

/**
Expand Down Expand Up @@ -338,8 +334,7 @@ protected function createPaymentRequest(string $merchantId, string $commerceCase
public function refundPaymentExecution(string $merchantId, string $commerceCaseId, string $checkoutId, string $paymentExecutionId, RefundRequest $refundRequest): RefundPaymentResponse
{
$request = $this->refundPaymentExecutionRequest($merchantId, $commerceCaseId, $checkoutId, $paymentExecutionId, $refundRequest);
list($response) = $this->makeApiCall($request, RefundPaymentResponse::class);
return $response;
return $this->makeApiCall($request, RefundPaymentResponse::class)[0];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PayoneCommercePlatform\Sdk\Models\CheckoutsResponse;
use PayoneCommercePlatform\Sdk\Models\CreateCheckoutRequest;
use PayoneCommercePlatform\Sdk\Models\CreateCheckoutResponse;
use PayoneCommercePlatform\Sdk\Models\ErrorResponse;
use PayoneCommercePlatform\Sdk\Errors\ApiErrorResponseException;
use PayoneCommercePlatform\Sdk\Errors\ApiResponseRetrievalException;
use PayoneCommercePlatform\Sdk\Models\PatchCheckoutRequest;
Expand Down Expand Up @@ -45,9 +44,6 @@ public function testCreateCheckout(): void
public function testCreateCheckoutUnsuccessful400(): void
{
// arrange
$createCheckoutResponse = new CreateCheckoutResponse(
amountOfMoney: new AmountOfMoney(400, 'EUR'),
);
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(status: 400, body: BaseApiClient::getSerializer()->serialize($errorResponse, 'json')));
$this->expectException(ApiErrorResponseException::class);
Expand All @@ -63,13 +59,13 @@ public function testCreateCheckoutUnsuccessful400(): void
public function testCreateCheckoutUnsuccessful500(): void
{
// arrange
$createCheckoutRequest = new CreateCheckoutRequest();
$this->httpClient->method('send')->willReturn(new Response(status: 500, body: 'invalid'));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);

// act
$response = $this->checkoutClient->createCheckout('1', '2', $createCheckoutRequest);
$createCheckoutRequest = new CreateCheckoutRequest();
$this->checkoutClient->createCheckout('1', '2', $createCheckoutRequest);
}

public function testGetCheckoutsSuccessful(): void
Expand Down Expand Up @@ -104,7 +100,7 @@ public function testGetCheckoutsUnsuccessful400(): void
$this->expectExceptionCode(400);

// act
$response = $this->checkoutClient->getCheckouts($this->merchantId);
$this->checkoutClient->getCheckouts($this->merchantId);
}

public function testGetCheckoutsUnsuccessful500(): void
Expand Down Expand Up @@ -140,7 +136,6 @@ public function testDeleteCheckoutUnsuccessful400(): void

public function testDeleteCheckoutUnsuccessful500(): void
{
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(status: 500, body: null));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);
Expand Down Expand Up @@ -175,7 +170,6 @@ public function testGetCheckoutUnsuccessful400(): void

public function testGetCheckoutUnsuccessful500(): void
{
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(status: 500, body: null));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);
Expand Down Expand Up @@ -208,7 +202,6 @@ public function testUpdateCheckoutUnsuccessful400(): void

public function testUpdateCheckoutUnsuccessful500(): void
{
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(status: 500, body: null));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public function testGetCommerceCaseUnsuccessful400(): void

public function testGetCommerceCaseUnsuccessful500(): void
{
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(status: 500, body: null));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);
Expand Down Expand Up @@ -192,7 +191,6 @@ public function testUpdateCommerceCaseUnsuccessful400(): void

public function testUpdateCommerceCaseUnsuccessful500(): void
{
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(status: 500, body: null));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public function testCreateOrderUnsuccessful400(): void

public function testCreateOrderUnsuccessful500(): void
{
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(status: 500, body: null));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);
Expand Down Expand Up @@ -146,18 +145,17 @@ public function testDeliverOrderUnsuccessful400(): void
$this->expectExceptionCode(400);

$payload = new DeliverRequest(deliverType: DeliverType::PARTIAL, isFinal: false);
$response = $this->orderManagementCheckoutActionsApiClient->deliverOrder('1', '2', '3', $payload);
$this->orderManagementCheckoutActionsApiClient->deliverOrder('1', '2', '3', $payload);
}

public function testDeliverOrderUnsuccessful500(): void
{
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(status: 500, body: null));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);

$payload = new DeliverRequest(deliverType: DeliverType::PARTIAL, isFinal: false);
$response = $this->orderManagementCheckoutActionsApiClient->deliverOrder('1', '2', '3', $payload);
$this->orderManagementCheckoutActionsApiClient->deliverOrder('1', '2', '3', $payload);
}

public function testReturnOrderSuccessful(): void
Expand Down Expand Up @@ -188,7 +186,6 @@ public function testReturnOrderUnsuccessful400(): void

public function testReturnOrderUnsuccessful500(): void
{
$errorResponse = $this->makeErrorResponse();
$this->httpClient->method('send')->willReturn(new Response(status: 500, body: null));
$this->expectException(ApiResponseRetrievalException::class);
$this->expectExceptionCode(500);
Expand Down
4 changes: 0 additions & 4 deletions tests/bootstrap.php

This file was deleted.

0 comments on commit e1d3712

Please sign in to comment.