DatabaseOptions::read()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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