ApprovedStatusPropertyAnnotator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 84.21%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 58
ccs 16
cts 19
cp 0.8421
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A newDIProperty() 0 2 1
A setApprovedStatus() 0 2 1
A addAnnotation() 0 16 4
A __construct() 0 2 1
1
<?php
2
3
namespace SMW\ApprovedRevs\PropertyAnnotators;
4
5
use SMW\DIProperty;
6
use SMW\SemanticData;
7
use SMWDIBlob as DIBlob;
8
use SMW\ApprovedRevs\DatabaseLogReader;
9
use SMW\ApprovedRevs\PropertyRegistry;
10
11
/**
12
 * @private
13
 *
14
 * @license GNU GPL v2+
15
 */
16
class ApprovedStatusPropertyAnnotator {
17
18
	/**
19
	 * @var DatabaseLogReader
20
	 */
21
	private $databaseLogReader;
22
23
	/**
24
	 * @var Integer|null
25
	 */
26
	private $approvedStatus;
27
28
	/**
29
	 * @param DatabaseLogReader $databaseLogReader
30
	 */
31 3
	public function __construct( DatabaseLogReader $databaseLogReader ) {
32 3
		$this->databaseLogReader = $databaseLogReader;
33 3
	}
34
35
	/**
36
	 * @since 1.0
37
	 *
38
	 * @param string $approvedStatus
39
	 */
40 2
	public function setApprovedStatus( $approvedStatus ) {
41 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...
42 2
	}
43
44
	/**
45
	 * @since 1.0
46
	 *
47
	 * @return DIProperty
48
	 */
49 2
	public function newDIProperty() {
50 2
		return new DIProperty( PropertyRegistry::SAR_PROP_APPROVED_STATUS );
51
	}
52
53
	/**
54
	 * @since 1.0
55
	 *
56
	 * @param SemanticData $semanticData
57
	 */
58 2
	public function addAnnotation( SemanticData $semanticData ) {
59
60 2
		if ( $this->approvedStatus === null ) {
61
			$this->approvedStatus = $this->databaseLogReader->getStatusOfLogEntry(
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->databaseLogReader...getTitle(), 'approval') 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...
62
				$semanticData->getSubject()->getTitle(),
63
				'approval'
64
			);
65
		}
66
67 2
		$property = $this->newDIProperty();
68 2
		$semanticData->removeProperty( $property );
69
70 2
		if ( is_string( $this->approvedStatus ) && $this->approvedStatus !== '' ) {
71 1
			$semanticData->addPropertyObjectValue(
72 1
				$property,
73 1
				new DIBlob( $this->approvedStatus )
74
			);
75
		}
76 2
	}
77
78
}
79