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 (#18)
by
unknown
11:49
created

getOtherEventsToObserve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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.2.0
11
 * @link      https://github.com/studioforty9/recaptcha
12
 */
13
14
/**
15
 * Studioforty9_Recaptcha_Helper_Data
16
 *
17
 * @category   Studioforty9
18
 * @package    Studioforty9_Recaptcha
19
 * @subpackage Helper
20
 * @author     StudioForty9 <[email protected]>
21
 */
22
class Studioforty9_Recaptcha_Helper_Data extends Mage_Core_Helper_Abstract
23
{
24
    /**#@+
25
     * Configuration paths.
26
     * @var string
27
     */
28
    const MODULE_ENABLED = 'google/recaptcha/enabled';
29
    const MODULE_ENABLED_CONTACTS = 'google/recaptcha/enabled_contacts';
30
    const MODULE_ENABLED_REVIEWS = 'google/recaptcha/enabled_reviews';
31
    const MODULE_ENABLED_SENDFRIEND = 'google/recaptcha/enabled_sendfriend';
32
    const MODULE_ENABLED_CUSTOMER_REG = 'google/recaptcha/enabled_customer_registration';
33
    const MODULE_OTHER_EVENTS_TO_OBSERVE = 'google/recaptcha/other_events_to_observe';
34
    const MODULE_KEY_SITE = 'google/recaptcha/site_key';
35
    const MODULE_KEY_SECRET = 'google/recaptcha/secret_key';
36
    const MODULE_KEY_THEME = 'google/recaptcha/theme';
37
    /**#@-*/
38
39
    /**
40
     * Is the module enabled in configuration.
41
     *
42
     * @codeCoverageIgnore
43
     * @return bool
44
     */
45
    public function isEnabled()
46
    {
47
        return Mage::getStoreConfigFlag(self::MODULE_ENABLED);
48
    }
49
50
    /**
51
     * Is the recaptcha enabled on the contacts form.
52
     *
53
     * @codeCoverageIgnore
54
     * @return bool
55
     */
56
    public function isContactsEnabled()
57
    {
58
        return Mage::getStoreConfigFlag(self::MODULE_ENABLED_CONTACTS);
59
    }
60
61
    /**
62
     * Is the recaptcha enabled on the product review form.
63
     *
64
     * @codeCoverageIgnore
65
     * @return bool
66
     */
67
    public function isReviewsEnabled()
68
    {
69
        return Mage::getStoreConfigFlag(self::MODULE_ENABLED_REVIEWS);
70
    }
71
72
    /**
73
     * Is the recaptcha enabled on the product send to friend form.
74
     *
75
     * @codeCoverageIgnore
76
     * @return bool
77
     */
78
    public function isSendFriendEnabled()
79
    {
80
        return Mage::getStoreConfigFlag(self::MODULE_ENABLED_SENDFRIEND);
81
    }
82
83
    /**
84
     * Is the recaptcha enabled on the customer registration form.
85
     *
86
     * @codeCoverageIgnore
87
     * @return bool
88
     */
89
    public function isCustomerRegistrationEnabled()
90
    {
91
        return Mage::getStoreConfigFlag(self::MODULE_ENABLED_CUSTOMER_REG);
92
    }
93
94
    /**
95
     * The recaptcha site key.
96
     *
97
     * @codeCoverageIgnore
98
     * @return string
99
     */
100
    public function getSiteKey()
101
    {
102
        return Mage::getStoreConfig(self::MODULE_KEY_SITE);
103
    }
104
105
    /**
106
     * The recaptcha secret key.
107
     *
108
     * @codeCoverageIgnore
109
     * @return string
110
     */
111
    public function getSecretKey()
112
    {
113
        return Mage::getStoreConfig(self::MODULE_KEY_SECRET);
114
    }
115
116
    /**
117
     * The recaptcha widget theme.
118
     *
119
     * @codeCoverageIgnore
120
     * @return string
121
     */
122
    public function getTheme()
123
    {
124
        return Mage::getStoreConfig(self::MODULE_KEY_THEME);
125
    }
126
127
    /**
128
     * Get the redirect URL.
129
     *  - no visitor_data or last_url stored in core/session
130
     *      return the base_url
131
     *  - no visitor_data but last_url is stored in core/session
132
     *      return the last_url
133
     *  - visitor_data exists but request_uri does not, but last_url is stored in core/session
134
     *      return the last_url
135
     * - request_uri exists
136
     *      return the request_uri
137
     *
138
     * @todo Unit Test this method.
139
     * @return string
140
     */
141
    public function getRedirectUrl()
142
    {
143
        $_session = Mage::getSingleton('core/session');
144
145
        if (! $_session->hasVisitorData() && !$_session->hasLastUrl()) {
146
            return Mage::getBaseUrl();
147
        }
148
149
        if (! $_session->hasVisitorData() && $_session->hasLastUrl()) {
150
            return $_session->getLastUrl();
151
        }
152
153
        $visitorData = $_session->getVisitorData();
154
        if (! array_key_exists('request_uri', $visitorData) && $_session->hasLastUrl()) {
155
            return $_session->getLastUrl();
156
        }
157
158
        return $visitorData['request_uri'];
159
    }
160
161
    /**
162
     * @codeCoverageIgnore
163
     * @return array
164
     */
165
    public function getOtherEventsToObserve()
166
    {
167
        return array_map('trim', explode(PHP_EOL, Mage::getStoreConfig(self::MODULE_OTHER_EVENTS_TO_OBSERVE)));
168
    }
169
170
    /**
171
     * Is the module allowed to run.
172
     *
173
     * @todo Unit Test this method.
174
     * @param Mage_Core_Controller_Request_Http $request
175
     * @return bool
176
     */
177
    public function isAllowed(Mage_Core_Controller_Request_Http $request)
178
    {
179
        if (! Mage::getConfig()->getModuleConfig("Studioforty9_Recaptcha")->is('active', 'true')) {
180
            return false;
181
        }
182
183
        $route = $request->getModuleName();
184
185
        $fullName = $route . '_' . $request->getControllerName() . '_' . $request->getActionName();
186
        
187
        $acl = array(
188
            'contacts'   => $this->isContactsEnabled(),
189
            'review'     => $this->isReviewsEnabled(),
190
            'customer'   => $this->isCustomerRegistrationEnabled(),
191
            'sendfriend' => $this->isSendFriendEnabled()
192
        );
193
194
        return (
195
            $this->isEnabled() &&
196
            (
197
                in_array($fullName, $this->getOtherEventsToObserve()) ||
198
                array_key_exists($route, $acl) && $acl[$route] === true
199
            )
200
        );
201
    }
202
}
203