SubPagePropertyAnnotator::addAnnotation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.7998
cc 2
nc 2
nop 2
crap 2
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 SMWDINumber as DINumber;
10
use SESP\PropertyAnnotator;
11
use SESP\AppFactory;
12
13
/**
14
 * @private
15
 * @ingroup SESP
16
 *
17
 * @license GNU GPL v2+
18
 * @since 2.0
19
 *
20
 * @author mwjames
21
 */
22
class SubPagePropertyAnnotator implements PropertyAnnotator {
23
24
	/**
25
	 * Predefined property ID
26
	 */
27
	const PROP_ID = '___SUBP';
28
29
	/**
30
	 * @var AppFactory
31
	 */
32
	private $appFactory;
33
34
	/**
35
	 * @since 2.0
36
	 *
37
	 * @param AppFactory $appFactory
38
	 */
39 3
	public function __construct( AppFactory $appFactory ) {
40 3
		$this->appFactory = $appFactory;
41 3
	}
42
43
	/**
44
	 * @since 2.0
45
	 *
46
	 * {@inheritDoc}
47
	 */
48 1
	public function isAnnotatorFor( DIProperty $property ) {
49 1
		return $property->getKey() === self::PROP_ID;
50
	}
51
52
	/**
53
	 * @since 2.0
54
	 *
55
	 * {@inheritDoc}
56
	 */
57 1
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
58
59 1
		$title = $semanticData->getSubject()->getTitle();
60
61
		//-1 = no limit. Returns TitleArray object
62 1
		$subpages = $title->getSubpages( -1 );
63
64 1
		foreach ( $subpages as $title ) {
65 1
			$semanticData->addPropertyObjectValue(
66 1
				$property,
67 1
				DIWikiPage::newFromTitle( $title )
68 1
			);
69 1
		}
70 1
	}
71
72
}
73