Passed
Push — master ( 67f90c...bc4091 )
by Blizzz
09:54 queued 10s
created

ExtStorageConfigHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
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\Files_External\Config\UserContext;
29
use OCA\User_LDAP\User_Proxy;
30
31
class ExtStorageConfigHandler extends UserContext implements IConfigHandler {
32
	use SimpleSubstitutionTrait;
33
34
	/**
35
	 * @param mixed $optionValue
36
	 * @return mixed the same type as $optionValue
37
	 * @since 16.0.0
38
	 * @throws \Exception
39
	 */
40
	public function handle($optionValue) {
41
		$this->placeholder = 'home';
42
		$user = $this->getUser();
43
44
		if($user === null) {
45
			return $optionValue;
46
		}
47
48
		$backend = $user->getBackend();
49
		if(!$backend instanceof User_Proxy) {
50
			return $optionValue;
51
		}
52
53
		$access = $backend->getLDAPAccess($user->getUID());
54
		if(!$access) {
0 ignored issues
show
introduced by
$access is of type OCA\User_LDAP\Access, thus it always evaluated to true.
Loading history...
55
			return $optionValue;
56
		}
57
58
		$attribute = $access->connection->ldapExtStorageHomeAttribute;
59
		if(empty($attribute)) {
60
			return $optionValue;
61
		}
62
63
		$ldapUser = $access->userManager->get($user->getUID());
64
		$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

64
		/** @scrutinizer ignore-call */ 
65
  $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...
65
66
		return $this->processInput($optionValue, $extHome);
67
	}
68
}
69