Completed
Push — master ( 2a7c05...7c1d68 )
by Michael
02:50
created

XoopsGTicket   C

Complexity

Total Complexity 60

Size/Duplication

Total Lines 389
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 389
rs 6.0975
c 0
b 0
f 0
wmc 60
lcom 1
cbo 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 27 6
A getTicketHtml() 0 4 1
A getTicketXoopsForm() 0 4 1
A addTicketXoopsFormElement() 0 4 1
A getTicketArray() 0 6 1
A getTicketParamString() 0 4 2
D issue() 0 45 10
F check() 0 85 19
C renderRepostForm() 0 48 8
B extractPostRecursive() 0 26 5
A clear() 0 4 1
A using() 0 8 2
A getErrors() 0 13 3

How to fix   Complexity   

Complex Class

Complex classes like XoopsGTicket often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use XoopsGTicket, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 33 and the first side effect is on line 439.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
use Xmf\Request;
24
25
// GIJOE's Ticket Class (based on Marijuana's Oreteki XOOPS)
26
// nobunobu's suggestions are applied
27
28
if (!class_exists('XoopsGTicket')) {
29
30
    /**
31
     * Class XoopsGTicket
32
     */
33
    class XoopsGTicket
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
34
    {
35
        public $_errors       = array();
36
        public $_latest_token = '';
37
        public $messages      = array();
38
39
        /**
40
         * XoopsGTicket constructor.
41
         */
42
        public function __construct()
43
        {
44
            global $xoopsConfig;
45
46
            // language file
47
            if (defined('XOOPS_ROOT_PATH') && !empty($xoopsConfig['language'])
48
                && false === strpos($xoopsConfig['language'], '/')
49
            ) {
50
                if (file_exists(dirname(__DIR__) . "/language/{$xoopsConfig['language']}/gticket_messages.phtml")) {
51
                    include dirname(__DIR__) . "/language/{$xoopsConfig['language']}/gticket_messages.phtml";
52
                }
53
            }
54
55
            // default messages
56
            if (empty($this->messages)) {
57
                $this->messages = array(
58
                    'err_general'       => 'GTicket Error',
59
                    'err_nostubs'       => 'No stubs found',
60
                    'err_noticket'      => 'No ticket found',
61
                    'err_nopair'        => 'No valid ticket-stub pair found',
62
                    'err_timeout'       => 'Time out',
63
                    'err_areaorref'     => 'Invalid area or referer',
64
                    'fmt_prompt4repost' => 'error(s) found:<br><span style="background-color:red;font-weight:bold;color:white;">%s</span><br>Confirm it.<br>And do you want to post again?',
65
                    'btn_repost'        => 'repost'
66
                );
67
            }
68
        }
69
70
        // render form as plain html
71
72
        /**
73
         * @param string $salt
74
         * @param int    $timeout
75
         * @param string $area
76
         *
77
         * @return string
78
         */
79
        public function getTicketHtml($salt = '', $timeout = 1800, $area = '')
80
        {
81
            return '<input type="hidden" name="XOOPS_G_TICKET" value="' . $this->issue($salt, $timeout, $area) . '" >';
82
        }
83
84
        // returns an object of XoopsFormHidden including theh ticket
85
86
        /**
87
         * @param string $salt
88
         * @param int    $timeout
89
         * @param string $area
90
         *
91
         * @return XoopsFormHidden
92
         */
93
        public function getTicketXoopsForm($salt = '', $timeout = 1800, $area = '')
94
        {
95
            return new XoopsFormHidden('XOOPS_G_TICKET', $this->issue($salt, $timeout, $area));
96
        }
97
98
        // add a ticket as Hidden Element into XoopsForm
99
100
        /**
101
         * @param        $form
102
         * @param string $salt
103
         * @param int    $timeout
104
         * @param string $area
105
         */
106
        public function addTicketXoopsFormElement(&$form, $salt = '', $timeout = 1800, $area = '')
107
        {
108
            $form->addElement(new XoopsFormHidden('XOOPS_G_TICKET', $this->issue($salt, $timeout, $area)));
109
        }
110
111
        // returns an array for xoops_confirm() ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
112
113
        /**
114
         * @param string $salt
115
         * @param int    $timeout
116
         * @param string $area
117
         *
118
         * @return array
119
         */
120
        public function getTicketArray($salt = '', $timeout = 1800, $area = '')
121
        {
122
            return array(
123
                'XOOPS_G_TICKET' => $this->issue($salt, $timeout, $area)
124
            );
125
        }
126
127
        // return GET parameter string.
128
129
        /**
130
         * @param string $salt
131
         * @param bool   $noamp
132
         * @param int    $timeout
133
         * @param string $area
134
         *
135
         * @return string
136
         */
137
        public function getTicketParamString($salt = '', $noamp = false, $timeout = 1800, $area = '')
138
        {
139
            return ($noamp ? '' : '&amp;') . 'XOOPS_G_TICKET=' . $this->issue($salt, $timeout, $area);
140
        }
141
142
        // issue a ticket
143
144
        /**
145
         * @param string $salt
146
         * @param int    $timeout
147
         * @param string $area
148
         *
149
         * @return string
150
         */
151
        public function issue($salt = '', $timeout = 1800, $area = '')
0 ignored issues
show
Coding Style introduced by
issue uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
issue uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
152
        {
153
            global $xoopsModule;
154
155
            if ('' === $salt) {
156
                if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) {
157
                    // $salt = '$2y$07$' . strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
158
                    $salt = '$2y$07$' . str_replace('+', '.', base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)));
159
                }
160
            }
161
162
            // create a token
163
            list($usec, $sec) = explode(' ', microtime());
164
            $appendix_salt       = empty($_SERVER['PATH']) ? XOOPS_DB_NAME : $_SERVER['PATH'];
165
            $token               = crypt($salt . $usec . $appendix_salt . $sec, $salt);
166
            $this->_latest_token = $token;
167
168
            if (empty($_SESSION['XOOPS_G_STUBS'])) {
169
                $_SESSION['XOOPS_G_STUBS'] = array();
170
            }
171
172
            // limit max stubs 10
173
            if (count($_SESSION['XOOPS_G_STUBS']) > 10) {
174
                $_SESSION['XOOPS_G_STUBS'] = array_slice($_SESSION['XOOPS_G_STUBS'], -10);
175
            }
176
177
            // record referer if browser send it
178
            $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['REQUEST_URI'];
179
180
            // area as module's dirname
181
            if (!$area && ($xoopsModule instanceof XoopsModule)) {
0 ignored issues
show
Bug introduced by
The class XoopsModule does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
182
                $area = $xoopsModule->getVar('dirname');
183
            }
184
185
            // store stub
186
            $_SESSION['XOOPS_G_STUBS'][] = array(
187
                'expire'  => time() + $timeout,
188
                'referer' => $referer,
189
                'area'    => $area,
190
                'token'   => $token
191
            );
192
193
            // paid md5ed token as a ticket
194
            return md5($token . XOOPS_DB_PREFIX);
195
        }
196
197
        // check a ticket
198
199
        /**
200
         * @param bool   $post
201
         * @param string $area
202
         * @param bool   $allow_repost
203
         *
204
         * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be null|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
205
         */
206
        public function check($post = true, $area = '', $allow_repost = true)
0 ignored issues
show
Coding Style introduced by
check uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
check uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
207
        {
208
            global $xoopsModule;
209
210
            $this->_errors = array();
211
212
            // CHECK: stubs are not stored in session
213
            if (!is_array(@$_SESSION['XOOPS_G_STUBS'])) {
214
                $this->_errors[]           = $this->messages['err_nostubs'];
215
                $_SESSION['XOOPS_G_STUBS'] = array();
216
            }
217
218
            // get key&val of the ticket from a user's query
219
            $ticket = $post ? @Request::getString('XOOPS_G_TICKET', '', 'POST') : @Request::getString('XOOPS_G_TICKET', '', 'GET');
220
221
            // CHECK: no tickets found
222
            if (empty($ticket)) {
223
                $this->_errors[] = $this->messages['err_noticket'];
224
            }
225
226
            // gargage collection & find a right stub
227
            $stubs_tmp                 = $_SESSION['XOOPS_G_STUBS'];
228
            $_SESSION['XOOPS_G_STUBS'] = array();
229
            foreach ($stubs_tmp as $stub) {
230
                // default lifetime 30min
231
                if ($stub['expire'] >= time()) {
232
                    if (md5($stub['token'] . XOOPS_DB_PREFIX) === $ticket) {
233
                        $found_stub = $stub;
234
                    } else {
235
                        // store the other valid stubs into session
236
                        $_SESSION['XOOPS_G_STUBS'][] = $stub;
237
                    }
238
                } else {
239
                    if (md5($stub['token'] . XOOPS_DB_PREFIX) === $ticket) {
240
                        // not CSRF but Time-Out
241
                        $timeout_flag = true;
242
                    }
243
                }
244
            }
245
246
            // CHECK: the right stub found or not
247
            if (empty($found_stub)) {
248
                if (empty($timeout_flag)) {
249
                    $this->_errors[] = $this->messages['err_nopair'];
250
                } else {
251
                    $this->_errors[] = $this->messages['err_timeout'];
252
                }
253
            } else {
254
                // set area if necessary
255
                // area as module's dirname
256
                if (!$area && ($xoopsModule instanceof XoopsModule)) {
0 ignored issues
show
Bug introduced by
The class XoopsModule does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
257
                    $area = $xoopsModule->getVar('dirname');
258
                }
259
260
                // check area or referer
261
                if (@$found_stub['area'] == $area) {
262
                    $area_check = true;
263
                }
264
                if (!empty($found_stub['referer'])
265
                    && true === strpos(@$_SERVER['HTTP_REFERER'], $found_stub['referer'])
266
                ) {
267
                    $referer_check = true;
268
                }
269
270
                if (empty($area_check) && empty($referer_check)) { // loose
271
                    $this->_errors[] = $this->messages['err_areaorref'];
272
                }
273
            }
274
275
            if (!empty($this->_errors)) {
276
                if ($allow_repost) {
277
                    // repost form
278
                    $this->renderRepostForm($area);
279
                    exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method check() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
280
                } else {
281
                    // failed
282
                    $this->clear();
283
284
                    return false;
285
                }
286
            } else {
287
                // all green
288
                return true;
289
            }
290
        }
291
292
        // draw form for repost
293
294
        /**
295
         * @param string $area
296
         */
297
        public function renderRepostForm($area = '')
0 ignored issues
show
Coding Style introduced by
renderRepostForm uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
renderRepostForm uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
298
        {
299
            // Notify which file is broken
300
            if (headers_sent()) {
301
                restore_error_handler();
302
                set_error_handler('GTicket_ErrorHandler4FindOutput');
303
                header('Dummy: for warning');
304
                restore_error_handler();
305
                exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method renderRepostForm() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
306
            }
307
308
            error_reporting(0);
309
            while (ob_get_level()) {
310
                ob_end_clean();
311
            }
312
313
            $table = '<table>';
314
            $form  = '<form action="?' . htmlspecialchars(@$_SERVER['QUERY_STRING'], ENT_QUOTES) . '" method="post" >';
315
            foreach ($_POST as $key => $val) {
316
                if ($key === 'XOOPS_G_TICKET') {
317
                    continue;
318
                }
319
                if (get_magic_quotes_gpc()) {
320
                    $key = stripslashes($key);
321
                }
322
                if (is_array($val)) {
323
                    list($tmp_table, $tmp_form) = $this->extractPostRecursive(htmlspecialchars($key, ENT_QUOTES), $val);
324
                    $table .= $tmp_table;
325
                    $form  .= $tmp_form;
326
                } else {
327
                    if (get_magic_quotes_gpc()) {
328
                        $val = stripslashes($val);
329
                    }
330
                    $table .= '<tr><th>' . htmlspecialchars($key, ENT_QUOTES) . '</th><td>' . htmlspecialchars($val, ENT_QUOTES) . '</td></tr>' . "\n";
331
                    $form  .= '<input type="hidden" name="' . htmlspecialchars($key, ENT_QUOTES) . '" value="' . htmlspecialchars($val, ENT_QUOTES) . '" >' . "\n";
332
                }
333
            }
334
            $table .= '</table>';
335
            $form  .= $this->getTicketHtml(__LINE__, 300, $area) . '<input type="submit" value="' . $this->messages['btn_repost'] . '" ></form>';
336
337
            echo '<html><head><title>'
338
                 . $this->messages['err_general']
339
                 . '</title><style>table,td,th {border:solid black 1px; border-collapse:collapse;}</style></head><body>'
340
                 . sprintf($this->messages['fmt_prompt4repost'], $this->getErrors())
341
                 . $table
342
                 . $form
343
                 . '</body></html>';
344
        }
345
346
        /**
347
         * @param $key_name
348
         * @param $tmp_array
349
         *
350
         * @return array
351
         */
352
        public function extractPostRecursive($key_name, $tmp_array)
353
        {
354
            $table = '';
355
            $form  = '';
356
            foreach ($tmp_array as $key => $val) {
357
                if (get_magic_quotes_gpc()) {
358
                    $key = stripslashes($key);
359
                }
360
                if (is_array($val)) {
361
                    list($tmp_table, $tmp_form) = $this->extractPostRecursive($key_name . '[' . htmlspecialchars($key, ENT_QUOTES) . ']', $val);
362
                    $table .= $tmp_table;
363
                    $form  .= $tmp_form;
364
                } else {
365
                    if (get_magic_quotes_gpc()) {
366
                        $val = stripslashes($val);
367
                    }
368
                    $table .= '<tr><th>' . $key_name . '[' . htmlspecialchars($key, ENT_QUOTES) . ']</th><td>' . htmlspecialchars($val, ENT_QUOTES) . '</td></tr>' . "\n";
369
                    $form  .= '<input type="hidden" name="' . $key_name . '[' . htmlspecialchars($key, ENT_QUOTES) . ']" value="' . htmlspecialchars($val, ENT_QUOTES) . '" >' . "\n";
370
                }
371
            }
372
373
            return array(
374
                $table,
375
                $form
376
            );
377
        }
378
379
        // clear all stubs
380
        public function clear()
0 ignored issues
show
Coding Style introduced by
clear uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
381
        {
382
            $_SESSION['XOOPS_G_STUBS'] = array();
383
        }
384
385
        // Ticket Using
386
387
        /**
388
         * @return bool
389
         */
390
        public function using()
0 ignored issues
show
Coding Style introduced by
using uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
391
        {
392
            if (!empty($_SESSION['XOOPS_G_STUBS'])) {
393
                return true;
394
            } else {
395
                return false;
396
            }
397
        }
398
399
        // return errors
400
401
        /**
402
         * @param bool $ashtml
403
         *
404
         * @return array|string
405
         */
406
        public function getErrors($ashtml = true)
407
        {
408
            if ($ashtml) {
409
                $ret = '';
410
                foreach ($this->_errors as $msg) {
411
                    $ret .= "$msg<br>\n";
412
                }
413
            } else {
414
                $ret = $this->_errors;
415
            }
416
417
            return $ret;
418
        }
419
420
        // end of class
421
    }
422
423
    /**
424
     * @param $errNo
425
     * @param $errStr
426
     * @param $errFile
427
     * @param $errLine
428
     */
429
    function GTicket_ErrorHandler4FindOutput($errNo, $errStr, $errFile, $errLine)
0 ignored issues
show
Unused Code introduced by
The parameter $errNo is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errFile is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errLine is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
430
    {
431
        if (preg_match('?' . preg_quote(XOOPS_ROOT_PATH) . '([^:]+)\:(\d+)?', $errStr, $regs)) {
432
            echo 'Irregular output! check the file ' . htmlspecialchars($regs[1]) . ' line ' . htmlspecialchars($regs[2]);
433
        } else {
434
            echo 'Irregular output! check language files etc.';
435
        }
436
    }
437
438
    // create a instance in global scope
439
    $GLOBALS['xoopsGTicket'] = new XoopsGTicket();
440
}
441
442
if (!function_exists('admin_refcheck')) {
443
444
    //Admin Referer Check By Marijuana(Rev.011)
445
    /**
446
     * @param string $chkref
447
     *
448
     * @return bool
449
     */
450
    function admin_refcheck($chkref = '')
0 ignored issues
show
Coding Style introduced by
admin_refcheck uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
451
    {
452
        if (empty($_SERVER['HTTP_REFERER'])) {
453
            return true;
454
        } else {
455
            $ref = $_SERVER['HTTP_REFERER'];
456
        }
457
        $cr = XOOPS_URL;
458
        if ('' != $chkref) {
459
            $cr .= $chkref;
460
        }
461
        if (0 !== strpos($ref, $cr)) {
462
            return false;
463
        }
464
465
        return true;
466
    }
467
}
468