Completed
Push — refact-v2 ( 0317e0 )
by mw
04:47
created

LocalPropertyAnnotator::addAnnotation()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
eloc 13
nc 8
nop 2
dl 0
loc 26
rs 6.7272
c 0
b 0
f 0
ccs 0
cts 19
cp 0
crap 56
1
<?php
2
3
namespace SESP\PropertyAnnotators;
4
5
use SMW\DIProperty;
6
use SMW\DIWikiPage;
7
use SMW\SemanticData;
8
use SMWDataItem as DataItem;
9
use SESP\PropertyAnnotator;
10
use SESP\AppFactory;
11
12
/**
13
 * @private
14
 * @ingroup SESP
15
 *
16
 * @license GNU GPL v2+
17
 * @since 2.0
18
 *
19
 * @author mwjames
20
 */
21
class LocalPropertyAnnotator implements PropertyAnnotator {
22
23
	/**
24
	 * @var AppFactory
25
	 */
26
	private $appFactory;
27
28
	/**
29
	 * @since 2.0
30
	 *
31
	 * @param AppFactory $appFactory
32
	 */
33
	public function __construct( AppFactory $appFactory ) {
34
		$this->appFactory = $appFactory;
35
	}
36
37
	/**
38
	 * @since 2.0
39
	 *
40
	 * {@inheritDoc}
41
	 */
42
	public function isAnnotatorFor( DIProperty $property ) {
43
		return true;
44
	}
45
46
	/**
47
	 * @since 2.0
48
	 *
49
	 * {@inheritDoc}
50
	 */
51
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
52
53
		$time = microtime( true );
54
55
		$localDefs = $this->appFactory->getOption( 'sespLocalPropertyDefinitions', 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...
56
		$dataItem = null;
57
58
		foreach ( $localDefs as $key => $definition ) {
59
60
			if ( !isset( $definition['id'] ) || $definition['id'] !== $property->getKey() ) {
61
				continue;
62
			}
63
64
			if ( isset( $definition['hook'] ) && is_callable( $definition['hook'] ) ) {
65
				$dataItem = call_user_func_array( $definition['hook'], array( $this->appFactory, $property, $semanticData ) );
66
			}
67
		}
68
69
		if ( $dataItem instanceof DataItem ) {
70
			$semanticData->addPropertyObjectValue( $property, $dataItem );
71
		}
72
73
		$this->appFactory->getLogger()->info(
74
			__METHOD__ . ' (procTime in sec: '. ( microtime( true ) - $time ) . ')'
75
		);
76
	}
77
78
}
79