Skip to content

Commit

Permalink
PT-10692 - Clean up code style
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed Sep 3, 2019
1 parent 279ef45 commit 4da9eeb
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 205 deletions.
19 changes: 18 additions & 1 deletion .php_cs.dist
Expand Up @@ -12,6 +12,8 @@ file that was distributed with this source code.
EOF;

return PhpCsFixer\Config::create()
->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers())
->setRiskyAllowed(true)
->setUsingCache(false)
->setRules([
'@PSR2' => true,
Expand All @@ -25,7 +27,22 @@ return PhpCsFixer\Config::create()
'phpdoc_summary' => false,
'blank_line_after_opening_tag' => false,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'long']
'array_syntax' => ['syntax' => 'long'],
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
'general_phpdoc_annotation_remove' => [
'annotations' => ['copyright', 'category'],
],
'phpdoc_var_annotation_correct_order' => true,
'doctrine_annotation_indentation' => true,
'doctrine_annotation_spaces' => true,
'no_superfluous_phpdoc_tags' => true,
'php_unit_test_case_static_method_calls' => true,
PhpCsFixerCustomFixers\Fixer\NoUselessCommentFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\NoUnneededConcatenationFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\SingleSpaceAfterStatementFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\SingleSpaceBeforeStatementFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\PhpdocParamTypeFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\OperatorLinebreakFixer::name() => ['only_booleans' => true],
])
->setFinder($finder)
;
88 changes: 42 additions & 46 deletions Bootstrap.php

Large diffs are not rendered by default.

20 changes: 7 additions & 13 deletions Components/Paypal/AddressValidator.php
Expand Up @@ -16,27 +16,23 @@

class AddressValidator implements AddressValidatorInterface
{
/** @var AddressValidatorInterface */
/**
* @var AddressValidatorInterface
*/
private $innerValidator;

/** @var DIContainer $container */
private $container;

/**
* PaypalAddressValidator constructor.
*
* @param AddressValidatorInterface $innerValidator
* @param DIContainer $container
* @var DIContainer
*/
private $container;

public function __construct(AddressValidatorInterface $innerValidator, DIContainer $container)
{
$this->innerValidator = $innerValidator;
$this->container = $container;
}

/**
* @param Address $address
*
* @throws ValidationException
*/
public function validate(Address $address)
Expand All @@ -62,7 +58,7 @@ public function validate(Address $address)
$violations = $exception->getViolations();
$allowedViolations = array('state', 'phone', 'additionalAddressLine1', 'additionalAddressLine2');

/** @var $violation ConstraintViolationInterface */
/** @var ConstraintViolationInterface $violation */
foreach ($violations->getIterator() as $violation) {
if (!in_array($violation->getPropertyPath(), $allowedViolations, true)) {
throw $exception;
Expand All @@ -74,8 +70,6 @@ public function validate(Address $address)
}

/**
* @param Address $address
*
* @return bool
*/
public function isValid(Address $address)
Expand Down
7 changes: 3 additions & 4 deletions Components/Paypal/Client.php
Expand Up @@ -83,8 +83,7 @@ public function __construct($config)
}

/**
* @param $name
* @param array $args
* @param string $name
*
* @return array|bool
*/
Expand All @@ -99,12 +98,12 @@ public function __call($name, array $args = array())
'USER' => $this->apiUsername,
'SIGNATURE' => $this->apiSignature,
));

if (!empty($args[0])) {
$this->setParameterPost($args[0]);
}
$response = $this->request('POST');

$body = $response->getBody();
$body = $this->request('POST')->getBody();
$params = array();
parse_str($body, $params);

Expand Down
2 changes: 1 addition & 1 deletion Components/Paypal/RestClient.php
Expand Up @@ -184,7 +184,7 @@ protected function getBaseUri()
}

/**
* @param \Zend_Http_Response $response
* @param Zend_Http_Response $response
*
* @return array
*/
Expand Down
26 changes: 18 additions & 8 deletions Controllers/Backend/PaymentPaypal.php
Expand Up @@ -52,6 +52,7 @@ public function getListAction()
$limit = $this->Request()->getParam('limit', 20);
$start = $this->Request()->getParam('start', 0);
$filter = $this->Request()->getParam('filter', false);
$sort = $this->Request()->getParam('sort');

$subShopFilter = null;
if ($filter && !empty($filter)) {
Expand All @@ -61,7 +62,7 @@ public function getListAction()
}
}

if ($sort = $this->Request()->getParam('sort')) {
if ($sort) {
$sort = current($sort);
}
$direction = empty($sort['direction']) || $sort['direction'] === 'DESC' ? 'DESC' : 'ASC';
Expand Down Expand Up @@ -169,7 +170,7 @@ public function getListAction()
/**
* Will register the correct shop for a given transactionId.
*
* @param $transactionId
* @param string $transactionId
*/
public function registerShopByTransactionId($transactionId)
{
Expand All @@ -194,8 +195,7 @@ public function getBalanceAction()
$shopId = (int) $this->Request()->getParam('shopId');
$this->registerShopByShopId($shopId);

$client = $this->get('paypalClient');
$balance = $client->getBalance(array(
$balance = $this->get('paypalClient')->getBalance(array(
'RETURNALLCURRENCIES' => 0,
));

Expand Down Expand Up @@ -478,7 +478,7 @@ public function testClientAction()
$this->get('paypalClient');

$config = $this->Request()->getParams();
$config = new \Enlight_Config($config, true);
$config = new Enlight_Config($config, true);

// Test timeout
$timeout = (($config->get('paypalTimeout') ?: 20) * 0.25);
Expand Down Expand Up @@ -552,7 +552,7 @@ public function getWhitelistedCSRFActions()
/**
* Helper which registers a shop in order to use the PayPal API client within the context of the given shop
*
* @param $shopId
* @param int $shopId
*
* @throws RuntimeException
*/
Expand All @@ -570,8 +570,18 @@ private function registerShopByShopId($shopId)
}
}

$bootstrap = Shopware()->Bootstrap();
$shop->registerResources($bootstrap);
if (defined('Shopware::VERSION')) {
$swVersion = Shopware::VERSION;
} else {
$swVersion = Shopware()->Container()->get('config')->get('version');
}

if (version_compare($swVersion, '5.6.0', '>=')) {
$this->get('shopware.components.shop_registration_service')->registerResources($shop);
} else {
$bootstrap = Shopware()->Bootstrap();
$shop->registerResources($bootstrap);
}
}

private function formatErrorMessage($data)
Expand Down
29 changes: 13 additions & 16 deletions Controllers/Frontend/PaymentPaypal.php
Expand Up @@ -6,12 +6,16 @@
* file that was distributed with this source code.
*/

use Shopware\Bundle\MediaBundle\MediaService;
use Shopware\Components\CSRFWhitelistAware;
use Shopware\Components\Logger;
use Shopware\Components\Model\ModelManager;
use Shopware\Models\Customer\Address;
use Shopware\Models\Customer\Customer;

require_once __DIR__ . '/../../Components/CSRFWhitelistAware.php';

class Shopware_Controllers_Frontend_PaymentPaypal extends Shopware_Controllers_Frontend_Payment implements \Shopware\Components\CSRFWhitelistAware
class Shopware_Controllers_Frontend_PaymentPaypal extends Shopware_Controllers_Frontend_Payment implements CSRFWhitelistAware
{
/**
* @var Shopware_Plugins_Frontend_SwagPaymentPaypal_Bootstrap
Expand Down Expand Up @@ -93,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 @@ -131,7 +135,7 @@ public function gatewayAction()
$logoImage = $config->get('paypalLogoImage');
if ($logoImage !== null) {
if ($this->plugin->isShopware51() && !$this->plugin->isShopware52()) {
/** @var \Shopware\Bundle\MediaBundle\MediaService $mediaService */
/** @var MediaService $mediaService */
$mediaService = $this->get('shopware_media.media_service');
$logoImage = $mediaService->getUrl($logoImage);
}
Expand Down Expand Up @@ -287,7 +291,7 @@ public function returnAction()

// Canceled payment
if (isset($details['CHECKOUTSTATUS'])
&& (!isset($details['PAYERID']) || !isset($details['PAYMENTREQUEST_0_ADDRESSSTATUS']))
&& !isset($details['PAYERID'], $details['PAYMENTREQUEST_0_ADDRESSSTATUS'])
) {
unset($this->session->PaypalResponse);

Expand Down Expand Up @@ -400,8 +404,7 @@ public function notifyAction()
{
$txnId = $this->Request()->get('parent_txn_id') ?: $this->Request()->get('txn_id');
try {
$client = $this->get('paypalClient');
$details = $client->getTransactionDetails(array('TRANSACTIONID' => $txnId));
$details = $this->get('paypalClient')->getTransactionDetails(array('TRANSACTIONID' => $txnId));
} catch (Exception $e) {
$message = sprintf(
'PayPal-Notify: Exception %s',
Expand All @@ -426,17 +429,14 @@ public function notifyAction()
}

/**
* @param $details
*
* @return array
*/
protected function finishCheckout($details)
protected function finishCheckout(array $details)
{
$client = $client = $this->get('paypalClient');
$config = $this->plugin->Config();

$router = $this->Front()->Router();
$notifyUrl = $router->assemble(array('action' => 'notify', 'forceSecure' => true));
$notifyUrl = $this->Front()->Router()->assemble(array('action' => 'notify', 'forceSecure' => true));

$params = array(
'TOKEN' => $details['TOKEN'],
Expand Down Expand Up @@ -570,9 +570,6 @@ protected function finishCheckout($details)
return $result;
}

/**
* @param array $details
*/
protected function createAccount(array $details)
{
/** @var sAdmin $module */
Expand Down Expand Up @@ -940,7 +937,7 @@ private function updateShipping($userId, $shippingData)
/** @var Customer $customer */
$customer = $em->getRepository('Shopware\Models\Customer\Customer')->findOneBy(array('id' => $userId));

/** @var \Shopware\Models\Customer\Address $address */
/** @var Address $address */
$address = $customer->getDefaultShippingAddress();

$form = $this->createForm('Shopware\Bundle\AccountBundle\Form\Account\AddressFormType', $address);
Expand All @@ -961,7 +958,7 @@ private function logError($response)
}

$message = '[' . $response['L_ERRORCODE0'] . '] - ' . $response['L_SHORTMESSAGE0'] . '. ' . $response['L_LONGMESSAGE0'];
/** @var \Shopware\Components\Logger $pluginLogger */
/** @var Logger $pluginLogger */
$pluginLogger = Shopware()->Container()->get('pluginlogger');
$pluginLogger->error($message);
}
Expand Down
5 changes: 0 additions & 5 deletions Subscriber/BackendIndex.php
Expand Up @@ -17,11 +17,6 @@ class BackendIndex
*/
protected $bootstrap;

/**
* BackendIndex constructor.
*
* @param Bootstrap $bootstrap
*/
public function __construct(Bootstrap $bootstrap)
{
$this->bootstrap = $bootstrap;
Expand Down
11 changes: 3 additions & 8 deletions Subscriber/Frontend.php
Expand Up @@ -8,6 +8,7 @@

namespace Shopware\SwagPaymentPaypal\Subscriber;

use Shopware\Models\Shop\Shop;
use Shopware_Plugins_Frontend_SwagPaymentPaypal_Bootstrap as Bootstrap;

class Frontend
Expand All @@ -22,9 +23,6 @@ class Frontend
*/
protected $config;

/**
* @param Bootstrap $bootstrap
*/
public function __construct(Bootstrap $bootstrap)
{
$this->bootstrap = $bootstrap;
Expand All @@ -41,12 +39,9 @@ public static function getSubscribedEvents()
);
}

/**
* @param \Enlight_Event_EventArgs $args
*/
public function onPostDispatch(\Enlight_Event_EventArgs $args)
{
/** @var $action \Enlight_Controller_Action */
/** @var \Enlight_Controller_Action $action */
$action = $args->get('subject');
$request = $action->Request();
$response = $action->Response();
Expand All @@ -66,7 +61,7 @@ public function onPostDispatch(\Enlight_Event_EventArgs $args)
$controllerName = $request->getControllerName();
$actionName = $request->getActionName();

/** @var $shopContext \Shopware\Models\Shop\Shop */
/** @var Shop $shopContext */
$shopContext = $this->bootstrap->get('shop');
$templateVersion = $shopContext->getTemplate()->getVersion();

Expand Down
7 changes: 3 additions & 4 deletions Views/backend/payment_paypal/app.js
Expand Up @@ -5,7 +5,7 @@
* file that was distributed with this source code.
*/

//{block name="backend/payment_paypal/application"}
// {block name="backend/payment_paypal/application"}
Ext.define('Shopware.apps.PaymentPaypal', {

extend: 'Enlight.app.SubApplication',
Expand All @@ -15,7 +15,7 @@ Ext.define('Shopware.apps.PaymentPaypal', {

params: {},

controllers: [ 'Main' ],
controllers: ['Main'],

stores: [
'main.List'
Expand All @@ -37,5 +37,4 @@ Ext.define('Shopware.apps.PaymentPaypal', {
return me.controller.mainWindow;
}
});
//{/block}

// {/block}

0 comments on commit 4da9eeb

Please sign in to comment.