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

ApprovedStatusPropertyAnnotator.php (1 issue)

assigning incompatible types to properties.

Bug Documentation Major

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 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;
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 )
76 1
			);
77 1
		} else {
78 1
			$semanticData->removeProperty( $property );
79
		}
80 2
	}
81
82
}
83