UserNotice   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 42
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addMsg() 0 12 1
A runInternal() 0 18 5
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme\Task\Subtask;
4
5
use BotRiconferme\TaskHelper\TaskResult;
6
use BotRiconferme\Wiki\User;
7
8
/**
9
 * Notify the affected users
10
 */
11
class UserNotice extends Subtask {
12
	/**
13
	 * @inheritDoc
14
	 */
15
	public function runInternal(): int {
16
		$pages = $this->getDataProvider()->getCreatedPages();
17
		$users = $this->getDataProvider()->getUsersToProcess();
18
19
		if ( !$pages || !$users ) {
20
			return TaskResult::STATUS_NOTHING;
21
		}
22
23
		$ricNums = [];
24
		foreach ( $pages as $page ) {
25
			$ricNums[ $page->getUserName() ] = $page->getNum();
26
		}
27
28
		foreach ( $users as $name => $user ) {
29
			$this->addMsg( $user, $ricNums[ $name ] );
30
		}
31
32
		return TaskResult::STATUS_GOOD;
33
	}
34
35
	/**
36
	 * Leaves a message to the talk page
37
	 *
38
	 * @param User $user
39
	 * @param int $ricNum
40
	 */
41
	protected function addMsg( User $user, int $ricNum ): void {
42
		$this->getLogger()->info( "Leaving msg to $user" );
43
		$msg = $this->msg( 'user-notice-msg' )->params( [ '$num' => $ricNum ] )->text();
44
45
		$params = [
46
			'section' => 'new',
47
			'text' => $msg,
48
			'sectiontitle' => $this->msg( 'user-notice-sectiontitle' )->text(),
49
			'summary' => $this->msg( 'user-notice-summary' )->text()
50
		];
51
52
		$user->getTalkPage()->edit( $params );
53
	}
54
}
55