BooleanHandler   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 3
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseTableName() 0 3 1
A completeTable() 0 5 1
A getEqualityFieldName() 0 3 1
A getInsertValues() 0 11 3
A getEqualityFieldValue() 0 7 3
1
<?php
2
3
namespace Wikibase\QueryEngine\SQLStore\DVHandler;
4
5
use DataValues\BooleanValue;
6
use DataValues\DataValue;
7
use Doctrine\DBAL\Schema\Table;
8
use Doctrine\DBAL\Types\Type;
9
use InvalidArgumentException;
10
use Wikibase\QueryEngine\SQLStore\DataValueHandler;
11
12
/**
13
 * Represents the mapping between BooleanValue and
14
 * the corresponding table in the store.
15
 *
16
 * @since 0.1
17
 *
18
 * @licence GNU GPL v2+
19
 * @author Jeroen De Dauw < [email protected] >
20
 */
21
class BooleanHandler extends DataValueHandler {
22
23
	/**
24
	 * @see DataValueHandler::getBaseTableName
25
	 *
26
	 * @return string
27
	 */
28
	protected function getBaseTableName() {
29
		return 'boolean';
30
	}
31
32
	/**
33
	 * @see DataValueHandler::completeTable
34
	 */
35
	protected function completeTable( Table $table ) {
36
		$table->addColumn( 'value', Type::BOOLEAN );
37
38
		$table->addIndex( array( 'value' ) );
39
	}
40
41
	/**
42
	 * @see DataValueHandler::getEqualityFieldName
43
	 *
44
	 * @return string
45
	 */
46
	public function getEqualityFieldName() {
47
		return 'value';
48
	}
49
50
	/**
51
	 * @see DataValueHandler::getInsertValues
52
	 *
53
	 * @param DataValue $value
54
	 *
55
	 * @throws InvalidArgumentException
56
	 * @return array
57
	 */
58
	public function getInsertValues( DataValue $value ) {
59
		if ( !( $value instanceof BooleanValue ) ) {
60
			throw new InvalidArgumentException( 'Value is not a BooleanValue.' );
61
		}
62
63
		$values = array(
64
			'value' => $value->getValue() ? 1 : 0,
65
		);
66
67
		return $values;
68
	}
69
70
	/**
71
	 * @see DataValueHandler::getEqualityFieldValue
72
	 *
73
	 * @param DataValue $value
74
	 *
75
	 * @throws InvalidArgumentException
76
	 * @return int
77
	 */
78
	public function getEqualityFieldValue( DataValue $value ) {
79
		if ( !( $value instanceof BooleanValue ) ) {
80
			throw new InvalidArgumentException( 'Value is not a BooleanValue.' );
81
		}
82
83
		return $value->getValue() ? 1 : 0;
84
	}
85
86
}
87