Completed
Push — refact-v2 ( d4acae...9bddae )
by mw
03:23
created

PageLengthPropertyAnnotator::addAnnotation()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 2
dl 0
loc 15
ccs 11
cts 11
cp 1
crap 4
rs 9.2
c 0
b 0
f 0
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 3
	public function __construct( AppFactory $appFactory ) {
39 3
		$this->appFactory = $appFactory;
40 3
	}
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 1
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
57
58 1
		$title = $semanticData->getSubject()->getTitle();
59
60 1
		$length = $title->getLength();
61 1
		$dataItem = null;
62
63 1
		if ( is_integer( $length ) && $length > 0 ) {
64 1
			$dataItem = new DINumber( $length );
65 1
		}
66
67 1
		if ( $dataItem instanceof DataItem ) {
68 1
			$semanticData->addPropertyObjectValue( $property, $dataItem );
69 1
		}
70 1
	}
71
72
}
73