Completed
Push — master ( ddac6b...cf6d46 )
by Kenji
03:11
created

functions.php ➔ reset_instance()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 56
Code Lines 33

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
eloc 33
nc 3
nop 0
dl 0
loc 56
rs 9.0544

How to fix   Long Method   

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
 * Part of ci-phpunit-test
4
 *
5
 * @author     Kenji Suzuki <https://github.com/kenjis>
6
 * @license    MIT License
7
 * @copyright  2015 Kenji Suzuki
8
 * @link       https://github.com/kenjis/ci-phpunit-test
9
 */
10
11
/**
12
 * Inject instance to load_class() function
13
 * 
14
 * @param string $classname
15
 * @param object $instance
16
 */
17
function load_class_instance($classname, $instance)
18
{
19
	load_class($classname, '', NULL, FALSE, $instance);
20
}
21
22
/**
23
 * Reset CodeIgniter instance
24
 */
25
function reset_instance()
26
{
27
	// Reset loaded classes
28
	load_class('', '', NULL, TRUE);
29
	is_loaded('', TRUE);
30
31
	// Reset config functions
32
	reset_config();
33
34
	// Close db connection
35
	$CI =& get_instance();
36
	if (isset($CI->db))
37
	{
38
		if (
39
			$CI->db->dsn !== 'sqlite::memory:'
40
			&& $CI->db->database !== ':memory:'
41
		)
42
		{
43
			$CI->db->close();
44
			$CI->db = null;
45
		}
46
		else
47
		{
48
			// Don't close if SQLite in-memory database
49
			// If we close it, all tables and stored data will be gone
50
			load_class_instance('db', $CI->db);
51
		}
52
	}
53
54
	// Load core classes
55
	$BM =& load_class('Benchmark', 'core');
56
	CIPHPUnitTestSuperGlobal::set_Global('BM', $BM);
57
	$EXT =& load_class('Hooks', 'core');
58
	CIPHPUnitTestSuperGlobal::set_Global('EXT', $EXT);
59
	$CFG =& load_class('Config', 'core');
60
	CIPHPUnitTestSuperGlobal::set_Global('CFG', $CFG);
61
	$UNI =& load_class('URI', 'core');
62
	CIPHPUnitTestSuperGlobal::set_Global('UNI', $UNI);
63
//	$URI =& load_class('Utf8', 'core');
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
64
//	CIPHPUnitTestSuperGlobal::set_Global('URI', $URI);
65
	$RTR =& load_class('Router', 'core');
66
	CIPHPUnitTestSuperGlobal::set_Global('RTR', $RTR);
67
	$OUT =& load_class('Output', 'core');
68
	CIPHPUnitTestSuperGlobal::set_Global('OUT', $OUT);
69
	$SEC =& load_class('Security', 'core');
70
	CIPHPUnitTestSuperGlobal::set_Global('SEC', $SEC);
71
	$IN =& load_class('Input', 'core');
72
	CIPHPUnitTestSuperGlobal::set_Global('IN', $IN);
73
	$LANG =& load_class('Lang', 'core');
74
	CIPHPUnitTestSuperGlobal::set_Global('LANG', $LANG);
75
76
	CIPHPUnitTest::loadLoader();
77
78
	// Remove CodeIgniter instance
79
	$CI = new CIPHPUnitTestNullCodeIgniter();
80
}
81
82
/**
83
 * Set return value of is_cli() function
84
 * 
85
 * @param bool $return
86
 */
87
function set_is_cli($return)
88
{
89
	is_cli($return);
0 ignored issues
show
Unused Code introduced by
The call to the function is_cli() seems unnecessary as the function has no side-effects.
Loading history...
90
}
91
92
/**
93
 * Reset config functions
94
 */
95
function reset_config()
96
{
97
	get_config([], TRUE);
98
	config_item(NULL, TRUE);
99
}
100