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.
Completed
Pull Request — master (#31)
by
unknown
14:25
created

Studioforty9_Recaptcha_Block_Explicit   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 185
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A isAllowed() 0 8 2
A getSiteKey() 0 4 1
A getTheme() 0 4 1
A getType() 0 4 1
A getSize() 0 4 1
B getRecaptchaScript() 0 26 4
A getRecaptchaId() 0 4 1
A _getHelper() 0 4 1
A shouldCallScript() 0 13 3
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_Block_Explicit
16
 *
17
 * @category   Studioforty9
18
 * @package    Studioforty9_Recaptcha
19
 * @subpackage Block
20
 */
21
class Studioforty9_Recaptcha_Block_Explicit extends Mage_Core_Block_Template
22
{
23
    protected $_languages = array(
24
        'ar_DZ|ar_SA|ar_KW|ar_MA|ar_EG|az_AZ|' => 'ar',
25
        'bg_BG' => 'bg',
26
        'ca_ES' => 'ca',
27
        'zh_CN' => 'zh-CN',
28
        'zh_HK|zh_TW' => 'zh-TW',
29
        'hr_HR' => 'hr',
30
        'cs_CZ' => 'cs',
31
        'da_DK' => 'da',
32
        'nl_NL' => 'nl',
33
        'en_GB|en_AU|en_NZ|en_IE|cy_GB' => 'en-GB',
34
        'en_US|en_CA' => 'en',
35
        'fil_PH' => 'fil',
36
        'fi_FI' => 'fi',
37
        'fr_FR' => 'fr',
38
        'fr_CA' => 'fr-CA',
39
        'de_DE' => 'de',
40
        'de_AT)' => 'de-AT',
41
        'de_CH' => 'de-CH',
42
        'el_GR' => 'el',
43
        'he_IL' => 'iw',
44
        'hi_IN' => 'hi',
45
        'hu_HU' => 'hu',
46
        'gu_IN|id_ID' => 'id',
47
        'it_IT|it_CH' => 'it',
48
        'ja_JP' => 'ja',
49
        'ko_KR' => 'ko',
50
        'lv_LV' => 'lv',
51
        'lt_LT' => 'lt',
52
        'nb_NO' => 'no',
53
        'fa_IR' => 'fa',
54
        'pl_PL' => 'pl',
55
        'pt_BR' => 'pt-BR',
56
        'pt_PT' => 'pt-PT',
57
        'ro_RO' => 'ro',
58
        'ru_RU' => 'ru',
59
        'sr_RS' => 'sr',
60
        'sk_SK' => 'sk',
61
        'sl_SI' => 'sl',
62
        'es_ES|gl_ES' => 'es',
63
        'es_AR|es_CL|es_CO|es_CR|es_MX|es_PA|es_PE|es_VE' => 'es-419',
64
        'sv_SE' => 'sv',
65
        'th_TH' => 'th',
66
        'tr_TR' => 'tr',
67
        'uk_UA' => 'uk',
68
        'vi_VN' => 'vi'
69
    );
70
    
71
    /**
72
     * @var
73
     */
74
    protected $_shouldCallScript = null;
75
76
    /**
77
     * Is the block allowed to display.
78
     *
79
     * @param string $route
80
     * @return bool
81
     */
82
    public function isAllowed($route = '')
83
    {
84
        if ($this->hasData('allow')) {
85
            return (bool) $this->getData('allow');
86
        }
87
88
        return $this->_getHelper()->isAllowed($route);
89
    }
90
91
    /**
92
     * Get the recaptcha site key.
93
     *
94
     * @codeCoverageIgnore
95
     * @return string
96
     */
97
    public function getSiteKey()
98
    {
99
        return $this->_getHelper()->getSiteKey();
100
    }
101
102
    /**
103
     * Get the recaptcha theme setting.
104
     *
105
     * @codeCoverageIgnore
106
     * @return string
107
     */
108
    public function getTheme()
109
    {
110
        return $this->_getHelper()->getTheme();
111
    }
112
113
    /**
114
     * Get the recaptcha type setting.
115
     *
116
     * @codeCoverageIgnore
117
     * @return string
118
     */
119
    public function getType()
120
    {
121
        return $this->_getHelper()->getType();
122
    }
123
124
    /**
125
     * Get the recaptcha size setting.
126
     *
127
     * @codeCoverageIgnore
128
     * @return string
129
     */
130
    public function getSize()
131
    {
132
        return $this->_getHelper()->getSize();
133
    }
134
135
    /**
136
     * Get the reCAPTACHA javascript code.
137
     *
138
     * @return string
139
     */
140
    public function getRecaptchaScript()
141
    {
142
        if (! $this->_getHelper()->isEnabled()) {
143
            return '';
144
        }
145
146
        $language = Mage::app()->getLocale()->getLocale()->toString();
147
        $lang = 'en';
148
149
        foreach ($this->_languages as $options => $_lang) {
150
            if (stristr($options, $language)) {
151
                $lang = $_lang;
152
            }
153
        }
154
155
        $query = array(
156
            'onload' => 'onloadCallback',
157
            'render' => 'explicit',
158
            'hl'     => $lang
159
        );
160
161
        return sprintf(
162
            '<script src="https://www.google.com/recaptcha/api.js?%s" async defer></script>',
163
            http_build_query($query)
164
        );
165
    }
166
167
    /**
168
     * Get a unique ID for the recaptcha block.
169
     *
170
     * @return string
171
     */
172
    public function getRecaptchaId()
173
    {
174
        return uniqid();
175
    }
176
177
    /**
178
     * Get the recaptcha helper.
179
     *
180
     * @return Studioforty9_Recaptcha_Helper_Data
181
     */
182
    protected function _getHelper()
183
    {
184
        return Mage::helper('studioforty9_recaptcha');
185
    }
186
187
    /**
188
     * Should we call the script again ?
189
     *
190
     * @return bool
191
     */
192
    public function shouldCallScript()
193
    {
194
        if (is_null($this->_shouldCallScript)) {
195
            if (Mage::getSingleton('studioforty9_recaptcha/counter')->getCount()) {
196
                $this->_shouldCallScript = false;
197
            } else {
198
                Mage::getSingleton('studioforty9_recaptcha/counter')->increase();
199
                $this->_shouldCallScript = true;
200
            }
201
        }
202
203
        return $this->_shouldCallScript;
204
    }
205
}
206