Completed
Pull Request — master (#75)
by mw
04:29 queued 02:37
created

TalkPageNumRevisionPropertyAnnotator.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
	 * Predefined property ID
25
	 */
26
	const PROP_ID = '___NTREV';
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()->getTalkPage();
59
60 1
		$numRevisions = $this->getPageRevisions(
61 1
			$title->getArticleID()
62 1
		);
63
64 1
		$dataItem = null;
65
66 1
		if ( $title->exists() && $numRevisions > 0 ) {
67 1
			$dataItem = new DINumber( $numRevisions );
68 1
		}
69
70 1
		if ( $dataItem instanceof DataItem ) {
71 1
			$semanticData->addPropertyObjectValue( $property, $dataItem );
72 1
		}
73 1
	}
74
75 1
	private function getPageRevisions( $pageId ) {
76 1
		return $this->appFactory->getConnection()->estimateRowCount(
0 ignored issues
show
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...
77 1
			"revision",
78 1
			"*",
79 1
			array( "rev_page" => $pageId )
80 1
		);
81
	}
82
83
}
84