Passed
Branch master (fbf0a6)
by Volodymyr
04:04
created

OnepagePlugin::afterGetJsLayout()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 5
nop 2
dl 0
loc 27
rs 9.1111
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type Magento\Checkout\Block\Onepage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
Unused Code introduced by
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