Passed
Push — master ( bf1943...bfd61d )
by Blizzz
09:37
created

ExtStorageConfigHandler::handle()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 15
nc 5
nop 1
dl 0
loc 25
rs 9.4555
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2019 Arthur Schiwon <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\User_LDAP\Handler;
25
26
use OCA\Files_External\Config\IConfigHandler;
27
use OCA\Files_External\Config\SimpleSubstitutionTrait;
28
use OCA\User_LDAP\User_Proxy;
29
use OCP\IUserSession;
30
31
class ExtStorageConfigHandler implements IConfigHandler {
32
	use SimpleSubstitutionTrait;
33
34
	/** @var IUserSession */
35
	private $session;
36
37
	public function __construct(IUserSession $session) {
38
		$this->placeholder = 'home';
39
		$this->session = $session;
40
	}
41
42
	/**
43
	 * @param mixed $optionValue
44
	 * @return mixed the same type as $optionValue
45
	 * @since 16.0.0
46
	 * @throws \Exception
47
	 */
48
	public function handle($optionValue) {
49
		$user = $this->session->getUser();
50
		if($user === null) {
51
			return $optionValue;
52
		}
53
54
		$backend = $user->getBackend();
55
		if(!$backend instanceof User_Proxy) {
56
			return $optionValue;
57
		}
58
59
		$access = $backend->getLDAPAccess($user->getUID());
60
		if(!$access) {
0 ignored issues
show
introduced by
$access is of type OCA\User_LDAP\Access, thus it always evaluated to true.
Loading history...
61
			return $optionValue;
62
		}
63
64
		$attribute = $access->connection->ldapExtStorageHomeAttribute;
65
		if(empty($attribute)) {
66
			return $optionValue;
67
		}
68
69
		$ldapUser = $access->userManager->get($user->getUID());
70
		$extHome = $ldapUser->getExtStorageHome();
0 ignored issues
show
Bug introduced by
The method getExtStorageHome() does not exist on OCA\User_LDAP\User\OfflineUser. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
		/** @scrutinizer ignore-call */ 
71
  $extHome = $ldapUser->getExtStorageHome();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
72
		return $this->processInput($optionValue, $extHome);
73
	}
74
}
75