Issues (10)

Plugin/Block/Account/AuthenticationPopupPlugin.php (1 issue)

1
<?php
2
/**
3
 * Copyright (c) 2019. Volodymyr Hryvinskyi.  All rights reserved.
4
 * @author: <mailto:[email protected]>
5
 * @github: <https://github.com/hryvinskyi>
6
 */
7
8
namespace Hryvinskyi\InvisibleCaptcha\Plugin\Block\Account;
9
10
use Hryvinskyi\Base\Helper\Json;
11
use Hryvinskyi\InvisibleCaptcha\Helper\Config\Frontend;
12
use Hryvinskyi\InvisibleCaptcha\Helper\Config\General;
13
use Hryvinskyi\InvisibleCaptcha\Model\LayoutSettings;
14
use Magento\Customer\Block\Account\AuthenticationPopup;
15
16
class AuthenticationPopupPlugin
17
{
18
    /**
19
     * @var LayoutSettings
20
     */
21
    private $layoutSettings;
22
23
    /**
24
     * @var General
25
     */
26
    private $generalConfig;
27
28
    /**
29
     * @var Frontend
30
     */
31
    private $frontendConfig;
32
33
    /**
34
     * AuthenticationPopupPlugin constructor.
35
     *
36
     * @param LayoutSettings $layoutSettings
37
     * @param General $generalConfig
38
     * @param Frontend $frontendConfig
39
     */
40
    public function __construct(
41
        LayoutSettings $layoutSettings,
42
        General $generalConfig,
43
        Frontend $frontendConfig
44
    ) {
45
        $this->layoutSettings = $layoutSettings;
46
        $this->generalConfig = $generalConfig;
47
        $this->frontendConfig = $frontendConfig;
48
    }
49
50
    /**
51
     * @param AuthenticationPopup $subject
52
     * @param string $result
53
     *
54
     * @return string
55
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
56
     */
57
    public function afterGetJsLayout(AuthenticationPopup $subject, $result)
0 ignored issues
show
The parameter $subject is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

57
    public function afterGetJsLayout(/** @scrutinizer ignore-unused */ AuthenticationPopup $subject, $result)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        $layout = Json::decode($result);
60
        $layout['components']['authenticationPopup']['children']['invisible-captcha']['config']
61
            = $this->layoutSettings->getCaptchaSettings();
62
63
        if (
64
            (
65
                !$this->generalConfig->hasEnabled()
66
                || !$this->frontendConfig->hasEnabled()
67
                || !$this->frontendConfig->hasEnabledCustomerLogin()
68
            )
69
            && isset($layout['components']['authenticationPopup']['children']['invisible-captcha'])
70
        ) {
71
            unset($layout['components']['authenticationPopup']['children']['invisible-captcha']);
72
        }
73
74
        return Json::encode($layout);
75
    }
76
}
77