Completed
Push — master ( 8931ba...9baa96 )
by Roeland
47:53
created

AvatarManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getAvatar() 0 6 2
1
<?php
2
/**
3
 * @author Arthur Schiwon <[email protected]>
4
 * @author Joas Schilling <[email protected]>
5
 * @author Lukas Reschke <[email protected]>
6
 * @author Morris Jobke <[email protected]>
7
 * @author Robin McCorkell <[email protected]>
8
 * @author Roeland Jago Douma <[email protected]>
9
 *
10
 * @copyright Copyright (c) 2015, ownCloud, Inc.
11
 * @license AGPL-3.0
12
 *
13
 * This code is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License, version 3,
15
 * as published by the Free Software Foundation.
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, version 3,
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
24
 *
25
 */
26
27
namespace OC;
28
29
use OCP\IAvatarManager;
30
use OCP\IUserManager;
31
use OCP\Files\IRootFolder;
32
use OCP\IL10N;
33
34
/**
35
 * This class implements methods to access Avatar functionality
36
 */
37
class AvatarManager implements IAvatarManager {
38
39
	/** @var  IUserManager */
40
	private $userManager;
41
42
	/** @var  IRootFolder */
43
	private $rootFolder;
44
45
	/** @var IL10N */
46
	private $l;
47
48 4
	public function __construct(
49
			IUserManager $userManager,
50
			IRootFolder $rootFolder,
51
			IL10N $l) {
52 4
		$this->userManager = $userManager;
53 4
		$this->rootFolder = $rootFolder;
54 4
		$this->l = $l;
55 4
	}
56
57
	/**
58
	 * return a user specific instance of \OCP\IAvatar
59
	 * @see \OCP\IAvatar
60
	 * @param string $user the ownCloud user id
61
	 * @return \OCP\IAvatar
62
	 * @throws \Exception In case the username is potentially dangerous
63
	 */
64 2
	public function getAvatar($user) {
65 2
		if (!$this->userManager->userExists($user)) {
66 1
			throw new \Exception('user does not exist');
67
		}
68 1
		return new Avatar($this->rootFolder->getUserFolder($user)->getParent(), $this->l);
69
	}
70
}
71