Completed
Push — master ( 946aec...bc2207 )
by mw
03:21
created

ServicesFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 6
dl 0
loc 85
rs 10
c 0
b 0
f 0
ccs 19
cts 19
cp 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setConnection() 0 3 1
A getConnection() 0 8 2
A newApprovedRevsFacade() 0 3 1
A newDatabaseLogReader() 0 3 1
A newApprovedByPropertyAnnotator() 0 3 1
A newApprovedStatusPropertyAnnotator() 0 3 1
A newApprovedDatePropertyAnnotator() 0 3 1
A newApprovedRevPropertyAnnotator() 0 3 1
1
<?php
2
3
namespace SMW\ApprovedRevs;
4
5
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedByPropertyAnnotator;
6
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedStatusPropertyAnnotator;
7
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedDatePropertyAnnotator;
8
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedRevPropertyAnnotator;
9
use Title;
10
11
/**
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class ServicesFactory {
18
19
	/**
20
	 * @var DatabaseBase
21
	 */
22
	private $connection;
23
24
	/**
25
	 * @since 1.0
26
	 */
27 2
	public function setConnection( \DatabaseBase $connection ) {
28 2
		$this->connection = $connection;
0 ignored issues
show
Documentation Bug introduced by
It seems like $connection of type object<DatabaseBase> is incompatible with the declared type object<SMW\ApprovedRevs\DatabaseBase> of property $connection.

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...
29 2
	}
30
31
	/**
32
	 * @since 1.3
33
	 *
34
	 * @return DatabaseBase
35
	 */
36 5
	public function getConnection() {
37
38 5
		if ( $this->connection === null ) {
39 3
			$this->connection = wfGetDB( DB_SLAVE );
40
		}
41
42 5
		return $this->connection;
43
	}
44
45
	/**
46
	 * @since 1.0
47
	 *
48
	 * @return ApprovedRevsFacade
49
	 */
50 2
	public function newApprovedRevsFacade() {
51 2
		return new ApprovedRevsFacade();
52
	}
53
54
	/**
55
	 * @since 1.0
56
	 *
57
	 * @param null|Title $title to get the DBLogReader
58
	 * @param string $type which log entries to get (default: approval)
59
	 * @return DatabaseLogReader
60
	 */
61 4
	public function newDatabaseLogReader( Title $title = null, $type = 'approval' ) {
62 4
		return new DatabaseLogReader( $this->getConnection(), $title, $type );
63
	}
64
65
	/**
66
	 * @since 1.0
67
	 *
68
	 * @return ApprovedByPropertyAnnotator
69
	 */
70 1
	public function newApprovedByPropertyAnnotator() {
71 1
		return new ApprovedByPropertyAnnotator( $this->newDatabaseLogReader() );
72
	}
73
74
	/**
75
	 * @since 1.0
76
	 *
77
	 * @return ApprovedStatusPropertyAnnotator
78
	 */
79 1
	public function newApprovedStatusPropertyAnnotator() {
80 1
		return new ApprovedStatusPropertyAnnotator( $this->newDatabaseLogReader() );
81
	}
82
83
	/**
84
	 * @since 1.0
85
	 *
86
	 * @return ApprovedDatePropertyAnnotator
87
	 */
88 1
	public function newApprovedDatePropertyAnnotator() {
89 1
		return new ApprovedDatePropertyAnnotator( $this->newDatabaseLogReader() );
90
	}
91
92
	/**
93
	 * @since 1.0
94
	 *
95
	 * @return ApprovedRevPropertyAnnotator
96
	 */
97 1
	public function newApprovedRevPropertyAnnotator() {
98 1
		return new ApprovedRevPropertyAnnotator( $this->newApprovedRevsFacade() );
99
	}
100
101
}
102