Completed
Pull Request — master (#5628)
by Joas
17:04
created

Provider::parse()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 4
nop 3
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 * @copyright Copyright (c) 2016 Christoph Wurst <[email protected]>
6
 *
7
 * Two-factor backup codes
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OCA\TwoFactorBackupCodes\Activity;
24
25
use InvalidArgumentException;
26
use OCP\Activity\IEvent;
27
use OCP\Activity\IManager;
28
use OCP\Activity\IProvider;
29
use OCP\IURLGenerator;
30
use OCP\L10N\IFactory as L10nFactory;
31
32
class Provider implements IProvider {
33
34
	/** @var L10nFactory */
35
	private $l10n;
36
37
	/** @var IURLGenerator */
38
	private $urlGenerator;
39
40
	/** @var IManager */
41
	private $activityManager;
42
43
	/**
44
	 * @param L10nFactory $l10n
45
	 * @param IURLGenerator $urlGenerator
46
	 * @param IManager $activityManager
47
	 */
48
	public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) {
49
		$this->urlGenerator = $urlGenerator;
50
		$this->activityManager = $activityManager;
51
		$this->l10n = $l10n;
52
	}
53
54
	public function parse($language, IEvent $event, IEvent $previousEvent = null) {
55
		if ($event->getApp() !== 'twofactor_backupcodes') {
56
			throw new InvalidArgumentException();
57
		}
58
59
		$l = $this->l10n->get('twofactor_backupcodes', $language);
60
61
		switch ($event->getSubject()) {
62
			case 'codes_generated':
63
				$event->setParsedSubject($l->t('You created two-factor backup codes for your account'));
64
65
				if ($this->activityManager->getRequirePNG()) {
66
					$event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png')));
67
				} else {
68
					$event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')));
69
				}
70
				break;
71
			default:
72
				throw new InvalidArgumentException();
73
		}
74
		return $event;
75
	}
76
77
}
78