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

CIPHPUnitTestDbConnectionStore::destory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
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