Completed
Push — master ( 8743fe...6080d9 )
by Morris
33:24 queued 19:49
created

Notifier::prepare()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2018, Roeland Jago Douma <[email protected]>
5
 *
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\TwoFactorBackupCodes\Notifications;
26
27
use OCP\L10N\IFactory;
28
use OCP\Notification\INotification;
29
use OCP\Notification\INotifier;
30
31
class Notifier implements INotifier {
32
33
	/** @var IFactory */
34
	private $factory;
35
36
	public function __construct(IFactory $factory) {
37
		$this->factory = $factory;
38
	}
39
40
	public function prepare(INotification $notification, $languageCode) {
41
		if ($notification->getApp() !== 'twofactor_backupcodes') {
42
			// Not my app => throw
43
			throw new \InvalidArgumentException();
44
		}
45
46
		// Read the language from the notification
47
		$l = $this->factory->get('twofactor_backupcodes', $languageCode);
48
49
		switch ($notification->getSubject()) {
50
			case 'create_backupcodes':
51
				$notification->setParsedSubject(
52
					$l->t('Generate backup codes')
53
				)->setParsedMessage(
54
					$l->t('You have enabled two-factor authentication but have not yet generated backup codes. Be sure to do this in case you lose access to your second factor.')
55
				);
56
				return $notification;
57
58
			default:
59
				// Unknown subject => Unknown notification => throw
60
				throw new \InvalidArgumentException();
61
		}
62
	}
63
64
}
65