ApprovedByPropertyAnnotator   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 3
dl 0
loc 72
ccs 22
cts 28
cp 0.7856
rs 10
c 0
b 0
f 0

5 Methods

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

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...
53
	}
54
55
	/**
56
	 * {@inheritDoc}
57 1
	 */
58 1
	public function isAnnotatorFor( DIProperty $property ) {
59
		return $property->getKey() === self::PROP_ID;
60
	}
61
62
	/**
63
	 * {@inheritDoc}
64 2
	 */
65
	public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
66 2
67
		if ( $this->approvedBy === null && class_exists( 'ApprovedRevs' ) ) {
68
			$title = $semanticData->getSubject()->getTitle();
69
			if ( ApprovedRevs::pageIsApprovable( $title ) ) {
70
				$this->approvedBy = ApprovedRevs::getRevApprover( $title );
71
			}
72
		}
73
74
		$dataItem = $this->getDataItem();
75 2
76
		if ( $dataItem ) {
77 2
			$semanticData->addPropertyObjectValue( $property, $dataItem );
78 1
		} else {
79 1
			$semanticData->removeProperty( $property );
80 1
		}
81
	}
82 2
83
	private function getDataItem() {
84 2
		if ( $this->approvedBy instanceof User ) {
0 ignored issues
show
Bug introduced by
The class User does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
85 2
			$userPage = $this->approvedBy->getUserPage();
86 1
87
			if ( $userPage instanceof Title ) {
0 ignored issues
show
Bug introduced by
The class Title does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
88 1
				return DIWikiPage::newFromTitle( $userPage );
89 1
			}
90
		}
91
	}
92 1
93
}
94