Skip to content

Commit

Permalink
Add PHPCS PSR12 standard (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ddly authored Mar 6, 2024
1 parent bedb2ca commit f3c5f29
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 24 deletions.
11 changes: 11 additions & 0 deletions .dev-tools/.php-cs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ruleset name="Tpay Standard">
<descripton>Tpay PHPCS coding standard</descripton>
<file>../</file>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/*.js</exclude-pattern>
<rule ref="PSR12">
<exclude name="PSR12.Operators.OperatorSpacing.NoSpaceBefore" />
<exclude name="PSR12.Operators.OperatorSpacing.NoSpaceAfter" />
</rule>
</ruleset>
9 changes: 6 additions & 3 deletions .dev-tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"tpay-com/coding-standards": "^1.0.1",
"tpay-com/tpay-openapi-php": "^1.3",
"tpay-com/tpay-php": "^2.3.4",
"vimeo/psalm": "^5.15.0"
"vimeo/psalm": "^5.15.0",
"squizlabs/php_codesniffer": "*"
},
"repositories": [
{
Expand All @@ -19,15 +20,17 @@
"scripts": {
"cs:fixer": "./vendor/bin/php-cs-fixer fix -vvv --diff",
"cs:phpstan": "./vendor/bin/phpstan",
"cs:psalm": "./vendor/bin/psalm"
"cs:psalm": "./vendor/bin/psalm",
"cs:sniffer": "./vendor/bin/phpcs --standard=.php-cs.xml -n"
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"kubawerlos/composer-smaller-lock": true,
"magento/composer-dependency-version-audit-plugin": false,
"magento/magento-composer-installer": false,
"php-http/discovery": false
"php-http/discovery": false,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
36 changes: 35 additions & 1 deletion .dev-tools/composer.lock

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

5 changes: 4 additions & 1 deletion .github/workflows/sca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: none, bcmath, curl, dom, fileinfo, gd, iconv, intl, mbstring, pdo_mysql, simplexml, soap, sockets, tokenizer, xsl, zip
extensions: none, bcmath, curl, dom, fileinfo, gd, iconv, intl, mbstring, pdo_mysql, simplexml, soap, sockets, tokenizer, xsl, xmlwriter, zip
coverage: none

- run: composer validate --strict
Expand All @@ -27,6 +27,9 @@ jobs:
- working-directory: .dev-tools
run: composer cs:fixer -- --dry-run

- working-directory: .dev-tools
run: composer cs:sniffer

- working-directory: .dev-tools
run: composer cs:phpstan

Expand Down
2 changes: 1 addition & 1 deletion Controller/tpay/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private function extractNotification(StoreInterface $store): Response
}

$this->saveCard($notification, $orderId);
$this->tpayService->SetOrderStatus($orderId, $notification, $this->tpay);
$this->tpayService->setOrderStatus($orderId, $notification, $this->tpay);

return (new Response())->setStatusCode(Response::STATUS_CODE_200)->setContent('TRUE');
} catch (Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Token extends AbstractDb
{
protected function _construct()
protected function _construct()// phpcs:ignore
{
$this->_init('tpay_credit_cards', 'id');
}
Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/Token/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Collection extends AbstractCollection
{
protected function _construct()
protected function _construct()// phpcs:ignore
{
$this->_init('tpaycom\magento2basic\Model\Tokens', 'tpaycom\magento2basic\Model\ResourceModel\Token');
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function deleteToken($requestToken)
return $this;
}

protected function _construct()
protected function _construct() // phpcs:ignore
{
$this->_init('tpaycom\magento2basic\Model\ResourceModel\Token');
}
Expand Down
48 changes: 37 additions & 11 deletions Service/TpayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\Order\Payment;
use Magento\Sales\Model\Order\Payment\Operations\RegisterCaptureNotificationOperation;
use Magento\Sales\Model\Order\Payment\State\CommandInterface;
use Magento\Sales\Model\Order\Payment\Transaction;
Expand Down Expand Up @@ -93,7 +92,7 @@ public function getPayment(string $orderId): OrderPaymentInterface
*
* @return bool|OrderInterface
*/
public function SetOrderStatus(string $orderId, array $validParams, TpayInterface $tpayModel)
public function setOrderStatus(string $orderId, array $validParams, TpayInterface $tpayModel)
{
$order = $this->getOrderById($orderId);

Expand Down Expand Up @@ -158,8 +157,9 @@ public function setCardOrderStatus($orderId, array $validParams, $tpayModel)
$emailNotify = false;

$order = $this->updateTransactionId($order, $validParams);
$amountCheck = (float) number_format((float) $validParams['amount'], 2, '.', '') !== $orderAmount;

if (!isset($validParams['status']) || 'correct' !== $validParams['status'] || ((float) number_format((float) $validParams['amount'], 2, '.', '') !== $orderAmount)) {
if (!isset($validParams['status']) || 'correct' !== $validParams['status'] || $amountCheck) {
$comment = __('Payment has been declined. ').'</br>'.$transactionDesc;
$this->addCommentToHistory($orderId, $comment);
} else {
Expand Down Expand Up @@ -222,7 +222,9 @@ protected function getCardTransactionDesc($validParams)
}

$transactionDesc = (is_null($error)) ? ' ' : ' Reason: <b>'.$error.'</b>';
$transactionDesc .= (isset($validParams['test_mode'])) && 1 === (int) $validParams['test_mode'] ? '<b> TEST </b>' : ' ';
$transactionDesc .= (isset($validParams['test_mode'])) && 1 === (int) $validParams['test_mode']
? '<b> TEST </b>'
: ' ';

return $transactionDesc;
}
Expand All @@ -233,10 +235,20 @@ protected function getCardTransactionDesc($validParams)
* @param float|string $amount
* @param bool|int $skipFraudDetection
*/
private function registerCaptureNotificationTpay(OrderPaymentInterface $payment, $amount, array $validParams, $skipFraudDetection = false)
{
private function registerCaptureNotificationTpay(
OrderPaymentInterface $payment,
$amount,
array $validParams,
$skipFraudDetection = false
) {
// @var $payment Payment
$payment->setTransactionId($this->transactionManager->generateTransactionId($payment, Transaction::TYPE_CAPTURE, $payment->getAuthorizationTransaction()));
$payment->setTransactionId(
$this->transactionManager->generateTransactionId(
$payment,
Transaction::TYPE_CAPTURE,
$payment->getAuthorizationTransaction()
)
);

$order = $payment->getOrder();
$amount = (float) $amount;
Expand Down Expand Up @@ -271,10 +283,20 @@ private function registerCaptureNotificationTpay(OrderPaymentInterface $payment,
$payment->addTransactionCommentsToOrder($transaction, $message);
}

private function registerCardCaptureNotificationTpay(OrderPaymentInterface $payment, $amount, $validParams, $skipFraudDetection = false)
{
private function registerCardCaptureNotificationTpay(
OrderPaymentInterface $payment,
$amount,
$validParams,
$skipFraudDetection = false
) {
// @var $payment Payment
$payment->setTransactionId($this->transactionManager->generateTransactionId($payment, Transaction::TYPE_CAPTURE, $payment->getAuthorizationTransaction()));
$payment->setTransactionId(
$this->transactionManager->generateTransactionId(
$payment,
Transaction::TYPE_CAPTURE,
$payment->getAuthorizationTransaction()
)
);

$order = $payment->getOrder();
$amount = (float) $amount;
Expand All @@ -285,7 +307,11 @@ private function registerCardCaptureNotificationTpay(OrderPaymentInterface $paym
}
$orderCurrency = array_search($orderCurrencyCode, CurrencyCodesDictionary::CODES);
// register new capture
if (!$invoice && $payment->isCaptureFinal($amount) && ($orderCurrency === (int) $validParams['currency'] || $orderCurrencyCode === $validParams['currency'])) {
if (
!$invoice
&& $payment->isCaptureFinal($amount)
&& ($orderCurrency === (int) $validParams['currency'] || $orderCurrencyCode === $validParams['currency'])
) {
$invoice = $order->prepareInvoice()->register();
$invoice->setOrder($order);
$order->addRelatedObject($invoice);
Expand Down
19 changes: 15 additions & 4 deletions Service/TpayTokensService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ class TpayTokensService extends Tokens
/** @var ResourceConnection */
private $resourceConnection;

public function __construct(Context $context, Registry $registry, ResourceConnection $resourceConnection, $resource = null, ?AbstractDb $resourceCollection = null, array $data = [])
{
public function __construct(
Context $context,
Registry $registry,
ResourceConnection $resourceConnection,
$resource = null,
?AbstractDb $resourceCollection = null,
array $data = []
) {
$this->resourceConnection = $resourceConnection;
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}

public function setCustomerToken(string $customerId, ?string $token, string $shortCode, string $vendor, ?string $crc = null)
{
public function setCustomerToken(
string $customerId,
?string $token,
string $shortCode,
string $vendor,
?string $crc = null
) {
$tokenEntity = $this->load($token, 'cli_auth');

if (!$tokenEntity->getId()) {
Expand Down

0 comments on commit f3c5f29

Please sign in to comment.