Completed
Push — refact-v2 ( 0317e0 )
by mw
04:47
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
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 TalkPageNumRevisionPropertyAnnotator implements PropertyAnnotator {
22
23
	/**
24
	 * @var AppFactory
25
	 */
26
	private $appFactory;
27
28
	/**
29
	 * @since 2.0
30
	 *
31
	 * @param AppFactory $appFactory
32
	 */
33
	public function __construct( AppFactory $appFactory ) {
34
		$this->appFactory = $appFactory;
35
	}
36
37
	/**
38
	 * @since 2.0
39
	 *
40
	 * {@inheritDoc}
41
	 */
42
	public function isAnnotatorFor( DIProperty $property ) {
43
		return $property->getKey() === '___NTREV' ;
44
	}
45
46
	/**
47
	 * @since 2.0
48
	 *
49
	 * {@inheritDoc}
50
	 */
51
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
52
53
		$title = $semanticData->getSubject()->getTitle()->getTalkPage();
54
55
		$numRevisions = $this->getPageRevisions(
56
			$title->getArticleID()
57
		);
58
59
		$dataItem = null;
60
61
		if ( $title->exists() && $numRevisions > 0 ) {
62
			$dataItem = new DINumber( $numRevisions );
63
		}
64
65
		if ( $dataItem instanceof DataItem ) {
66
			$semanticData->addPropertyObjectValue( $property, $dataItem );
67
		}
68
	}
69
70
	private function getPageRevisions( $pageId ) {
71
		return $this->appFactory->getConnection()->estimateRowCount(
0 ignored issues
show
Bug introduced by
The method estimateRowCount cannot be called on $this->appFactory->getConnection() (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
72
			"revision",
73
			"*",
74
			array( "rev_page" => $pageId )
75
		);
76
	}
77
78
}
79