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

AjaxResponseFailure   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A execute() 0 10 1
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\Model\Provider\Failure;
11
12
use Hryvinskyi\InvisibleCaptcha\Helper\Config\General;
13
use Hryvinskyi\InvisibleCaptcha\Model\Provider\AbstractFailure;
14
use Hryvinskyi\InvisibleCaptcha\Model\Provider\FailureInterface;
15
use Hryvinskyi\InvisibleCaptcha\Model\Provider\FailureMessages;
16
use Hryvinskyi\InvisibleCaptcha\Model\ReCaptcha\Response;
17
use Magento\Framework\App\Action\Action;
18
use Magento\Framework\App\ActionFlag;
19
use Magento\Framework\App\ResponseInterface;
20
use Magento\Framework\Json\EncoderInterface;
21
22
class AjaxResponseFailure extends AbstractFailure
23
{
24
    /**
25
     * @var ActionFlag
26
     */
27
    private $actionFlag;
28
29
    /**
30
     * @var EncoderInterface
31
     */
32
    private $encoder;
33
34
    /**
35
     * @var General
36
     */
37
    private $config;
38
39
    /**
40
     * AjaxResponseFailure constructor.
41
     *
42
     * @param ActionFlag $actionFlag
43
     * @param EncoderInterface $encoder
44
     * @param General $config
45
     * @param FailureMessages $failureMessages
46
     */
47
    public function __construct(
48
        ActionFlag $actionFlag,
49
        EncoderInterface $encoder,
50
        General $config,
51
        FailureMessages $failureMessages
52
    ) {
53
        $this->actionFlag = $actionFlag;
54
        $this->encoder = $encoder;
55
        $this->config = $config;
56
57
        parent::__construct($failureMessages);
58
    }
59
60
    /**
61
     * Handle captcha failure
62
     *
63
     * @param Response $verifyReCaptcha
64
     * @param ResponseInterface|null $response
65
     *
66
     * @return void
67
     */
68
    public function execute(Response $verifyReCaptcha, ResponseInterface $response = null)
69
    {
70
        $this->actionFlag->set('', Action::FLAG_NO_DISPATCH, true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of Magento\Framework\App\ActionFlag::set(). ( Ignorable by Annotation )

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

70
        $this->actionFlag->set('', Action::FLAG_NO_DISPATCH, /** @scrutinizer ignore-type */ true);
Loading history...
71
72
        $jsonPayload = $this->encoder->encode([
73
            'errors'  => true,
74
            'messages' => $this->getMessagesString($verifyReCaptcha),
75
        ]);
76
77
        $response->representJson($jsonPayload);
0 ignored issues
show
Bug introduced by
The method representJson() does not exist on Magento\Framework\App\ResponseInterface. It seems like you code against a sub-type of Magento\Framework\App\ResponseInterface such as Magento\Framework\App\Response\Http. ( Ignorable by Annotation )

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

77
        $response->/** @scrutinizer ignore-call */ 
78
                   representJson($jsonPayload);
Loading history...
Bug introduced by
The method representJson() does not exist on null. ( Ignorable by Annotation )

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

77
        $response->/** @scrutinizer ignore-call */ 
78
                   representJson($jsonPayload);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
    }
79
}
80