Completed
Push — master ( 1811ff...1fe2bc )
by mw
08:02
created

ApprovedStatusPropertyAnnotator   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 66
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setApprovedStatus() 0 3 1
A isAnnotatorFor() 0 3 1
B addAnnotation() 0 18 5
A getDataItem() 0 3 1
1
<?php
2
3
namespace SESP\PropertyAnnotators;
4
5
use SMW\DIProperty;
6
use SMW\SemanticData;
7
use SMWDIString as DIString;
8
use SESP\PropertyAnnotator;
9
use SESP\AppFactory;
10
use LogReader;
11
12
/**
13
 * @private
14
 * @ingroup SESP
15
 *
16
 * @license GNU GPL v2+
17
 */
18
class ApprovedStatusPropertyAnnotator implements PropertyAnnotator {
19
20
	/**
21
	 * Predefined property ID
22
	 */
23
	const PROP_ID = '___APPROVEDSTATUS';
24
25
	/**
26
	 * @var AppFactory
27
	 */
28
	private $appFactory;
29
30
	/**
31
	 * @var Integer|null
32
	 */
33
	private $approvedStatus;
34
35
	/**
36
	 * @param AppFactory $appFactory
37
	 */
38
	public function __construct( AppFactory $appFactory ) {
39
		$this->appFactory = $appFactory;
40
	}
41
42
	/**
43
	 * @since 2.0
44
	 *
45
	 * @param string $approvedStatus
46
	 */
47
	public function setApprovedStatus( $approvedStatus ) {
48
		$this->approvedStatus = $approvedStatus;
0 ignored issues
show
Documentation Bug introduced by
It seems like $approvedStatus of type string is incompatible with the declared type integer|null of property $approvedStatus.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
	}
50
51
	/**
52
	 * {@inheritDoc}
53
	 */
54
	public function isAnnotatorFor( DIProperty $property ) {
55
		return $property->getKey() === self::PROP_ID;
56
	}
57
58
	public function getDataItem() {
59
		return new DIString( $this->approvedStatus );
0 ignored issues
show
Deprecated Code introduced by
The class SMWDIString has been deprecated with message: Will be removed after SMW 1.9; use SMWDIBlob instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
60
	}
61
62
	/**
63
	 * {@inheritDoc}
64
	 */
65
	public function addAnnotation(
66
		DIProperty $property, SemanticData $semanticData
67
	) {
68
		if ( $this->approvedStatus === null && class_exists( 'ApprovedRevs' ) ) {
69
			$logReader = $this->appFactory->newDatabaseLogReader(
70
				$semanticData->getSubject()->getTitle(), 'approval'
71
			);
72
			$this->approvedStatus = $logReader->getStatusOfLogEntry();
0 ignored issues
show
Documentation Bug introduced by
It seems like $logReader->getStatusOfLogEntry() of type string is incompatible with the declared type integer|null of property $approvedStatus.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
73
		}
74
75
		if ( is_string( $this->approvedStatus ) && $this->approvedStatus !== "" ) {
76
			$semanticData->addPropertyObjectValue(
77
				$property, $this->getDataItem()
78
			);
79
		} else {
80
			$semanticData->removeProperty( $property );
81
		}
82
	}
83
}
84