Completed
Push — refact-v2 ( f926b0...ed207f )
by mw
02:37
created

PropertyRegistry   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 85.45%

Importance

Changes 0
Metric Value
dl 0
loc 120
ccs 47
cts 55
cp 0.8545
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B registerAsFixedProperties() 0 28 5
B addPropertyDefinition() 0 35 4
B registerOn() 0 24 5
1
<?php
2
3
namespace SESP;
4
5
use SMW\PropertyRegistry as BasePropertyRegistry;
6
use SMW\DataTypeRegistry;
7
use SMW\DIProperty;
8
use SMW\Message;
9
use SMWDataItem as DataItem;
10
11
/**
12
 * @ingroup SESP
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
19
class PropertyRegistry {
20
21
	/**
22
	 * @var AppFactory
23
	 */
24
	private $appFactory;
25
26
	/**
27
	 * @since 2.0
28
	 *
29
	 * @param AppFactory $appFactory
30
	 */
31 6
	public function __construct( AppFactory $appFactory ) {
32 6
		$this->appFactory = $appFactory;
33 6
	}
34
35
	/**
36
	 * @since 1.0
37
	 *
38
	 * @param PropertyRegistry $propertyRegistry
39
	 *
40
	 * @return boolean
41
	 */
42 3
	public function registerOn( BasePropertyRegistry $propertyRegistry ) {
43
44 3
		$definitions = $this->appFactory->getPropertyDefinitions();
45
46 3
		foreach ( $definitions as $key => $definition ) {
47
48 2
			if ( !isset( $definition['id'] ) ) {
49 1
				continue;
50
			}
51
52 1
			$this->addPropertyDefinition( $propertyRegistry, $definition );
53 3
		}
54
55 3
		foreach ( $definitions->safeGet( '_EXIF', array() ) as $key => $definition ) {
56
57 1
			if ( !isset( $definition['id'] ) ) {
58
				continue;
59
			}
60
61 1
			$this->addPropertyDefinition( $propertyRegistry, $definition );
62 3
		}
63
64 3
		return true;
65
	}
66
67
	/**
68
	 * @since 2.0
69
	 *
70
	 * @param array $customFixedProperties
71
	 * @param array $fixedPropertyTablePrefix
72
	 */
73 2
	public function registerAsFixedProperties( &$customFixedProperties, &$fixedPropertyTablePrefix ) {
74
75 2
		if ( $this->appFactory->getOption( 'sespUseAsFixedTables' ) === false ) {
76 1
			return;
77
		}
78
79 1
		$definitions = $this->appFactory->getPropertyDefinitions();
80
81 1
		$properties = array_flip(
82 1
			$this->appFactory->getOption( 'sespSpecialProperties', array() )
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83 1
		);
84
85 1
		foreach ( $definitions as $key => $definition ) {
86
87
			if ( !isset( $definition['id'] ) ) {
88
				continue;
89
			}
90
91
			$id = $definition['id'];
92
93
			if ( isset( $properties[$key] ) ) {
94
				$customFixedProperties[$id] = str_replace( array( '___', '__' ), '_', strtolower( $id ) );
95
96
				// Legacy setting `smw_ftp` vs. `smw_fpt`
97
				$fixedPropertyTablePrefix[$id] = 'smw_ftp_sesp';
98
			}
99 1
		}
100 1
	}
101
102 2
	private function addPropertyDefinition( $propertyRegistry, $definition ) {
103
104 2
		$visible = isset( $definition['show'] ) ? $definition['show'] : false;
105 2
		$annotable = false;
106
107 2
		$alias = isset( $definition['alias'] ) ? $definition['alias'] : 'smw-unknown-alias';
108
109
		// If someone screws up the definition format we just fail epically here
110
		// on purpose
111
112 2
		$propertyRegistry->registerProperty(
113 2
			$definition['id'],
114 2
			$definition['type'],
115 2
			$definition['label'],
116 2
			$visible,
117
			$annotable
118 2
		);
119
120 2
		$propertyRegistry->registerPropertyAlias(
121 2
			$definition['id'],
122 2
			Message::get( $alias )
123 2
		);
124
125 2
		$propertyRegistry->registerPropertyAliasByMsgKey(
126 2
			$definition['id'],
127
			$alias
128 2
		);
129
130 2
		$desc = isset( $definition['desc'] ) ? $definition['desc'] : '';
131
132 2
		$propertyRegistry->registerPropertyDescriptionMsgKeyById(
133 2
			$definition['id'],
134
			$desc
135 2
		);
136 2
	}
137
138
}
139