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 — develop (#168)
by
unknown
10:21
created

DB.php ➔ DB()   F

Complexity

Conditions 37
Paths > 20000

Size

Total Lines 168
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 37
eloc 64
nc 25488
nop 2
dl 0
loc 168
rs 2
c 0
b 0
f 0

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
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 51 and the first side effect is on line 38.

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
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
9
 * Copyright (c) 2014 - 2015, British Columbia Institute of Technology
10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
 * copies of the Software, and to permit persons to whom the Software is
16
 * furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in
19
 * all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 *
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
32
 * @copyright	Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
33
 * @license	http://opensource.org/licenses/MIT	MIT License
34
 * @link	http://codeigniter.com
35
 * @since	Version 1.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
39
40
/**
41
 * Initialize the database
42
 *
43
 * @category	Database
44
 * @author	EllisLab Dev Team
45
 * @link	http://codeigniter.com/user_guide/database/
46
 *
47
 * @param 	string|string[]	$params
48
 * @param 	bool		$query_builder_override
49
 *				Determines if query builder should be used or not
50
 */
51
function &DB($params = '', $query_builder_override = NULL)
52
{
53
	// Load the DB config file if a DSN string wasn't passed
54
	if (is_string($params) && strpos($params, '://') === FALSE)
55
	{
56
		// Is the config file in the environment folder?
57
		if ( ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php')
58
			&& ! file_exists($file_path = APPPATH.'config/database.php'))
59
		{
60
			show_error('The configuration file database.php does not exist.');
61
		}
62
63
		include($file_path);
64
65
		// Make packages contain database config files,
66
		// given that the controller instance already exists
67
		if (class_exists('CI_Controller', FALSE))
68
		{
69
			foreach (get_instance()->load->get_package_paths() as $path)
70
			{
71
				if ($path !== APPPATH)
72
				{
73
					if (file_exists($file_path = $path.'config/'.ENVIRONMENT.'/database.php'))
74
					{
75
						include($file_path);
76
					}
77
					elseif (file_exists($file_path = $path.'config/database.php'))
78
					{
79
						include($file_path);
80
					}
81
				}
82
			}
83
		}
84
85
		if ( ! isset($db) OR count($db) === 0)
86
		{
87
			show_error('No database connection settings were found in the database config file.');
88
		}
89
90
		if ($params !== '')
91
		{
92
			$active_group = $params;
93
		}
94
95
		if ( ! isset($active_group))
96
		{
97
			show_error('You have not specified a database connection group via $active_group in your config/database.php file.');
98
		}
99
		elseif ( ! isset($db[$active_group]))
100
		{
101
			show_error('You have specified an invalid database connection group ('.$active_group.') in your config/database.php file.');
102
		}
103
104
		$params = $db[$active_group];
105
	}
106
	elseif (is_string($params))
107
	{
108
		/**
109
		 * Parse the URL from the DSN string
110
		 * Database settings can be passed as discreet
111
		 * parameters or as a data source name in the first
112
		 * parameter. DSNs must have this prototype:
113
		 * $dsn = 'driver://username:password@hostname/database';
114
		 */
115
		if (($dsn = @parse_url($params)) === FALSE)
116
		{
117
			show_error('Invalid DB Connection String');
118
		}
119
120
		$params = array(
121
			'dbdriver'	=> $dsn['scheme'],
122
			'hostname'	=> isset($dsn['host']) ? rawurldecode($dsn['host']) : '',
123
			'port'		=> isset($dsn['port']) ? rawurldecode($dsn['port']) : '',
124
			'username'	=> isset($dsn['user']) ? rawurldecode($dsn['user']) : '',
125
			'password'	=> isset($dsn['pass']) ? rawurldecode($dsn['pass']) : '',
126
			'database'	=> isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : ''
127
		);
128
129
		// Were additional config items set?
130
		if (isset($dsn['query']))
131
		{
132
			parse_str($dsn['query'], $extra);
133
134
			foreach ($extra as $key => $val)
135
			{
136
				if (is_string($val) && in_array(strtoupper($val), array('TRUE', 'FALSE', 'NULL')))
137
				{
138
					$val = var_export($val, TRUE);
139
				}
140
141
				$params[$key] = $val;
142
			}
143
		}
144
	}
145
146
	// No DB specified yet? Beat them senseless...
147
	if (empty($params['dbdriver']))
148
	{
149
		show_error('You have not selected a database type to connect to.');
150
	}
151
152
	// Load the DB classes. Note: Since the query builder class is optional
153
	// we need to dynamically create a class that extends proper parent class
154
	// based on whether we're using the query builder class or not.
155
	if ($query_builder_override !== NULL)
156
	{
157
		$query_builder = $query_builder_override;
158
	}
159
	// Backwards compatibility work-around for keeping the
160
	// $active_record config variable working. Should be
161
	// removed in v3.1
162
	elseif ( ! isset($query_builder) && isset($active_record))
163
	{
164
		$query_builder = $active_record;
165
	}
166
167
	require_once(BASEPATH.'database/DB_driver.php');
168
169
	if ( ! isset($query_builder) OR $query_builder === TRUE)
170
	{
171
		require_once(BASEPATH.'database/DB_query_builder.php');
172
		if ( ! class_exists('CI_DB', FALSE))
173
		{
174
			/**
175
			 * CI_DB
176
			 *
177
			 * Acts as an alias for both CI_DB_driver and CI_DB_query_builder.
178
			 *
179
			 * @see	CI_DB_query_builder
180
			 * @see	CI_DB_driver
181
			 */
182
			class CI_DB extends CI_DB_query_builder { }
183
		}
184
	}
185
	elseif ( ! class_exists('CI_DB', FALSE))
186
	{
187
		/**
188
	 	 * @ignore
189
		 */
190
		class CI_DB extends CI_DB_driver { }
191
	}
192
193
	// Load the DB driver
194
	$driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php';
195
196
	file_exists($driver_file) OR show_error('Invalid DB driver');
197
	require_once($driver_file);
198
199
	// Instantiate the DB adapter
200
	$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
201
	$DB = new $driver($params);
202
203
	// Check for a subdriver
204
	if ( ! empty($DB->subdriver))
205
	{
206
		$driver_file = BASEPATH.'database/drivers/'.$DB->dbdriver.'/subdrivers/'.$DB->dbdriver.'_'.$DB->subdriver.'_driver.php';
207
208
		if (file_exists($driver_file))
209
		{
210
			require_once($driver_file);
211
			$driver = 'CI_DB_'.$DB->dbdriver.'_'.$DB->subdriver.'_driver';
212
			$DB = new $driver($params);
213
		}
214
	}
215
216
	$DB->initialize();
217
	return $DB;
218
}
219