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

ObserverRedirectFailure::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 10
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
namespace Hryvinskyi\InvisibleCaptcha\Model\Provider\Failure;
9
10
use Hryvinskyi\InvisibleCaptcha\Helper\Config\General;
11
use Hryvinskyi\InvisibleCaptcha\Model\Provider\AbstractFailure;
12
use Hryvinskyi\InvisibleCaptcha\Model\Provider\FailureMessages;
13
use Hryvinskyi\InvisibleCaptcha\Model\ReCaptcha\Response;
14
use Magento\Framework\App\Action\Action;
15
use Magento\Framework\App\ActionFlag;
16
use Magento\Framework\App\ResponseInterface;
17
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface;
18
use Magento\Framework\UrlInterface;
19
20
class ObserverRedirectFailure extends AbstractFailure
21
{
22
    /**
23
     * @var MessageManagerInterface
24
     */
25
    private $messageManager;
26
27
    /**
28
     * @var ActionFlag
29
     */
30
    private $actionFlag;
31
32
    /**
33
     * @var General
34
     */
35
    private $config;
36
37
    /**
38
     * @var RedirectUrlInterface
39
     */
40
    private $redirectUrlProvider;
41
42
    /**
43
     * @var UrlInterface
44
     */
45
    private $url;
46
47
    /**
48
     * RedirectFailure constructor.
49
     *
50
     * @param MessageManagerInterface $messageManager
51
     * @param ActionFlag $actionFlag
52
     * @param General $config
53
     * @param UrlInterface $url
54
     * @param FailureMessages $failureMessages
55
     * @param RedirectUrlInterface|null $redirectUrlProvider
56
     */
57
    public function __construct(
58
        MessageManagerInterface $messageManager,
59
        ActionFlag $actionFlag,
60
        General $config,
61
        UrlInterface $url,
62
        FailureMessages $failureMessages,
63
        RedirectUrlInterface $redirectUrlProvider = null
64
    ) {
65
        $this->messageManager = $messageManager;
66
        $this->actionFlag = $actionFlag;
67
        $this->config = $config;
68
        $this->redirectUrlProvider = $redirectUrlProvider;
69
        $this->url = $url;
70
71
        parent::__construct($failureMessages);
72
    }
73
74
    /**
75
     * Get redirect URL
76
     *
77
     * @return string
78
     */
79
    private function getUrl()
80
    {
81
        return $this->redirectUrlProvider->getRedirectUrl();
82
    }
83
84
    /**
85
     * Handle captcha failure
86
     *
87
     * @param Response $verifyReCaptcha
88
     * @param ResponseInterface $response
89
     *
90
     * @return void
91
     */
92
    public function execute(Response $verifyReCaptcha, ResponseInterface $response = null)
93
    {
94
        $this->messageManager->addErrorMessage($this->getMessagesString($verifyReCaptcha));
95
        $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

95
        $this->actionFlag->set('', Action::FLAG_NO_DISPATCH, /** @scrutinizer ignore-type */ true);
Loading history...
96
97
        $response->setRedirect($this->getUrl());
0 ignored issues
show
Bug introduced by
The method setRedirect() 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

97
        $response->/** @scrutinizer ignore-call */ 
98
                   setRedirect($this->getUrl());

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...
Bug introduced by
The method setRedirect() 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\HttpInterface. ( Ignorable by Annotation )

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

97
        $response->/** @scrutinizer ignore-call */ 
98
                   setRedirect($this->getUrl());
Loading history...
98
    }
99
}
100