Completed
Push — refact-v2 ( 9bddae...f926b0 )
by mw
05:08
created

AppFactory::setConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SESP;
4
5
use Psr\Log\NullLogger;
6
use Psr\Log\LoggerInterface;
7
use Psr\Log\LoggerAwareInterface;
8
use Title;
9
use WikiPage;
10
use User;
11
12
/**
13
 * @ingroup SESP
14
 *
15
 * @license GNU GPL v2+
16
 * @since 1.3
17
 *
18
 * @author mwjames
19
 */
20
class AppFactory implements LoggerAwareInterface {
21
22
	/**
23
	 * @var array
24
	 */
25
	private $options;
26
27
	/**
28
	 * @var array
29
	 */
30
	private $connection;
31
32
	/**
33
	 * @var LoggerInterface
34
	 */
35
	private $logger;
36
37
	/**
38
	 * @var PropertyDefinitions
39
	 */
40
	private $propertyDefinitions;
41
42
	/**
43
	 * @since 2.0
44
	 *
45
	 * @param array $options
46
	 */
47 9
	public function __construct( array $options = array() ) {
48 9
		$this->options = $options;
49 9
	}
50
51
	/**
52
	 * @since 2.0
53
	 */
54 1
	public function setConnection( \DatabaseBase $connection ) {
55 1
		$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 array 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...
56 1
	}
57
58
	/**
59
	 * @since 1.3
60
	 *
61
	 * @return DatabaseBase
62
	 */
63 1
	public function getConnection() {
64 1
		return $this->connection;
65
	}
66
67
	/**
68
	 * @see LoggerAwareInterface::setLogger
69
	 *
70
	 * @since 2.0
71
	 *
72
	 * @param LoggerInterface $logger
73
	 */
74
	public function setLogger( LoggerInterface $logger ) {
75
		$this->logger = $logger;
76
	}
77
78
	/**
79
	 * @since 3.0
80
	 *
81
	 * @param LoggerInterface
82
	 */
83 1
	public function getLogger() {
84
85 1
		if ( $this->logger === null ) {
86 1
			return new NullLogger();
87
		}
88
89
		return $this->logger;
90
	}
91
92
	/**
93
	 * @since 2.4
94
	 *
95
	 * @param string $key
96
	 * @param $default $mixed
0 ignored issues
show
Documentation introduced by
The doc-type $default could not be parsed: Unknown type name "$default" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
Bug introduced by
There is no parameter named $mixed. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
97
	 *
98
	 * @return mixed|false
99
	 */
100 2
	public function getOption( $key, $default = false ) {
101
102 2
		if ( isset( $this->options[$key] ) ) {
103 2
			return $this->options[$key];
104
		}
105
106
		return $default;
107
	}
108
109
	/**
110
	 * @since 2.0
111
	 *
112
	 * @return PropertyDefinitions
113
	 */
114 1
	public function getPropertyDefinitions() {
115
116 1
		if ( $this->propertyDefinitions !== null ) {
117
			return $this->propertyDefinitions;
118
		}
119
120 1
		$this->propertyDefinitions = new PropertyDefinitions(
121 1
			$this->getOption( 'sespPropertyDefinitionFile' )
122 1
		);
123
124 1
		$this->propertyDefinitions->setLocalPropertyDefinitions(
125 1
			$this->getOption( 'sespLocalPropertyDefinitions', array() )
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
126 1
		);
127
128 1
		return $this->propertyDefinitions;
129
	}
130
131
	/**
132
	 * @since 1.3
133
	 *
134
	 * @param Title $title
135
	 *
136
	 * @return WikiPage
137
	 */
138 2
	public function newWikiPage( Title $title ) {
139
140
		// #55
141
		// Fight a possible DB corruption and avoid "NS_MEDIA is a virtual namespace; use NS_FILE"
142 2
		if ( $title->getNamespace() === NS_MEDIA ) {
143 1
			$title = Title::makeTitleSafe(
144 1
				NS_FILE,
145 1
				$title->getDBkey(),
146 1
				$title->getInterwiki(),
147 1
				$title->getFragment()
148 1
			);
149 1
		}
150
151 2
		return WikiPage::factory( $title );
152
	}
153
154
	/**
155
	 * @since 1.3
156
	 *
157
	 * @param Title $title
158
	 *
159
	 * @return User
160
	 */
161 1
	public function newUserFromTitle( Title $title ) {
162 1
		return User::newFromName( $title->getText() );
163
	}
164
165
	/**
166
	 * @since 1.3
167
	 *
168
	 * @param $id
169
	 *
170
	 * @return User
171
	 */
172 1
	public function newUserFromID( $id ) {
173 1
		return User::newFromId( $id );
174
	}
175
176
}
177