DatabaseOptions   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEditMode() 0 4 3
A __construct() 0 3 1
A getAdapter() 0 6 2
A getCacheMode() 0 2 1
A read() 0 2 1
1
<?php
2
namespace Maphper\DataSource;
3
class DatabaseOptions {
4
	private $db;
5
	private $options;
6
7
	public function __construct($db, $options) {
8
		$this->db = $db;
9
		$this->options = $options;
10
	}
11
12
	public function getAdapter() {
13
		if ($this->db instanceof \Maphper\DataSource) return $this->db;
14
15
		$adapter = '\\Maphper\\DataSource\\' . ucfirst($this->db->getAttribute(\PDO::ATTR_DRIVER_NAME)) . 'Adapter';
16
17
		return new $adapter($this->db);
18
	}
19
20
	public function getEditMode() {
21
		if (!isset($this->options['editmode'])) return false;
22
23
		return $this->options['editmode'] === true ? Database::EDIT_STRUCTURE | Database::EDIT_INDEX | Database::EDIT_OPTIMISE : $this->options['editmode'];
24
	}
25
26
	public function getCacheMode() {
27
		return $this->options['cachemode'] ?? true;
28
	}
29
30
	public function read($option) {
31
		return $this->options[$option] ?? false;
32
	}
33
}
34