GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Studioforty9_Recaptcha_Helper_Request   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 83
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setHttpClient() 0 6 1
A getHttpClient() 0 10 2
B verify() 0 26 3
A _getHelper() 0 4 1
1
<?php
2
/**
3
 * Studioforty9_Recaptcha
4
 *
5
 * @category  Studioforty9
6
 * @package   Studioforty9_Recaptcha
7
 * @author    StudioForty9 <[email protected]>
8
 * @copyright 2015 StudioForty9 (http://www.studioforty9.com)
9
 * @license   https://github.com/studioforty9/recaptcha/blob/master/LICENCE BSD
10
 * @version   1.5.7
11
 * @link      https://github.com/studioforty9/recaptcha
12
 */
13
14
/**
15
 * Studioforty9_Recaptcha_Helper_Request
16
 *
17
 * @category   Studioforty9
18
 * @package    Studioforty9_Recaptcha
19
 * @subpackage Helper
20
 * @author     StudioForty9 <[email protected]>
21
 */
22
class Studioforty9_Recaptcha_Helper_Request extends Mage_Core_Helper_Abstract
23
{
24
    const REQUEST_URL = 'https://www.google.com/recaptcha/api/siteverify';
25
    const REQUEST_RESPONSE = 'g-recaptcha-response';
26
27
    /**
28
     * @var Varien_Http_Client $_client
29
     */
30
    protected $_client;
31
32
    /**
33
     * Set the client to make the request to recaptca.
34
     *
35
     * @param Varien_Http_Client $client The http client to use
36
     *
37
     * @return $this
38
     */
39
    public function setHttpClient(Varien_Http_Client $client)
40
    {
41
        $this->_client = $client;
42
        
43
        return $this;
44
    }
45
46
    /**
47
     * Get the Http Client to use for the request to reCAPTCHA
48
     *
49
     * @return Zend_Http_Client
50
     */
51
    public function getHttpClient()
52
    {
53
        if (is_null($this->_client)) {
54
            $this->_client = new Zend_Http_Client();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Zend_Http_Client() of type object<Zend_Http_Client> is incompatible with the declared type object<Varien_Http_Client> of property $_client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
        }
56
        
57
        $this->_client->setUri(self::REQUEST_URL);
58
59
        return $this->_client;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->_client; of type Zend_Http_Client|Varien_Http_Client adds the type Varien_Http_Client to the return on line 59 which is incompatible with the return type documented by Studioforty9_Recaptcha_H..._Request::getHttpClient of type Zend_Http_Client.
Loading history...
60
    }
61
62
    /**
63
     * Verify the details of the recaptcha request.
64
     *
65
     * @return Studioforty9_Recaptcha_Helper_Response
66
     */
67
    public function verify()
68
    {
69
        $params = array(
70
            'secret'   => $this->_getHelper()->getSecretKey(),
71
            'response' => $this->_getRequest()->getPost(self::REQUEST_RESPONSE),
72
            'remoteip' => $this->_getRequest()->getClientIp(true),
73
        );
74
        
75
        $client = $this->getHttpClient();
76
        $client->setParameterPost($params);
77
        $errors = array();
78
79
        try {
80
            $response = $client->request('POST');
81
            $body = $response->getBody();
82
            $data = Mage::helper('core')->jsonDecode($body);
83
            if (array_key_exists('error-codes', $data)) {
84
                $errors = $data['error-codes'];
85
            }
86
        } catch (Exception $e) {
87
            Mage::logException($e);
88
            $data = array('success' => false);
89
        }
90
91
        return new Studioforty9_Recaptcha_Helper_Response($data['success'], $errors);
92
    }
93
94
    /**
95
     * Get the module data helper.
96
     *
97
     * @codeCoverageIgnore
98
     * @return Studioforty9_Recaptcha_Helper_Data
99
     */
100
    protected function _getHelper()
101
    {
102
        return Mage::helper('studioforty9_recaptcha');
103
    }
104
}
105