LocalPropertyAnnotator   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 63
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isAnnotatorFor() 0 3 1
A addAnnotation() 0 14 2
A callOnLocalDef() 0 16 6
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 4
	public function __construct( AppFactory $appFactory ) {
34 4
		$this->appFactory = $appFactory;
35 4
	}
36
37
	/**
38
	 * @since 2.0
39
	 *
40
	 * {@inheritDoc}
41
	 */
42 1
	public function isAnnotatorFor( DIProperty $property ) {
43 1
		return true;
44
	}
45
46
	/**
47
	 * @since 2.0
48
	 *
49
	 * {@inheritDoc}
50
	 */
51 2
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
52
53 2
		$time = microtime( true );
54
55 2
		$localDefs = $this->appFactory->getOption( 'sespgLocalDefinitions', [] );
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
57 2
		foreach ( $localDefs as $key => $definition ) {
58 2
			$this->callOnLocalDef( $definition, $property, $semanticData );
59 2
		}
60
61 2
		$this->appFactory->getLogger()->info(
62 2
			__METHOD__ . ' (procTime in sec: '. round( ( microtime( true ) - $time ), 5 ) . ')'
63 2
		);
64 2
	}
65
66 2
	private function callOnLocalDef( $definition, $property, $semanticData ) {
67
68 2
		if ( !isset( $definition['id'] ) || $definition['id'] !== $property->getKey() ) {
69 1
			return;
70
		}
71
72 1
		$dataItem = null;
73
74 1
		if ( isset( $definition['callback'] ) && is_callable( $definition['callback'] ) ) {
75 1
			$dataItem = call_user_func_array( $definition['callback'], [ $this->appFactory, $property, $semanticData ] );
76 1
		}
77
78 1
		if ( $dataItem instanceof DataItem ) {
79 1
			$semanticData->addPropertyObjectValue( $property, $dataItem );
80 1
		}
81 1
	}
82
83
}
84