UserSaveOptions   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 56
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 12 4
A performUpdate() 0 6 1
1
<?php
2
3
namespace SWL\MediaWiki\Hooks;
4
5
use SWL\tableUpdater;
6
7
use User;
8
9
/**
10
 * Called just before saving user preferences/options in order to find the
11
 * watchlist groups the user watches, and update the swl_users_per_group table.
12
 *
13
 * https://www.mediawiki.org/wiki/Manual:Hooks/UserSaveOptions
14
 *
15
 * @ingroup SWL
16
 *
17
 * @license GNU GPL v2+
18
 * @since 1.0
19
 *
20
 * @author Jeroen De Dauw < [email protected] >
21
 * @author mwjames
22
 */
23
class UserSaveOptions {
24
25
	/**
26
	 * @var TableUpdater
27
	 */
28
	private $tableUpdater;
29
30
	/**
31
	 * @var User
32
	 */
33
	private $user;
34
35
	/**
36
	 * @var array
37
	 */
38
	private $options;
39
40
	/**
41
	 * @since 1.0
42
	 *
43
	 * @param TableUpdater $tableUpdater
44
	 * @param User $user
45
	 * @param array &$options
46
	 */
47 4
	public function __construct( TableUpdater $tableUpdater, User $user, array &$options ) {
48 4
		$this->tableUpdater = $tableUpdater;
0 ignored issues
show
Documentation Bug introduced by
It seems like $tableUpdater of type object<SWL\TableUpdater> is incompatible with the declared type object<SWL\MediaWiki\Hooks\TableUpdater> of property $tableUpdater.

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...
49 4
		$this->user = $user;
50 4
		$this->options =& $options;
51 4
	}
52
53
	/**
54
	 * @since 1.0
55
	 *
56
	 * @return boolean
57
	 */
58 3
	public function execute() {
59
60 3
		$groupIds = array();
61
62 3
		foreach ( $this->options as $name => $value ) {
63 2
			if ( strpos( $name, 'swl_watchgroup_' ) === 0 && $value ) {
64 2
				$groupIds[] = (int)substr( $name, strrpos( $name, '_' ) + 1 );
65
			}
66
		}
67
68 3
		return $this->performUpdate( $groupIds );
69
	}
70
71 3
	protected function performUpdate( array $groupIds ) {
72 3
		return $this->tableUpdater->updateGroupIdsForUser(
73 3
			$this->user->getId(),
74 3
			$groupIds
75
		);
76
	}
77
78
}
79