Completed
Push — master ( 335380...3837d1 )
by mw
132:18 queued 97:45
created

Table::addOption()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\SQLStore\TableBuilder;
4
5
use RuntimeException;
6
7
/**
8
 * @private
9
 *
10
 * @license GNU GPL v2+
11
 * @since 2.5
12
 *
13
 * @author mwjames
14
 */
15
class Table {
16
17
	/**
18
	 * @var string
19
	 */
20
	private $name;
21
22
	/**
23
	 * @var array
24
	 */
25
	private $configuration = array();
26
27
	/**
28
	 * @since 2.5
29
	 *
30
	 * @param string $name
31
	 */
32
	public function __construct( $name ) {
33
		$this->name = $name;
34
	}
35
36
	/**
37
	 * @since 2.5
38
	 *
39
	 * @param string
40
	 */
41
	public function getName() {
42
		return $this->name;
43
	}
44
45
	/**
46
	 * @since 2.5
47
	 *
48
	 * @param string|null $key
49
	 *
50
	 * @param array
51
	 */
52
	public function getConfiguration( $key = null ) {
53
54
		if ( isset( $this->configuration[$key] ) ) {
55
			return  $this->configuration[$key];
56
		}
57
58
		return $this->configuration;
59
	}
60
61
	/**
62
	 * @since 2.5
63
	 *
64
	 * @param string $column
65
	 * @param string $type
66
	 */
67
	public function addColumn( $column, $type ) {
68
		$this->configuration['fields'][$column] = $type;
69
	}
70
71
	/**
72
	 * @since 2.5
73
	 *
74
	 * @param string|array $index
75
	 */
76
	public function addIndex( $index ) {
77
		$this->configuration['indicies'][] = $index;
78
	}
79
80
	/**
81
	 * @since 2.5
82
	 *
83
	 * @param string $key
84
	 * @param string|array $index
85
	 */
86
	public function addIndexWithKey( $key, $index ) {
87
		$this->configuration['indicies'][$key] = $index;
88
	}
89
90
	/**
91
	 * @since 2.5
92
	 *
93
	 * @param string $key
94
	 * @param string $option
95
	 *
96
	 * @throws RuntimeException
97
	 */
98
	public function addOption( $key, $option ) {
99
100
		if ( $key === 'fields' || $key === 'indicies' ) {
101
			throw new RuntimeException( "$key is a reserved option key." );
102
		}
103
104
		$this->configuration[$key] = $option;
105
	}
106
107
}
108