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
Push — 2.8 ( b9ed1f...cd67fa )
by Thorsten
15:59
created

Bootstrap.php ➔ pmf_error_handler()   C

Complexity

Conditions 14
Paths 97

Size

Total Lines 78
Code Lines 51

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 14
eloc 51
nc 97
nop 5
dl 0
loc 78
rs 5.1581

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Bootstrap phpMyFAQ
4
 *
5
 * PHP Version 5.3
6
 *
7
 * This Source Code Form is subject to the terms of the Mozilla Public License,
8
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
9
 * obtain one at http://mozilla.org/MPL/2.0/.
10
 *
11
 * @category  phpMyFAQ
12
 * @package   Configuration
13
 * @author    Thorsten Rinne <[email protected]>
14
 * @copyright 2012-2016 phpMyFAQ Team
15
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
16
 * @link      http://www.phpmyfaq.de
17
 * @since     2012-03-07
18
 */
19
20
use Symfony\Component\ClassLoader\UniversalClassLoader;
21
22
//
23
// Debug mode:
24
// - false      debug mode disabled
25
// - true       debug mode enabled
26
//
27
define('DEBUG', false);
28
if (DEBUG) {
29
    ini_set('display_errors', 1);
30
    ini_set('display_startup_errors', 1);
31
    error_reporting(E_ALL | E_STRICT);
32
} else {
33
    error_reporting(0);
34
}
35
36
if (!defined('IS_VALID_PHPMYFAQ')) {
37
    exit();
38
}
39
40
//
41
// Fix the PHP include path if PMF is running under a "strange" PHP configuration
42
//
43
$foundCurrPath = false;
44
$includePaths  = explode(PATH_SEPARATOR, ini_get('include_path'));
45
$i             = 0;
46
while ((!$foundCurrPath) && ($i < count($includePaths))) {
47
    if ('.' == $includePaths[$i]) {
48
        $foundCurrPath = true;
49
    }
50
    $i++;
51
}
52
if (!$foundCurrPath) {
53
    ini_set('include_path', '.' . PATH_SEPARATOR . ini_get('include_path'));
54
}
55
56
//
57
// Tweak some PHP configuration values
58
// Warning: be sure the server has enough memory and stack for PHP
59
//
60
ini_set('pcre.backtrack_limit', 100000000);
61
ini_set('pcre.recursion_limit', 100000000);
62
63
//
64
// Check if multisite/multisite.php exist for Multisite support
65
//
66
if (file_exists(__DIR__ . '/../multisite/multisite.php') && 'cli' !== PHP_SAPI) {
67
    require __DIR__ . '/../multisite/multisite.php';
68
}
69
70
//
71
// The root directory
72
//
73
if (! defined('PMF_ROOT_DIR')) {
74
    define('PMF_ROOT_DIR', dirname(__DIR__));
75
}
76
77
//
78
// Read configuration and constants
79
//
80
if (! defined('PMF_MULTI_INSTANCE_CONFIG_DIR')) {
81
    // Single instance configuration
82
    define('PMF_CONFIG_DIR', dirname(__DIR__) . '/config');
83
} else {
84
    // Multi instance configuration
85
    define('PMF_CONFIG_DIR', PMF_MULTI_INSTANCE_CONFIG_DIR);
86
}
87
88
//
89
// Check if config/database.php exist -> if not, redirect to installer
90
//
91 View Code Duplication
if (!file_exists(PMF_CONFIG_DIR . '/database.php') && !file_exists(PMF_ROOT_DIR . '/inc/data.php')) {
92
    header("Location: install/setup.php");
93
    exit();
94
}
95
96
if (file_exists(PMF_ROOT_DIR . '/inc/data.php')) {
97
    require PMF_ROOT_DIR . '/inc/data.php';
98
} else {
99
    require PMF_CONFIG_DIR . '/database.php';
100
}
101
require PMF_CONFIG_DIR . '/constants.php';
102
103
/**
104
 * The include directory
105
 */
106
define('PMF_INCLUDE_DIR', __DIR__);
107
108
/**
109
 * The directory where the translations reside
110
 */
111
define('PMF_LANGUAGE_DIR', dirname(__DIR__) . '/lang');
112
113
//
114
// Setting up PSR-0 autoloader for Symfony Components
115
//
116
require PMF_INCLUDE_DIR . '/libs/Symfony/Component/ClassLoader/UniversalClassLoader.php';
117
118
$loader = new UniversalClassLoader();
119
$loader->registerNamespace('Symfony', PMF_INCLUDE_DIR . '/libs');
120
$loader->registerPrefix('PMF_', PMF_INCLUDE_DIR);
121
$loader->register();
122
123
//
124
// Set the error handler to our pmf_error_handler() function
125
//
126
set_error_handler('pmf_error_handler');
127
128
//
129
// Create a database connection
130
//
131
PMF_Db::setTablePrefix($DB['prefix']);
132
$db = PMF_Db::factory($DB['type']);
133
$db->connect($DB['server'], $DB['user'], $DB['password'], $DB['db']);
134
135
//
136
// Fetch the configuration and add the database connection
137
//
138
$faqConfig = new PMF_Configuration($db);
139
$faqConfig->getAll();
140
141
//
142
// We always need a valid session!
143
//
144
ini_set('session.use_only_cookies', 1); // Avoid any PHP version to move sessions on URLs
145
ini_set('session.auto_start', 0);       // Prevent error to use session_start() if it's active in php.ini
146
ini_set('session.use_trans_sid', 0);
147
ini_set('url_rewriter.tags', '');
148
149
//
150
// Start the PHP session
151
//
152
PMF_Init::cleanRequest();
153
session_start();
154
155
//
156
// Connect to LDAP server, when LDAP support is enabled
157
//
158
if ($faqConfig->get('security.ldapSupport') && file_exists(PMF_CONFIG_DIR . '/ldap.php') && extension_loaded('ldap')) {
159
    require PMF_CONFIG_DIR . '/constants_ldap.php';
160
    require PMF_CONFIG_DIR . '/ldap.php';
161
    $faqConfig->setLdapConfig($PMF_LDAP);
162
} else {
163
    $ldap = null;
164
}
165
166
//
167
// Build attachments path
168
//
169
$confAttachmentsPath = trim($faqConfig->get('records.attachmentsPath'));
170
if ('/' == $confAttachmentsPath[0] || preg_match('%^[a-z]:(\\\\|/)%i', $confAttachmentsPath)) {
171
    // If we're here, some windows or unix style absolute path was detected.
172
    define('PMF_ATTACHMENTS_DIR', $confAttachmentsPath);
173
} else {
174
    // otherwise build the absolute path
175
    $tmp = dirname(__DIR__) . DIRECTORY_SEPARATOR . $confAttachmentsPath;
176
177
    // Check that nobody is traversing
178
    if (0 === strpos((string)$tmp, dirname(__DIR__))) {
179
        define('PMF_ATTACHMENTS_DIR', $tmp);
180
    } else {
181
        define('PMF_ATTACHMENTS_DIR', false);
182
    }
183
}
184
185
//
186
// Fix if phpMyFAQ is running behind a proxy server
187
//
188 View Code Duplication
if (! isset($_SERVER['HTTP_HOST'])) {
189
    if (isset($_SERVER['HTTP_X_FORWARDED_SERVER'])) {
190
        $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_SERVER'];
191
    } else {
192
        $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
193
    };
194
}
195
196
//
197
// Fix undefined server variables in Windows IIS & CGI mode
198
//
199
if (! isset($_SERVER['SCRIPT_NAME'])) {
200
    if(isset($_SERVER['SCRIPT_FILENAME'])) {
201
        $_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_FILENAME'];
202
    } elseif(isset($_SERVER['PATH_TRANSLATED'])) {
203
        $_SERVER['SCRIPT_NAME'] = $_SERVER['PATH_TRANSLATED'];
204
    } elseif(isset($_SERVER['PATH_INFO'])) {
205
        $_SERVER['SCRIPT_NAME'] = $_SERVER['PATH_INFO'];
206
    } elseif(isset($_SERVER['SCRIPT_URL'])) {
207
        $_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_URL'];
208
    }
209
}
210
211
/**
212
 * phpMyFAQ custom error handler function, also to prevent the disclosure of
213
 * potential sensitive data.
214
 *
215
 * @access public
216
 * @param  int    $level    The level of the error raised.
217
 * @param  string $message  The error message.
218
 * @param  string $filename The filename that the error was raised in.
219
 * @param  int    $line     The line number the error was raised at.
220
 * @param  mixed  $context  It optionally contains an array of every variable
221
 *                          that existed in the scope the error was triggered in.
222
 *
223
 * @return bool
224
 */
225
function pmf_error_handler($level, $message, $filename, $line, $context)
226
{
227
    // Sanity check
228
    // Note: when DEBUG mode is true we want to track any error!
229
    if (
230
        // 1. the @ operator sets the PHP's error_reporting() value to 0
231
        (!DEBUG && (0 == error_reporting()))
232
        // 2. Honor the value of PHP's error_reporting() function
233
        || (!DEBUG && (0 == ($level & error_reporting())))
234
    ) {
235
        // Do nothing
236
        return true;
237
    }
238
239
    // Cleanup potential sensitive data
240
    $filename = (DEBUG ? $filename : basename($filename));
241
242
    $errorTypes = array(
243
        E_ERROR             => 'error',
244
        E_WARNING           => 'warning',
245
        E_PARSE             => 'parse error',
246
        E_NOTICE            => 'notice',
247
        E_CORE_ERROR        => 'code error',
248
        E_CORE_WARNING      => 'core warning',
249
        E_COMPILE_ERROR     => 'compile error',
250
        E_COMPILE_WARNING   => 'compile warning',
251
        E_USER_ERROR        => 'user error',
252
        E_USER_WARNING      => 'user warning',
253
        E_USER_NOTICE       => 'user notice',
254
        E_STRICT            => 'strict warning',
255
        E_RECOVERABLE_ERROR => 'recoverable error',
256
        E_DEPRECATED        => 'deprecated warning',
257
        E_USER_DEPRECATED   => 'user deprecated warning',
258
    );
259
    $errorType = 'unknown error';
260
    if (isset($errorTypes[$level])) {
261
        $errorType = $errorTypes[$level];
262
    }
263
264
    // Custom error message
265
    $errorMessage = sprintf(
266
        '<br><strong>phpMyFAQ %s</strong> [%s]: %s in <strong>%s</strong> on line <strong>%d</strong><br>',
267
        $errorType,
268
        $level,
269
        $message,
270
        $filename,
271
        $line
272
    );
273
274
    if (ini_get('display_errors')) {
275
        print $errorMessage;
276
    }
277
    if (ini_get('log_errors')) {
278
        error_log(sprintf('phpMyFAQ %s:  %s in %s on line %d',
279
            $errorType,
280
            $message,
281
            $filename,
282
            $line)
283
        );
284
    }
285
286
    switch ($level) {
287
        // Blocking errors
288
        case E_ERROR:
289
        case E_PARSE:
290
        case E_CORE_ERROR:
291
        case E_COMPILE_ERROR:
292
        case E_USER_ERROR:
293
            // Prevent processing any more PHP scripts
294
            exit();
295
            break;
296
        // Not blocking errors
297
        default:
298
            break;
299
    }
300
301
    return true;
302
}