Completed
Push — master ( 21ccfa...6f5178 )
by Mark A.
08:49
created

ApprovedStatusPropertyAnnotator::addAnnotation()   B

Complexity

Conditions 8
Paths 10

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 10.9144

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 9
cts 14
cp 0.6429
rs 8.4444
c 0
b 0
f 0
cc 8
nc 10
nop 2
crap 10.9144
1
<?php
2
3
namespace SESP\PropertyAnnotators;
4
5
use ApprovedRevs;
6
use SMW\DIProperty;
7
use SMW\SemanticData;
8
use SMWDIString as DIString;
9
use SESP\PropertyAnnotator;
10
use SESP\AppFactory;
11
use LogReader;
12
use Title;
13
14
/**
15
 * @private
16
 * @ingroup SESP
17
 *
18
 * @license GNU GPL v2+
19
 */
20
class ApprovedStatusPropertyAnnotator implements PropertyAnnotator {
21
22
	/**
23
	 * Predefined property ID
24
	 */
25
	const PROP_ID = '___APPROVEDSTATUS';
26
27
	/**
28
	 * @var AppFactory
29
	 */
30
	private $appFactory;
31
32
	/**
33
	 * @var Integer|null
34
	 */
35
	private $approvedStatus;
36
37
	/**
38 4
	 * @param AppFactory $appFactory
39 4
	 */
40 4
	public function __construct( AppFactory $appFactory ) {
41
		$this->appFactory = $appFactory;
42
	}
43
44
	/**
45
	 * @since 2.0
46
	 *
47 2
	 * @param string $approvedStatus
48 2
	 */
49 2
	public function setApprovedStatus( $approvedStatus ) {
50
		$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...
51
	}
52
53
	/**
54 1
	 * {@inheritDoc}
55 1
	 */
56
	public function isAnnotatorFor( DIProperty $property ) {
57
		return $property->getKey() === self::PROP_ID;
58
	}
59
60
	/**
61 2
	 * {@inheritDoc}
62
	 */
63 2
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
64
65
		if ( $this->approvedStatus === null && class_exists( 'ApprovedRevs' ) ) {
66
			$title = $semanticData->getSubject()->getTitle();
67
			if ( ApprovedRevs::pageIsApprovable( $title ) ) {
68
				$revId = ApprovedRevs::getApprovedRevID( $title );
69
				if ( $revId ) {
70
					if ( $title->getLatestRevID( Title::GAID_FOR_UPDATE ) === $revId  ) {
71
						$this->approvedStatus = "approved";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'approved' 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...
72 2
					} else {
73 1
						$this->approvedStatus = "pending";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'pending' 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...
74 1
					}
75 1
				} else {
76 1
					$this->approvedStatus = "unapproved";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'unapproved' 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...
77 1
				}
78 1
			}
79
		}
80 2
81
		if ( is_string( $this->approvedStatus ) && $this->approvedStatus !== '' ) {
82
			$semanticData->addPropertyObjectValue(
83
				$property,
84
				new DIString( $this->approvedStatus )
85
			);
86
		} else {
87
			$semanticData->removeProperty( $property );
88
		}
89
	}
90
91
}
92