PageNumRevisionPropertyAnnotator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 63
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isAnnotatorFor() 0 3 1
A addAnnotation() 0 18 4
A getPageRevisions() 0 7 1
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 PageNumRevisionPropertyAnnotator implements PropertyAnnotator {
22
23
	/**
24
	 * Predefined property ID
25
	 */
26
	const PROP_ID = '___NREV';
27
28
	/**
29
	 * @var AppFactory
30
	 */
31
	private $appFactory;
32
33
	/**
34
	 * @since 2.0
35
	 *
36
	 * @param AppFactory $appFactory
37
	 */
38 6
	public function __construct( AppFactory $appFactory ) {
39 6
		$this->appFactory = $appFactory;
40 6
	}
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 4
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
57
58 4
		$title = $semanticData->getSubject()->getTitle();
59
60 4
		$numRevisions = $this->getPageRevisions(
61 4
			$title->getArticleID()
62 4
		);
63
64 4
		$dataItem = null;
65
66 4
		if ( $title->exists() && $numRevisions > 0 ) {
67 1
			$dataItem = new DINumber( $numRevisions );
68 1
		}
69
70 4
		if ( $dataItem instanceof DataItem ) {
71 1
			$semanticData->addPropertyObjectValue( $property, $dataItem );
72 1
		}
73 4
	}
74
75 4
	private function getPageRevisions( $pageId ) {
76 4
		return $this->appFactory->getConnection()->estimateRowCount(
77 4
			"revision",
78 4
			"*",
79 4
			[ "rev_page" => $pageId ]
80 4
		);
81
	}
82
83
}
84