Passed
Push — master ( 50dbde...ac9260 )
by Morris
12:33
created

Notifier::prepare()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 18
nc 4
nop 2
dl 0
loc 29
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright 2019 Christoph Wurst <[email protected]>
7
 *
8
 * @author 2019 Christoph Wurst <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 */
25
26
namespace OC\Authentication\Notifications;
27
28
use InvalidArgumentException;
29
use OCP\L10N\IFactory as IL10nFactory;
30
use OCP\Notification\INotification;
31
use OCP\Notification\INotifier;
32
33
class Notifier implements INotifier {
34
35
	/** @var IL10nFactory */
36
	private $factory;
37
38
	public function __construct(IL10nFactory $l10nFactory) {
39
		$this->factory = $l10nFactory;
40
	}
41
42
	/**
43
	 * @inheritDoc
44
	 */
45
	public function prepare(INotification $notification, $languageCode) {
46
		if ($notification->getApp() !== 'auth') {
47
			// Not my app => throw
48
			throw new InvalidArgumentException();
49
		}
50
51
		// Read the language from the notification
52
		$l = $this->factory->get('lib', $languageCode);
53
54
		switch ($notification->getSubject()) {
55
			case 'remote_wipe_start':
56
				$notification->setParsedSubject(
57
					$l->t('Remote wipe started')
58
				)->setParsedMessage(
59
					$l->t('A remote wipe was started on device %s', $notification->getSubjectParameters())
60
				);
61
62
				return $notification;
63
			case 'remote_wipe_finish':
64
				$notification->setParsedSubject(
65
					$l->t('Remote wipe finished')
66
				)->setParsedMessage(
67
					$l->t('The remote wipe on %s has finished', $notification->getSubjectParameters())
68
				);
69
70
				return $notification;
71
			default:
72
				// Unknown subject => Unknown notification => throw
73
				throw new InvalidArgumentException();
74
		}
75
	}
76
77
}
78