Completed
Pull Request — master (#322)
by
unknown
02:51
created

CIPHPUnitTestDbConnectionStore   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A destory() 0 8 2
A closeConnection() 0 9 3
A cleanUpReference() 0 13 5
1
<?php
2
3
class CIPHPUnitTestDbConnectionStore
4
{
5
	private static $connections = [];
6
7
	public static function add(CI_DB $db)
8
	{
9
		self::$connections[] = $db;
10
	}
11
12
	public static function destory()
13
	{
14
		foreach (self::$connections as $db) {
15
			self::closeConnection($db);
16
		}
17
18
		self::$connections = [];
19
	}
20
21
	public static function closeConnection(CI_DB $db)
22
	{
23
		if ($db->dsn === 'sqlite::memory:' && $db->database === ':memory:') {
24
			return;
25
		}
26
27
		self::cleanUpReference($db);
28
		$db->close();
29
	}
30
31
	private static function cleanUpReference(CI_DB $db)
32
	{
33
		if ($db->dbdriver === 'oci8') {
34
			if (is_resource($db->curs_id)) {
35
				oci_free_statement($db->curs_id);
36
			}
37
			if (is_resource($db->stmt_id)) {
38
				oci_free_statement($db->stmt_id);
39
			}
40
		} elseif ($db->dbdriver === 'pdo') {
41
			$db->result_id = null;
42
		}
43
	}
44
}
45