Completed
Push — master ( 4cfef8...0aaff2 )
by
unknown
08:02
created

ApprovedStatusPropertyAnnotator::addAnnotation()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.9256

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 10
cts 15
cp 0.6667
rs 9.2888
cc 5
nc 4
nop 2
crap 5.9256
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 4
	public function __construct( AppFactory $appFactory ) {
39 4
		$this->appFactory = $appFactory;
40 4
	}
41
42
	/**
43
	 * @since 2.0
44
	 *
45
	 * @param string $approvedStatus
46
	 */
47 2
	public function setApprovedStatus( $approvedStatus ) {
48 2
		$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 2
	}
50
51
	/**
52
	 * {@inheritDoc}
53
	 */
54 1
	public function isAnnotatorFor( DIProperty $property ) {
55 1
		return $property->getKey() === self::PROP_ID;
56
	}
57
58
	/**
59
	 * {@inheritDoc}
60
	 */
61 2
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
62
63 2
		if ( $this->approvedStatus === null && class_exists( 'ApprovedRevs' ) ) {
64
65
			$logReader = $this->appFactory->newDatabaseLogReader(
66
				$semanticData->getSubject()->getTitle(), 'approval'
67
			);
68
69
			$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...
70
		}
71
72 2
		if ( is_string( $this->approvedStatus ) && $this->approvedStatus !== '' ) {
73 1
			$semanticData->addPropertyObjectValue(
74 1
				$property,
75 1
				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...
76 1
			);
77 1
		} else {
78 1
			$semanticData->removeProperty( $property );
79
		}
80 2
	}
81
82
}
83