ApprovedByPropertyAnnotator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 88%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 70
ccs 22
cts 25
cp 0.88
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A addAnnotation() 0 15 3
A newDIWikiPage() 0 10 3
A newDIProperty() 0 2 1
A setApprovedBy() 0 2 1
1
<?php
2
3
namespace SMW\ApprovedRevs\PropertyAnnotators;
4
5
use SMW\DIProperty;
6
use SMW\SemanticData;
7
use SMW\DIWikiPage;
8
use SMW\ApprovedRevs\DatabaseLogReader;
9
use SMW\ApprovedRevs\PropertyRegistry;
10
use User;
0 ignored issues
show
Bug introduced by
The type User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Title;
0 ignored issues
show
Bug introduced by
The type Title was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
/**
14
 * @private
15
 *
16
 * @license GNU GPL v2+
17
 */
18
class ApprovedByPropertyAnnotator {
19
20
	/**
21
	 * @var DatabaseLogReader
22
	 */
23
	private $databaseLogReader;
24
25
	/**
26
	 * @var Integer|null
27
	 */
28
	private $approvedBy;
29
30
	/**
31
	 * @param DatabaseLogReader $databaseLogReader
32
	 */
33 3
	public function __construct( DatabaseLogReader $databaseLogReader ) {
34 3
		$this->databaseLogReader = $databaseLogReader;
35 3
	}
36
37
	/**
38
	 * @since 1.0
39
	 *
40
	 * @param string $approvedBy
41
	 */
42 2
	public function setApprovedBy( $approvedBy ) {
43 2
		$this->approvedBy = $approvedBy;
0 ignored issues
show
Documentation Bug introduced by
It seems like $approvedBy of type string 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...
44 2
	}
45
46
	/**
47
	 * @since 1.0
48
	 *
49
	 * @return DIProperty
50
	 */
51 2
	public function newDIProperty() {
52 2
		return new DIProperty( PropertyRegistry::SAR_PROP_APPROVED_BY );
53
	}
54
55
	/**
56
	 * @since 1.0
57
	 *
58
	 * @param SemanticData $semanticData
59
	 */
60 2
	public function addAnnotation( SemanticData $semanticData ) {
61
62 2
		if ( $this->approvedBy === null ) {
63
			$this->approvedBy = $this->databaseLogReader->getUserForLogEntry(
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->databaseLogReader...getTitle(), 'approval') of type 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...
64
				$semanticData->getSubject()->getTitle(),
65
				'approval'
66
			);
67
		}
68
69 2
		$property = $this->newDIProperty();
70 2
		$dataItem = $this->newDIWikiPage();
71 2
		$semanticData->removeProperty( $property );
72
73 2
		if ( $dataItem ) {
74 1
			$semanticData->addPropertyObjectValue( $property, $dataItem );
75
		}
76 2
	}
77
78 2
	private function newDIWikiPage() {
79
80 2
		if ( !$this->approvedBy instanceof User ) {
81 1
			return;
82
		}
83
84 1
		$userPage = $this->approvedBy->getUserPage();
85
86 1
		if ( $userPage instanceof Title ) {
87 1
			return DIWikiPage::newFromTitle( $userPage );
88
		}
89
	}
90
91
}
92