PageLengthPropertyAnnotator::addAnnotation()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.7666
cc 4
nc 4
nop 2
crap 4
1
<?php
2
3
namespace SESP\PropertyAnnotators;
4
5
use SMW\DIProperty;
6
use SMW\SemanticData;
7
use SMWDataItem as DataItem;
8
use SMWDINumber as DINumber;
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 PageLengthPropertyAnnotator implements PropertyAnnotator {
22
23
	/**
24
	 * Predefined property ID
25
	 */
26
	const PROP_ID = '___PAGELGTH';
27
28
	/**
29
	 * @var AppFactory
30
	 */
31
	private $appFactory;
32
33
	/**
34
	 * @since 2.0
35
	 *
36
	 * @param AppFactory $appFactory
37
	 */
38 5
	public function __construct( AppFactory $appFactory ) {
39 5
		$this->appFactory = $appFactory;
40 5
	}
41
42
	/**
43
	 * @since 2.0
44
	 *
45
	 * {@inheritDoc}
46
	 */
47 1
	public function isAnnotatorFor( DIProperty $property ) {
48 1
		return $property->getKey() === self::PROP_ID;
49
	}
50
51
	/**
52
	 * @since 2.0
53
	 *
54
	 * {@inheritDoc}
55
	 */
56 3
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
57
58 3
		$title = $semanticData->getSubject()->getTitle();
59
60 3
		$length = $title->getLength();
61 3
		$dataItem = null;
62
63 3
		if ( is_integer( $length ) && $length > 0 ) {
64 1
			$dataItem = new DINumber( $length );
65 1
		}
66
67 3
		if ( $dataItem instanceof DataItem ) {
68 1
			$semanticData->addPropertyObjectValue( $property, $dataItem );
69 1
		}
70 3
	}
71
72
}
73