Passed
Push — master ( 8fe6ff...a89d57 )
by Володимир
05:41
created

Plugin/Block/Checkout/OnepagePlugin.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
declare(strict_types=1);
9
10
namespace Hryvinskyi\InvisibleCaptcha\Plugin\Block\Checkout;
11
12
use Hryvinskyi\Base\Helper\Json;
13
use Hryvinskyi\InvisibleCaptcha\Helper\Config\Frontend;
14
use Hryvinskyi\InvisibleCaptcha\Helper\Config\General;
15
use Hryvinskyi\InvisibleCaptcha\Model\LayoutSettings;
16
use Magento\Checkout\Block\Onepage;
17
18
/**
19
 * Class OnepagePlugin
20
 */
21
class OnepagePlugin
22
{
23
    /**
24
     * @var LayoutSettings
25
     */
26
    private $layoutSettings;
27
28
    /**
29
     * @var General
30
     */
31
    private $generalConfig;
32
33
    /**
34
     * @var Frontend
35
     */
36
    private $frontendConfig;
37
38
    /**
39
     * AuthenticationPopupPlugin constructor.
40
     *
41
     * @param LayoutSettings $layoutSettings
42
     * @param General $generalConfig
43
     * @param Frontend $frontendConfig
44
     */
45
    public function __construct(
46
        LayoutSettings $layoutSettings,
47
        General $generalConfig,
48
        Frontend $frontendConfig
49
    ) {
50
        $this->layoutSettings = $layoutSettings;
51
        $this->generalConfig = $generalConfig;
52
        $this->frontendConfig = $frontendConfig;
53
    }
54
55
    /**
56
     * @param Onepage $subject
57
     * @param string $result
58
     *
59
     * @return string
60
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
61
     */
62
    public function afterGetJsLayout(Onepage $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

62
    public function afterGetJsLayout(/** @scrutinizer ignore-unused */ Onepage $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...
63
    {
64
        $layout = Json::decode($result);
65
66
        $layout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
67
        ['shippingAddress']['children']['customer-email']['children']['invisible-captcha']['config']
68
            = $this->layoutSettings->getCaptchaSettings();
69
70
        $layout['components']['checkout']['children']['authentication']['children']['invisible-captcha']['config']
71
            = $this->layoutSettings->getCaptchaSettings();
72
73
        if (!$this->generalConfig->hasEnabled()
74
            || !$this->frontendConfig->hasEnabled()
75
            || !$this->frontendConfig->hasEnabledCustomerLogin()
76
        ) {
77
            if (isset($layout['components']['checkout']['children']['authentication']['children']['invisible-captcha'])) {
78
                unset($layout['components']['checkout']['children']['authentication']['children']['invisible-captcha']);
79
            }
80
81
            if (isset($layout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
82
                ['shippingAddress']['children']['customer-email']['children']['invisible-captcha'])) {
83
                unset($layout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
84
                    ['shippingAddress']['children']['customer-email']['children']['invisible-captcha']);
85
            }
86
        }
87
88
        return Json::encode($layout);
89
    }
90
}
91