PropertyRegistry   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 103
ccs 45
cts 45
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 66 4
A addPropertyDefinitionFor() 0 17 2
1
<?php
2
3
namespace SIL;
4
5
use SMW\PropertyRegistry as CorePropertyRegistry;
6
7
define( 'SIL_PROP_CONTAINER', 'Has interlanguage link' );
8
9
define( 'SIL_PROP_ILL_REF', 'Interlanguage reference' );
10
define( 'SIL_PROP_ILL_LANG', 'Page content language' );
11
12
define( 'SIL_PROP_IWL_REF', 'Interwiki reference' );
13
define( 'SIL_PROP_IWL_LANG', 'Interwiki language' );
14
15
/**
16
 * @license GNU GPL v2+
17
 * @since 1.0
18
 *
19
 * @author mwjames
20
 */
21
class PropertyRegistry {
22
23
	const SIL_CONTAINER = '__sil_container';
24
25
	const SIL_ILL_LANG  = '__sil_ill_lang';
26
	const SIL_ILL_REF   = '__sil_ill_ref';
27
28
	const SIL_IWL_LANG  = '__sil_iwl_lang';
29
	const SIL_IWL_REF   = '__sil_iwl_ref';
30
31
	/**
32
	 * @since 1.0
33
	 *
34
	 * @param CorePropertyRegistry $propertyRegistry
35
	 *
36
	 * @return boolean
37
	 */
38 4
	public function register( CorePropertyRegistry $propertyRegistry ) {
39
40
		$propertyDefinitions = [
41
42 4
			self::SIL_CONTAINER => [
43 4
				'label' => SIL_PROP_CONTAINER,
44 4
				'type'  => '__sob',
45 4
				'alias' => [ wfMessage( 'sil-property-alias-container' )->text(), 'hasInterlanguagelink', 'Has interlanguage links' ],
46 4
				'msgkey' => 'sil-property-alias-container',
47
				'visibility' => false,
48
				'annotableByUser'  => false
49
			],
50
51 4
			self::SIL_ILL_LANG => [
52 4
				'label' => SIL_PROP_ILL_LANG,
53 4
				'type'  => '_txt',
54 4
				'alias' => [ wfMessage( 'sil-property-ill-alias-language' )->text() ],
55 4
				'msgkey' => 'sil-property-ill-alias-language',
56
				'visibility' => true,
57
				'annotableByUser'  => true
58
			],
59
60 4
			self::SIL_ILL_REF => [
61 4
				'label' => SIL_PROP_ILL_REF,
62 4
				'type'  => '_wpg',
63 4
				'alias' => [ wfMessage( 'sil-property-ill-alias-reference' )->text() ],
64 4
				'msgkey' => 'sil-property-ill-alias-reference',
65
				'visibility' => true,
66
				'annotableByUser'  => false
67
			],
68
69 4
			self::SIL_IWL_LANG => [
70 4
				'label' => SIL_PROP_IWL_LANG,
71 4
				'type'  => '_txt',
72 4
				'alias' => [ wfMessage( 'sil-property-iwl-alias-language' )->text() ],
73 4
				'msgkey' => 'sil-property-iwl-alias-language',
74
				'visibility' => true,
75
				'annotableByUser'  => false
76
			],
77
78 4
			self::SIL_IWL_REF => [
79 4
				'label' => SIL_PROP_IWL_REF,
80 4
				'type'  => '_wpg',
81 4
				'alias' => [ wfMessage( 'sil-property-iwl-alias-reference' )->text() ],
82 4
				'msgkey' => 'sil-property-iwl-alias-reference',
83
				'visibility' => true,
84
				'annotableByUser'  => false
85
			]
86
		];
87
88 4
		foreach ( $propertyDefinitions as $propertyId => $definition ) {
89 4
			$this->addPropertyDefinitionFor( $propertyRegistry, $propertyId, $definition  );
90
		}
91
92 4
		foreach ( $propertyDefinitions as $propertyId => $definition ) {
93
			// 2.4+
94 4
			if ( method_exists( $propertyRegistry, 'registerPropertyAliasByMsgKey' ) ) {
95 4
				$propertyRegistry->registerPropertyAliasByMsgKey(
96 4
					$propertyId,
97 4
					$definition['msgkey']
98
				);
99
			}
100
		}
101
102 4
		return true;
103
	}
104
105 4
	private function addPropertyDefinitionFor( $propertyRegistry, $propertyId, $definition ) {
106
107 4
		$propertyRegistry->registerProperty(
108 4
			$propertyId,
109 4
			$definition['type'],
110 4
			$definition['label'],
111 4
			$definition['visibility'],
112 4
			$definition['annotableByUser']
113
		);
114
115 4
		foreach ( $definition['alias'] as $alias ) {
116 4
			$propertyRegistry->registerPropertyAlias(
117 4
				$propertyId,
118
				$alias
119
			);
120
		}
121 4
	}
122
123
}
124