Skip to content

Commit

Permalink
ci(PT13113): Add github workflow for code style (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Garding committed Jul 13, 2023
1 parent 0a61f8b commit 082c04d
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 70 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/javascript-code-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Javascript

on:
pull_request:
workflow_dispatch:
push:
branches:
- main

jobs:
call-javascript-workflow:
name: Analyse Javascript Code for SwagPaymentPaypal
uses: shopware5/docker-images-testing/.github/workflows/javascript-analysis.yml@main
with:
plugin-name: SwagPaymentPaypal
legacy-plugin: true
legacy-plugin-target: Frontend
17 changes: 17 additions & 0 deletions .github/workflows/php-code-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: PHP

on:
pull_request:
workflow_dispatch:
push:
branches:
- main

jobs:
call-analyse-workflow:
name: Analyse code for SwagPaymentPaypal
uses: shopware5/docker-images-testing/.github/workflows/php-code-analysis.yml@main
with:
plugin-name: SwagPaymentPaypal
legacy-plugin: true
legacy-plugin-target: Frontend
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea
.php-cs-fixer.cache
48 changes: 0 additions & 48 deletions .php_cs.dist

This file was deleted.

14 changes: 7 additions & 7 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function update($version)
$this->get('db')->exec($sql);
}
if (version_compare($version, '3.3.2', '<=')) {
//always remove unneeded settings
// always remove unneeded settings
$em = $this->get('models');
$form = $this->Form();
$paypalLogInApi = $form->getElement('paypalLogInApi');
Expand All @@ -137,7 +137,7 @@ public function update($version)
$this->Form()->removeElement('paypalVersion');
}

//Update form
// Update form
$this->createMyForm();
$this->createMyEvents();

Expand Down Expand Up @@ -316,22 +316,22 @@ public function getPaymentStatusId($paymentStatus)
case 'Pending':
case 'In-Progress':
$paymentStatusId = (int) $this->Config()->get('paypalPendingStatusId', 18);
break; //Reserviert
break; // Reserviert
case 'Processed':
$paymentStatusId = 18;
break; //In Bearbeitung > Reserviert
break; // In Bearbeitung > Reserviert
case 'Refunded':
case 'Partially-Refunded':
$paymentStatusId = 20;
break; //Wiedergutschrift
break; // Wiedergutschrift
case 'Cancelled-Reversal':
$paymentStatusId = 12;
break;
case 'Expired':
case 'Denied':
case 'Voided':
$paymentStatusId = 17;
break; //Offen
break; // Offen
case 'Reversed':
default:
$paymentStatusId = 21;
Expand Down Expand Up @@ -529,7 +529,7 @@ private function fixPaymentLogo()
$this->get('models')->flush();
}

//Remove file if don't have it in media manager but we have it under media/image folder
// Remove file if don't have it in media manager but we have it under media/image folder
if (file_exists($mediaPath)) {
unlink($mediaPath);
}
Expand Down
11 changes: 4 additions & 7 deletions Controllers/Backend/PaymentPaypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,16 @@ public function getDetailsAction()
'addressCountry' => $details['SHIPTOCOUNTRYCODE'],
'addressPhone' => $details['SHIPTOPHONENUM'],

'protectionStatus' => $details['PROTECTIONELIGIBILITY'], //Eligible, ItemNotReceivedEligible, UnauthorizedPaymentEligible, Ineligible
'protectionStatus' => $details['PROTECTIONELIGIBILITY'], // Eligible, ItemNotReceivedEligible, UnauthorizedPaymentEligible, Ineligible
'paymentStatus' => $details['PAYMENTSTATUS'],
'pendingReason' => $details['PENDINGREASON'],
'paymentDate' => new DateTime($details['ORDERTIME']),
'paymentType' => $details['PAYMENTTYPE'], //none, echeck, instant
'paymentType' => $details['PAYMENTTYPE'], // none, echeck, instant
'paymentAmount' => $details['AMT'],
'paymentCurrency' => $details['CURRENCYCODE'],

'transactionId' => $details['TRANSACTIONID'],
//'orderNumber' => $details['INVNUM'],
// 'orderNumber' => $details['INVNUM'],
);
$sql = 'SELECT `countryname` FROM `s_core_countries` WHERE `countryiso` LIKE ?';
$row['addressCountry'] = $this->get('db')->fetchOne($sql, array($row['addressCountry']));
Expand Down Expand Up @@ -424,10 +424,7 @@ public function doActionAction()
}

if ($result['ACK'] !== 'Success') {
throw new RuntimeException(
'[' . $result['L_SEVERITYCODE0'] . '] ' .
$result['L_SHORTMESSAGE0'] . ' ' . $result['L_LONGMESSAGE0'] . "<br>\n"
);
throw new RuntimeException('[' . $result['L_SEVERITYCODE0'] . '] ' . $result['L_SHORTMESSAGE0'] . ' ' . $result['L_LONGMESSAGE0'] . "<br>\n");
}

// Switch transaction id
Expand Down
16 changes: 8 additions & 8 deletions Controllers/Frontend/PaymentPaypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function indexAction()
$payPalResponse = $this->session->offsetGet('PaypalResponse');
if (!empty($payPalResponse['TOKEN'])) {
$this->forward('return');
// Paypal Basis || PayPal Express
// Paypal Basis || PayPal Express
} elseif ($this->getPaymentShortName() === 'paypal') {
$this->forward('gateway');
} else {
Expand Down Expand Up @@ -484,7 +484,7 @@ protected function finishCheckout(array $details)
}
}

//$params['SOFTDESCRIPTOR'] = $orderNumber;
// $params['SOFTDESCRIPTOR'] = $orderNumber;

if (!empty($params['REFERENCEID'])) {
foreach ($params as $key => $param) {
Expand Down Expand Up @@ -562,7 +562,7 @@ protected function finishCheckout(array $details)
$ppAmount = (float) $result['PAYMENTINFO_0_AMT'];
$swAmount = $this->getAmount();
if (abs($swAmount - $ppAmount) >= 0.01) {
$paymentStatus = 'AmountMissMatch'; //Überprüfung notwendig
$paymentStatus = 'AmountMissMatch'; // Überprüfung notwendig
}
$this->plugin->setPaymentStatus($result['PAYMENTINFO_0_TRANSACTIONID'], $paymentStatus);

Expand Down Expand Up @@ -670,8 +670,8 @@ protected function createAccount(array $details)
$sql .= "AND `subshopID` = {$shop->getId()} ";
}

//Always use the latest account. It is possible, that the account already exists but the password may be invalid.
//The plugin then creates a new account and uses that one instead.
// Always use the latest account. It is possible, that the account already exists but the password may be invalid.
// The plugin then creates a new account and uses that one instead.
$sql .= 'ORDER BY `id` DESC';
$data['auth']['passwordMD5'] = $this->get('db')->fetchOne($sql, array($data['auth']['email']));

Expand All @@ -681,7 +681,7 @@ protected function createAccount(array $details)

// Check login status
if ($module->sCheckUser()) {
//Save the new address.
// Save the new address.
if ($swVersion === '___VERSION___' || version_compare($swVersion, '5.2.0', '>=')) {
$userId = $this->session->offsetGet('sUserId');
$this->updateShipping($userId, $data['shipping']);
Expand Down Expand Up @@ -876,7 +876,7 @@ protected function getCustomerParameter()

$customer = array(
'CUSTOMERSERVICENUMBER' => $user['billingaddress']['customernumber'],
//'gender' => $shipping['salutation'] == 'ms' ? 'f' : 'm',
// 'gender' => $shipping['salutation'] == 'ms' ? 'f' : 'm',
'PAYMENTREQUEST_0_SHIPTONAME' => $name,
'PAYMENTREQUEST_0_SHIPTOSTREET' => $shipping['street'],
'PAYMENTREQUEST_0_SHIPTOSTREET2' => $shipping['street2'],
Expand Down Expand Up @@ -904,7 +904,7 @@ private function saveUser($data)
{
$plain = array_merge($data['auth'], $data['shipping']);

//Create forms and validate the input
// Create forms and validate the input
$customer = new Shopware\Models\Customer\Customer();
$form = $this->createForm('Shopware\Bundle\AccountBundle\Form\Account\PersonalFormType', $customer);
$form->submit($plain);
Expand Down
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.DEFAULT_GOAL := help

filter := "default"
dirname := $(notdir $(CURDIR))
envprefix := $(shell echo "$(dirname)" | tr A-Z a-z)
envname := $(envprefix)test
debug := "false"

help:
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help

install-plugin: .refresh-plugin-list ## Install and activate the plugin
@echo "Install the plugin"
php ./../../../../../../bin/console sw:plugin:install $(dirname) --activate
php ./../../../../../../bin/console sw:cache:clear

.refresh-plugin-list:
@echo "Refresh the plugin list"
php ./../../../../../../bin/console sw:plugin:refresh

CS_FIXER_RUN=
fix-cs: ## Run the code style fixer
php ./../../../../../../vendor/bin/php-cs-fixer fix --config=./php-cs-fixer.php -v $(CS_FIXER_RUN)

fix-cs-dry: CS_FIXER_RUN= --dry-run
fix-cs-dry: fix-cs ## Run the code style fixer in dry mode

check-js-code: check-eslint-backend ## Run esLint
fix-js-code: fix-eslint-backend fix-eslint-e2e fix-eslint-jest-tests ## Fix js code

ESLINT_FIX=
check-eslint-backend:
./../../../../../../themes/node_modules/eslint/bin/eslint.js --ignore-path .eslintignore -c ./../../../../../../themes/Backend/.eslintrc.js Views/backend $(ESLINT_FIX)

fix-eslint-backend: ESLINT_FIX= --fix
fix-eslint-backend: check-eslint-backend
60 changes: 60 additions & 0 deletions php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* (c) shopware AG <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PhpCsFixer\Config;
use PhpCsFixerCustomFixers\Fixer\NoUselessCommentFixer;
use PhpCsFixerCustomFixers\Fixer\PhpdocParamTypeFixer;
use PhpCsFixerCustomFixers\Fixer\SingleSpaceAfterStatementFixer;
use PhpCsFixerCustomFixers\Fixer\SingleSpaceBeforeStatementFixer;
use PhpCsFixerCustomFixers\Fixers;

$finder = PhpCsFixer\Finder::create()
->in(__DIR__);

$header = <<<EOF
(c) shopware AG <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

return (new Config())
->registerCustomFixers(new Fixers())
->setRiskyAllowed(true)
->setRules(array(
'@PSR2' => true,
'@Symfony' => true,
'header_comment' => array('header' => $header, 'separate' => 'bottom', 'comment_type' => 'PHPDoc'),
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'blank_line_after_opening_tag' => false,
'concat_space' => array('spacing' => 'one'),
'array_syntax' => array('syntax' => 'long'),
'yoda_style' => array('equal' => false, 'identical' => false, 'less_and_greater' => false),
'general_phpdoc_annotation_remove' => array(
'annotations' => array('copyright', 'category'),
),
'phpdoc_var_annotation_correct_order' => true,
'doctrine_annotation_indentation' => true,
'doctrine_annotation_spaces' => true,
'no_superfluous_phpdoc_tags' => true,
'native_constant_invocation' => false,
'php_unit_test_case_static_method_calls' => true,
'operator_linebreak' => array('only_booleans' => true),
'visibility_required' => false,
NoUselessCommentFixer::name() => true,
SingleSpaceAfterStatementFixer::name() => true,
SingleSpaceBeforeStatementFixer::name() => true,
PhpdocParamTypeFixer::name() => true,
))
->setFinder($finder)
;

0 comments on commit 082c04d

Please sign in to comment.