Completed
Push — master ( a11cd2...d581f7 )
by mw
02:32
created

ResponsePropertyList   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 96.77%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 11
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 108
ccs 30
cts 31
cp 0.9677
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getPropertyList() 0 3 1
A findPropertyKey() 0 8 2
A hasProperty() 0 3 1
A getProperty() 0 10 2
A addToPropertyList() 0 21 4
1
<?php
2
3
namespace SEQL\ByHttpRequest;
4
5
use SEQL\DataValueDeserializer;
6
use SMW\DIProperty;
7
use SMW\DIWikiPage;
8
9
/**
10
 * @license GNU GPL v2+
11
 * @since 1.0
12
 *
13
 * @author mwjames
14
 */
15
class ResponsePropertyList {
16
17
	/**
18
	 * @var string
19
	 */
20
	private $querySource = '';
21
22
	/**
23
	 * @var array
24
	 */
25
	private $propertyList = array();
26
27
	/**
28
	 * @var array
29
	 */
30
	private $internalLabelToKeyMap = array();
31
32
	/**
33
	 * @since 1.0
34
	 *
35
	 * @param string $querySource
36
	 */
37 11
	public function __construct( $querySource ) {
38 11
		$this->querySource = $querySource;
39 11
	}
40
41
	/**
42
	 * @since 1.0
43
	 *
44
	 * @return DIProperty[]
45
	 */
46 9
	public function getPropertyList() {
47 9
		return $this->propertyList;
48
	}
49
50
	/**
51
	 * @since 1.0
52
	 *
53
	 * @param string $key
54
	 *
55
	 * @return string
56
	 */
57 10
	public function findPropertyKey( $key ) {
58
59 10
		if ( isset( $this->internalLabelToKeyMap[$key] ) ) {
60 3
			return $this->internalLabelToKeyMap[$key];
61
		}
62
63 9
		return $key;
64
	}
65
66
	/**
67
	 * @since 1.0
68
	 *
69
	 * @param string $key
70
	 *
71
	 * @return boolean
72
	 */
73 8
	public function hasProperty( $key ) {
74 8
		return isset( $this->propertyList[$this->findPropertyKey( $key )] );
75
	}
76
77
	/**
78
	 * @since 1.0
79
	 *
80
	 * @param string $key
81
	 *
82
	 * @return DIProperty|null
83
	 */
84 10
	public function getProperty( $key ) {
85
86 10
		$key = $this->findPropertyKey( $key );
87
88 10
		if ( isset( $this->propertyList[$key] ) ) {
89 10
			return $this->propertyList[$key];
90
		}
91
92
		return null;
93
	}
94
95
	/**
96
	 * @since 1.0
97
	 *
98
	 * @param array $value
99
	 */
100 10
	public function addToPropertyList( array $value ) {
101
102 10
		if ( $value['label'] === '' ) {
103 6
			return;
104
		}
105
106 10
		if ( $value['mode'] == 0 ) {
107 2
			$property = new DIProperty( '_INST' );
108 2
			$this->internalLabelToKeyMap[$value['label']] = $property->getKey();
109 2
		} else {
110 8
			$property = DIProperty::newFromUserLabel( $value['label'] );
111 8
			$property->setPropertyTypeId( $value['typeid'] );
112
		}
113
114 10
		if ( isset( $value['redi'] ) ) {
115 2
			$this->internalLabelToKeyMap[$value['redi']] = $property->getKey();
116 2
		}
117
118 10
		$property->setInterwiki( $this->querySource );
119 10
		$this->propertyList[$property->getKey()] = $property;
120 10
	}
121
122
}
123