Completed
Push — master ( b068cc...8887b2 )
by mw
12s
created

resetTransactionProfiler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace SMW\MediaWiki;
4
5
use SMW\DBConnectionProvider;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @since 2.1
10
 *
11
 * @author mwjames
12
 */
13
class DatabaseConnectionProvider implements DBConnectionProvider {
14
15
	/**
16
	 * @var Database
17
	 */
18
	private $connection = null;
19
20
	/**
21
	 * @see DBConnectionProvider::getConnection
22
	 *
23
	 * @since 2.1
24
	 *
25
	 * @return Database
26
	 */
27 257
	public function getConnection() {
28
29 257
		if ( $this->connection === null ) {
30 225
			$this->connection = $this->createConnection();
31
		}
32
33 257
		return $this->connection;
34
	}
35
36
	/**
37
	 * @see #1499
38
	 *
39
	 * @since 2.4
40
	 */
41
	public function resetTransactionProfiler() {
42
		$this->getConnection()->resetTransactionProfiler();
43
	}
44
45
	/**
46
	 * @see DBConnectionProvider::releaseConnection
47
	 *
48
	 * @since 2.1
49
	 */
50 21
	public function releaseConnection() {
51 21
		$this->connection = null;
52 21
	}
53
54 225
	private function createConnection() {
0 ignored issues
show
Coding Style introduced by
createConnection uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
55
56 225
		$connection = new Database(
57 225
			new LazyDBConnectionProvider( DB_SLAVE ),
58 225
			new LazyDBConnectionProvider( DB_MASTER )
59
		);
60
61 225
		$connection->setDBPrefix( $GLOBALS['wgDBprefix'] );
62
63 225
		return $connection;
64
	}
65
66
}
67