Skip to content

Commit

Permalink
refactor: upgrade phpstan and fix new errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mustapayev committed Dec 24, 2024
1 parent d04cd35 commit 3fc6b8b
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 70 deletions.
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
"escapestudios/symfony2-coding-standard": "^3.11",
"monolog/monolog": "^2.8",
"php-http/curl-client": "^2.2",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-strict-rules": "^1.4",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^9",
"rector/rector": "^1.1",
"rector/rector": "^2.0",
"slim/psr7": "^1.4",
"squizlabs/php_codesniffer": "^3.5",
"symfony/event-dispatcher": "^5.4",
Expand All @@ -57,5 +57,11 @@
"allow-plugins": {
"php-http/discovery": true
}
},
"scripts": {
"test": "./vendor/bin/phpunit --testsuite=unit",
"phpstan": "./vendor/bin/phpstan",
"baseline": "./vendor/bin/phpstan --generate-baseline",
"rector": "./vendor/bin/rector"
}
}
128 changes: 86 additions & 42 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Crypt/EstV3PosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs):
}
}

$formInputs[] = $posAccount->getStoreKey();
$formInputs[] = $posAccount->getStoreKey() ?? '';
// escape | and \ characters
$data = \str_replace("\\", "\\\\", \array_values($formInputs));
$data = \str_replace(self::HASH_SEPARATOR, "\\".self::HASH_SEPARATOR, $data);
Expand Down
2 changes: 1 addition & 1 deletion src/Crypt/PosNetV1PosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function createHash(AbstractPosAccount $posAccount, array $requestData):
$threeDSecureData['CavvData'],
$threeDSecureData['Eci'],
$threeDSecureData['MdStatus'],
$posAccount->getStoreKey(),
$posAccount->getStoreKey() ?? '',
];

$hashStr = \implode(static::HASH_SEPARATOR, $hashData);
Expand Down
12 changes: 6 additions & 6 deletions src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
* @param string $txType
* @param CreditCardInterface|null $creditCard
*
* @return array<string, string>
* @return array<string, array<string, string>|int|string>
*
* @throws UnsupportedTransactionTypeException
*/
Expand All @@ -131,16 +131,16 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAc
//DisplayAmount: Amount değeri ile aynı olacak şekilde gönderilmelidir.
'DisplayAmount' => $this->formatAmount($order['amount']),
'CurrencyCode' => $this->mapCurrency($order['currency']),
'MerchantOrderId' => $order['id'],
'OkUrl' => $order['success_url'],
'FailUrl' => $order['fail_url'],
'MerchantOrderId' => (string) $order['id'],
'OkUrl' => (string) $order['success_url'],
'FailUrl' => (string) $order['fail_url'],
'DeviceData' => [
'ClientIP' => $order['ip'],
'ClientIP' => (string) $order['ip'],
],
];

if ($creditCard instanceof CreditCardInterface) {
$requestData['CardHolderName'] = $creditCard->getHolderName();
$requestData['CardHolderName'] = (string) $creditCard->getHolderName();
$requestData['CardType'] = $this->cardTypeMapping[$creditCard->getType()];
$requestData['CardNumber'] = $creditCard->getNumber();
$requestData['CardExpireDateYear'] = $creditCard->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
* @param string $txType
* @param CreditCardInterface|null $creditCard
*
* @return array<string, string>
* @return array<string, string|int>
*/
public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAccount, array $order, string $paymentModel, string $txType, ?CreditCardInterface $creditCard = null): array
{
Expand All @@ -109,13 +109,13 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAc
'Amount' => $this->formatAmount($order['amount']),
'DisplayAmount' => $this->formatAmount($order['amount']),
'FECCurrencyCode' => $this->mapCurrency($order['currency']),
'MerchantOrderId' => $order['id'],
'OkUrl' => $order['success_url'],
'FailUrl' => $order['fail_url'],
'MerchantOrderId' => (string) $order['id'],
'OkUrl' => (string) $order['success_url'],
'FailUrl' => (string) $order['fail_url'],
];

if ($creditCard instanceof CreditCardInterface) {
$requestData['CardHolderName'] = $creditCard->getHolderName();
$requestData['CardHolderName'] = (string) $creditCard->getHolderName();
$requestData['CardNumber'] = $creditCard->getNumber();
$requestData['CardExpireDateYear'] = $creditCard->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT);
$requestData['CardExpireDateMonth'] = $creditCard->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ protected function mapResponseTransactionSecurity(string $mdStatus): string
*
* @param array<string, string> $raw3DAuthResponseData
*
* @return array<string, string>
* @return array<string, mixed>
*/
protected function map3DCommonResponseData(array $raw3DAuthResponseData): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ interface NonPaymentResponseMapperInterface
/**
* @param array<string, string> $rawResponseData
*
* @return array<string, string>
* @return array<string, mixed>
*/
public function mapRefundResponse(array $rawResponseData): array;

/**
* @param array<string, string> $rawResponseData
*
* @return array<string, string>
* @return array<string, mixed>
*/
public function mapCancelResponse(array $rawResponseData): array;

Expand All @@ -31,14 +31,14 @@ public function mapStatusResponse(array $rawResponseData): array;
/**
* @param array<string, array<string, string>|string> $rawResponseData
*
* @return array<string, array<string, string|null>>
* @return array<string, mixed>
*/
public function mapHistoryResponse(array $rawResponseData): array;

/**
* @param array<string, array<string, string>|string> $rawResponseData
*
* @return array<string, array<string, string|null>>
* @return array<string, mixed>
*/
public function mapOrderHistoryResponse(array $rawResponseData): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface PaymentResponseMapperInterface
* @param string $txType
* @param array<string, mixed> $order
*
* @return array<string, string|float|null>
* @return array<string, mixed>
*/
public function mapPaymentResponse(array $rawPaymentResponseData, string $txType, array $order): array;

Expand All @@ -39,7 +39,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen
* @param string $txType
* @param array<string, mixed> $order
*
* @return array<string, string|float|null>
* @return array<string, mixed>
*/
public function map3DPayResponseData(array $raw3DAuthResponseData, string $txType, array $order): array;

Expand All @@ -50,7 +50,7 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp
* @param string $txType
* @param array<string, mixed> $order
*
* @return array<string, string|float|null>
* @return array<string, mixed>
*/
public function map3DHostResponseData(array $raw3DAuthResponseData, string $txType, array $order): array;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ protected function mapResponseTransactionSecurity(string $mdStatus): string
*
* @param array<string, string> $raw3DAuthResponseData
*
* @return array<string, string>
* @return array<string, mixed>
*/
protected function map3DCommonResponseData(array $raw3DAuthResponseData): array
{
Expand Down Expand Up @@ -527,7 +527,7 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array
* @param string $txType
* @param array<string, mixed> $order
*
* @return array<string, string|float|null>
* @return array<string, mixed>
*/
private function map3DPaymentPaymentResponse(array $rawPaymentResponseData, string $txType, array $order): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/SerializerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class SerializerFactory
*/
public static function createGatewaySerializer(string $gatewayClass): SerializerInterface
{
/** @var SerializerInterface[] $serializers */
$serializers = [
AkbankPosSerializer::class,
EstPosSerializer::class,
Expand All @@ -48,6 +47,7 @@ public static function createGatewaySerializer(string $gatewayClass): Serializer
VakifKatilimPosSerializer::class,
];

/** @var class-string<SerializerInterface> $serializer */
foreach ($serializers as $serializer) {
if ($serializer::supports($gatewayClass)) {
return new $serializer();
Expand Down
5 changes: 4 additions & 1 deletion src/Gateways/PosNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,17 @@ public function get3DFormData(array $order, string $paymentModel, string $txType

$this->logger->debug('preparing 3D form data');

/** @var array{data1: string, data2: string, sign: string} $responseData */
$responseData = $data['oosRequestDataResponse'];

return $this->requestDataMapper->create3DFormData(
$this->account,
$order,
$paymentModel,
$txType,
$this->get3DGatewayURL($paymentModel),
null,
$data['oosRequestDataResponse']
$responseData
);
}

Expand Down

0 comments on commit 3fc6b8b

Please sign in to comment.