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

TalkPageNumRevisionPropertyAnnotator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
ccs 0
cts 26
cp 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 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