Navigation Menu

Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Commit

Permalink
CS refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Sep 24, 2017
1 parent 65e6e92 commit 0419349
Show file tree
Hide file tree
Showing 24 changed files with 195 additions and 165 deletions.
2 changes: 1 addition & 1 deletion Block/Adminhtml/ReCaptcha.php
Expand Up @@ -78,6 +78,6 @@ public function getSize()
*/
public function canDisplayCaptcha()
{
return $this->config->getEnabledBackend();
return $this->config->isEnabledBackend();
}
}
8 changes: 4 additions & 4 deletions Block/Config.php
Expand Up @@ -56,10 +56,10 @@ public function getCaptchaConfig()
'badge' => $this->config->getFrontendPosition(),
'theme' => $this->config->getFrontendTheme(),
'enabled' => [
'login' => $this->config->getEnabledFrontendLogin(),
'create' => $this->config->getEnabledFrontendCreate(),
'forgot' => $this->config->getEnabledFrontendForgot(),
'contact' => $this->config->getEnabledFrontendContact(),
'login' => $this->config->isEnabledFrontendLogin(),
'create' => $this->config->isEnabledFrontendCreate(),
'forgot' => $this->config->isEnabledFrontendForgot(),
'contact' => $this->config->isEnabledFrontendContact(),
]
];
}
Expand Down
9 changes: 1 addition & 8 deletions Block/Frontend/ReCaptcha.php
Expand Up @@ -21,7 +21,6 @@

namespace MSP\ReCaptcha\Block\Frontend;

use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\View\Element\Template;
use MSP\ReCaptcha\Model\Config;

Expand All @@ -31,26 +30,20 @@ class ReCaptcha extends Template
* @var Config
*/
private $config;

/**
* @var array
*/
private $data;

/**
* @var EncoderInterface
*/
private $encoder;

public function __construct(
Template\Context $context,
Config $config,
EncoderInterface $encoder,
array $data = []
) {
parent::__construct($context, $data);
$this->config = $config;
$this->data = $data;
$this->encoder = $encoder;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Command/ReCaptcha.php
Expand Up @@ -56,6 +56,9 @@ protected function configure()
parent::configure();
}

/**
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->config->saveConfig(
Expand Down
20 changes: 10 additions & 10 deletions Model/Config.php
Expand Up @@ -86,7 +86,7 @@ public function getPrivateKey()
* Return true if enabled on backend
* @return bool
*/
public function getEnabledBackend()
public function isEnabledBackend()
{
if (!$this->getPrivateKey() || !$this->getPublicKey()) {
return false;
Expand All @@ -99,7 +99,7 @@ public function getEnabledBackend()
* Return true if enabled on frontend
* @return bool
*/
public function getEnabledFrontend()
public function isEnabledFrontend()
{
if (!$this->getPrivateKey() || !$this->getPublicKey()) {
return false;
Expand All @@ -112,9 +112,9 @@ public function getEnabledFrontend()
* Return true if enabled on frontend login
* @return bool
*/
public function getEnabledFrontendLogin()
public function isEnabledFrontendLogin()
{
if (!$this->getEnabledFrontend()) {
if (!$this->isEnabledFrontend()) {
return false;
}

Expand All @@ -125,9 +125,9 @@ public function getEnabledFrontendLogin()
* Return true if enabled on frontend forgot password
* @return bool
*/
public function getEnabledFrontendForgot()
public function isEnabledFrontendForgot()
{
if (!$this->getEnabledFrontend()) {
if (!$this->isEnabledFrontend()) {
return false;
}

Expand All @@ -138,9 +138,9 @@ public function getEnabledFrontendForgot()
* Return true if enabled on frontend contact
* @return bool
*/
public function getEnabledFrontendContact()
public function isEnabledFrontendContact()
{
if (!$this->getEnabledFrontend()) {
if (!$this->isEnabledFrontend()) {
return false;
}

Expand All @@ -151,9 +151,9 @@ public function getEnabledFrontendContact()
* Return true if enabled on frontend create user
* @return bool
*/
public function getEnabledFrontendCreate()
public function isEnabledFrontendCreate()
{
if (!$this->getEnabledFrontend()) {
if (!$this->isEnabledFrontend()) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/Position.php
Expand Up @@ -52,4 +52,4 @@ public function toArray()

return $return;
}
}
}
2 changes: 1 addition & 1 deletion Model/Config/Source/Size.php
Expand Up @@ -51,4 +51,4 @@ public function toArray()

return $return;
}
}
}
2 changes: 1 addition & 1 deletion Model/Config/Source/Theme.php
Expand Up @@ -51,4 +51,4 @@ public function toArray()

return $return;
}
}
}
2 changes: 1 addition & 1 deletion Model/Config/Source/Type.php
Expand Up @@ -54,4 +54,4 @@ public function toArray()

return $return;
}
}
}
14 changes: 8 additions & 6 deletions Model/Validate.php
Expand Up @@ -93,29 +93,31 @@ protected function _validate()

$userIp = $this->remoteAddress->getRemoteAddress();

$reCatchaResponse = $this->request->getParam('g-recaptcha-response', '');
$reCaptchaResponse = $this->request->getParam('g-recaptcha-response', '');

// Check if it is a JSON payload
if (!$reCatchaResponse) {
if (!$reCaptchaResponse) {
$content = $this->request->getContent();
if ($content) {
try {
$jsonParams = $this->jsonDecoder->decode($content);
if (isset($jsonParams['g-recaptcha-response'])) {
$reCatchaResponse = $jsonParams['g-recaptcha-response'];
$reCaptchaResponse = $jsonParams['g-recaptcha-response'];
}
} catch (\Exception $e) {
$reCatchaResponse = '';
$reCaptchaResponse = '';
}
}
}

if (!$reCatchaResponse) {
if (!$reCaptchaResponse) {
return false;
}

// @codingStandardsIgnoreStart
$reCaptcha = new ReCaptcha($secret);
$res = $reCaptcha->verify($reCatchaResponse, $userIp);
// @codingStandardsIgnoreEnd
$res = $reCaptcha->verify($reCaptchaResponse, $userIp);

return $res->isSuccess();
}
Expand Down
2 changes: 1 addition & 1 deletion Observer/Adminhtml/ForgotPasswordObserver.php
Expand Up @@ -64,7 +64,7 @@ public function __construct(

public function execute(Observer $observer)
{
if (!$this->config->getEnabledBackend()) {
if (!$this->config->isEnabledBackend()) {
return;
}

Expand Down
5 changes: 4 additions & 1 deletion Observer/Adminhtml/LoginObserver.php
Expand Up @@ -46,9 +46,12 @@ public function __construct(
$this->config = $config;
}

/**
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
*/
public function execute(Observer $observer)
{
if (!$this->config->getEnabledBackend()) {
if (!$this->config->isEnabledBackend()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Observer/Frontend/AjaxLoginObserver.php
Expand Up @@ -65,7 +65,7 @@ public function __construct(

public function execute(Observer $observer)
{
if (!$this->config->getEnabledFrontendLogin()) {
if (!$this->config->isEnabledFrontendLogin()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Observer/Frontend/ContactFormObserver.php
Expand Up @@ -72,7 +72,7 @@ public function __construct(

public function execute(Observer $observer)
{
if (!$this->config->getEnabledFrontendContact()) {
if (!$this->config->isEnabledFrontendContact()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Observer/Frontend/CreateUserObserver.php
Expand Up @@ -81,7 +81,7 @@ public function __construct(

public function execute(Observer $observer)
{
if (!$this->config->getEnabledFrontendCreate()) {
if (!$this->config->isEnabledFrontendCreate()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Observer/Frontend/ForgotPasswordObserver.php
Expand Up @@ -72,7 +72,7 @@ public function __construct(

public function execute(Observer $observer)
{
if (!$this->config->getEnabledFrontendForgot()) {
if (!$this->config->isEnabledFrontendForgot()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Observer/Frontend/LoginObserver.php
Expand Up @@ -80,7 +80,7 @@ public function __construct(

public function execute(Observer $observer)
{
if (!$this->config->getEnabledFrontendLogin()) {
if (!$this->config->isEnabledFrontendLogin()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion registration.php
Expand Up @@ -22,4 +22,4 @@
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'MSP_ReCaptcha',
__DIR__
);
);
2 changes: 1 addition & 1 deletion view/adminhtml/templates/msp_recaptcha.phtml
Expand Up @@ -20,7 +20,7 @@

/** @var $block MSP\ReCaptcha\Block\Adminhtml\ReCaptcha */
?>
<?php if ($block->canDisplayCaptcha()): ?>
<?php if ($block->canDisplayCaptcha()) : ?>
<div class="admin__field field-recaptcha">
<div class="g-recaptcha"
data-sitekey="<?php echo $block->getPublicKey() ?>"
Expand Down
18 changes: 9 additions & 9 deletions view/frontend/requirejs-config.js
Expand Up @@ -11,18 +11,18 @@
* obtain it through the world-wide-web, please send an email
* to info@magespecialist.it so we can send you a copy immediately.
*
* @category MSP
* @package MSP_ReCaptcha
* @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

'use strict';

var config = {
config: {
mixins: {
'Magento_Ui/js/view/messages': {
'MSP_ReCaptcha/js/ui-messages-mixin': true
}
config: {
mixins: {
'Magento_Ui/js/view/messages': {
'MSP_ReCaptcha/js/ui-messages-mixin': true
}
}
}
}
};
};
2 changes: 1 addition & 1 deletion view/frontend/templates/msp_recaptcha.phtml
Expand Up @@ -30,4 +30,4 @@
"Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout();?>
}
}
</script>
</script>

0 comments on commit 0419349

Please sign in to comment.