Passed
Push — master ( 21b7e5...813bdc )
by Christoph
12:53 queued 10s
created
lib/private/AppFramework/Http.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @param array $server $_SERVER
43 43
 	 * @param string $protocolVersion the http version to use defaults to HTTP/1.1
44 44
 	 */
45
-	public function __construct($server, $protocolVersion='HTTP/1.1') {
45
+	public function __construct($server, $protocolVersion = 'HTTP/1.1') {
46 46
 		$this->server = $server;
47 47
 		$this->protocolVersion = $protocolVersion;
48 48
 
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
 	 * @param string $ETag the etag
118 118
 	 * @return string
119 119
 	 */
120
-	public function getStatusHeader($status, \DateTime $lastModified=null, 
121
-									$ETag=null) {
120
+	public function getStatusHeader($status, \DateTime $lastModified = null, 
121
+									$ETag = null) {
122 122
 
123
-		if(!is_null($lastModified)) {
123
+		if (!is_null($lastModified)) {
124 124
 			$lastModified = $lastModified->format(\DateTime::RFC2822);
125 125
 		}
126 126
 
127 127
 		// if etag or lastmodified have not changed, return a not modified
128 128
 		if ((isset($this->server['HTTP_IF_NONE_MATCH'])
129
-			&& trim(trim($this->server['HTTP_IF_NONE_MATCH']), '"') === (string)$ETag)
129
+			&& trim(trim($this->server['HTTP_IF_NONE_MATCH']), '"') === (string) $ETag)
130 130
 
131 131
 			||
132 132
 
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
 		// we have one change currently for the http 1.0 header that differs
141 141
 		// from 1.1: STATUS_TEMPORARY_REDIRECT should be STATUS_FOUND
142 142
 		// if this differs any more, we want to create childclasses for this
143
-		if($status === self::STATUS_TEMPORARY_REDIRECT 
143
+		if ($status === self::STATUS_TEMPORARY_REDIRECT 
144 144
 			&& $this->protocolVersion === 'HTTP/1.0') {
145 145
 
146 146
 			$status = self::STATUS_FOUND;
147 147
 		}
148 148
 
149
-		return $this->protocolVersion . ' ' . $status . ' ' . 
149
+		return $this->protocolVersion.' '.$status.' '. 
150 150
 			$this->headers[$status];
151 151
 	}
152 152
 
Please login to merge, or discard this patch.
lib/private/legacy/OC_Defaults.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		$this->defaultColorPrimary = '#0082c9';
70 70
 		$this->defaultTextColorPrimary = '#ffffff';
71 71
 
72
-		$themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
72
+		$themePath = OC::$SERVERROOT.'/themes/'.OC_Util::getTheme().'/defaults.php';
73 73
 		if (file_exists($themePath)) {
74 74
 			// prevent defaults.php from printing output
75 75
 			ob_start();
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 		if ($this->themeExist('getShortFooter')) {
245 245
 			$footer = $this->theme->getShortFooter();
246 246
 		} else {
247
-			$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
248
-				' rel="noreferrer noopener">' .$this->getEntity() . '</a>'.
249
-				' – ' . $this->getSlogan();
247
+			$footer = '<a href="'.$this->getBaseUrl().'" target="_blank"'.
248
+				' rel="noreferrer noopener">'.$this->getEntity().'</a>'.
249
+				' – '.$this->getSlogan();
250 250
 		}
251 251
 
252 252
 		return $footer;
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 		if ($this->themeExist('buildDocLinkToKey')) {
275 275
 			return $this->theme->buildDocLinkToKey($key);
276 276
 		}
277
-		return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key;
277
+		return $this->getDocBaseUrl().'/server/'.$this->defaultDocVersion.'/go.php?to='.$key;
278 278
 	}
279 279
 
280 280
 	/**
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 * @return array scss variables to overwrite
297 297
 	 */
298 298
 	public function getScssVariables() {
299
-		if($this->themeExist('getScssVariables')) {
299
+		if ($this->themeExist('getScssVariables')) {
300 300
 			return $this->theme->getScssVariables();
301 301
 		}
302 302
 		return [];
@@ -317,12 +317,12 @@  discard block
 block discarded – undo
317 317
 			return $this->theme->getLogo($useSvg);
318 318
 		}
319 319
 
320
-		if($useSvg) {
320
+		if ($useSvg) {
321 321
 			$logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg');
322 322
 		} else {
323 323
 			$logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png');
324 324
 		}
325
-		return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
325
+		return $logo.'?v='.hash('sha1', implode('.', \OCP\Util::getVersion()));
326 326
 	}
327 327
 
328 328
 	public function getTextColorPrimary() {
Please login to merge, or discard this patch.
apps/user_ldap/lib/Connection.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		$this->configuration = new Configuration($configPrefix,
112 112
 												 !is_null($configID));
113 113
 		$memcache = \OC::$server->getMemCacheFactory();
114
-		if($memcache->isAvailable()) {
114
+		if ($memcache->isAvailable()) {
115 115
 			$this->cache = $memcache->createDistributed();
116 116
 		}
117 117
 		$helper = new Helper(\OC::$server->getConfig());
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	}
121 121
 
122 122
 	public function __destruct() {
123
-		if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
123
+		if (!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
124 124
 			@$this->ldap->unbind($this->ldapConnectionRes);
125 125
 			$this->bindResult = [];
126 126
 		}
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	public function __clone() {
133 133
 		$this->configuration = new Configuration($this->configPrefix,
134 134
 												 !is_null($this->configID));
135
-		if(count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
135
+		if (count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
136 136
 			$this->bindResult = [];
137 137
 		}
138 138
 		$this->ldapConnectionRes = null;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @return bool|mixed
145 145
 	 */
146 146
 	public function __get($name) {
147
-		if(!$this->configured) {
147
+		if (!$this->configured) {
148 148
 			$this->readConfiguration();
149 149
 		}
150 150
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		$before = $this->configuration->$name;
161 161
 		$this->configuration->$name = $value;
162 162
 		$after = $this->configuration->$name;
163
-		if($before !== $after) {
163
+		if ($before !== $after) {
164 164
 			if ($this->configID !== '' && $this->configID !== null) {
165 165
 				$this->configuration->saveConfiguration();
166 166
 			}
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	 * @param bool $state
185 185
 	 */
186 186
 	public function setIgnoreValidation($state) {
187
-		$this->ignoreValidation = (bool)$state;
187
+		$this->ignoreValidation = (bool) $state;
188 188
 	}
189 189
 
190 190
 	/**
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
 	 * Returns the LDAP handler
201 201
 	 */
202 202
 	public function getConnectionResource() {
203
-		if(!$this->ldapConnectionRes) {
203
+		if (!$this->ldapConnectionRes) {
204 204
 			$this->init();
205
-		} else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
205
+		} else if (!$this->ldap->isResource($this->ldapConnectionRes)) {
206 206
 			$this->ldapConnectionRes = null;
207 207
 			$this->establishConnection();
208 208
 		}
209
-		if(is_null($this->ldapConnectionRes)) {
210
-			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, ILogger::ERROR);
209
+		if (is_null($this->ldapConnectionRes)) {
210
+			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server '.$this->configuration->ldapHost, ILogger::ERROR);
211 211
 			throw new ServerNotAvailableException('Connection to LDAP server could not be established');
212 212
 		}
213 213
 		return $this->ldapConnectionRes;
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * resets the connection resource
218 218
 	 */
219 219
 	public function resetConnectionResource() {
220
-		if(!is_null($this->ldapConnectionRes)) {
220
+		if (!is_null($this->ldapConnectionRes)) {
221 221
 			@$this->ldap->unbind($this->ldapConnectionRes);
222 222
 			$this->ldapConnectionRes = null;
223 223
 			$this->bindResult = [];
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 */
231 231
 	private function getCacheKey($key) {
232 232
 		$prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
233
-		if(is_null($key)) {
233
+		if (is_null($key)) {
234 234
 			return $prefix;
235 235
 		}
236 236
 		return $prefix.hash('sha256', $key);
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 	 * @return mixed|null
242 242
 	 */
243 243
 	public function getFromCache($key) {
244
-		if(!$this->configured) {
244
+		if (!$this->configured) {
245 245
 			$this->readConfiguration();
246 246
 		}
247
-		if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
247
+		if (is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
248 248
 			return null;
249 249
 		}
250 250
 		$key = $this->getCacheKey($key);
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
 	 * @return string
260 260
 	 */
261 261
 	public function writeToCache($key, $value) {
262
-		if(!$this->configured) {
262
+		if (!$this->configured) {
263 263
 			$this->readConfiguration();
264 264
 		}
265
-		if(is_null($this->cache)
265
+		if (is_null($this->cache)
266 266
 			|| !$this->configuration->ldapCacheTTL
267 267
 			|| !$this->configuration->ldapConfigurationActive) {
268 268
 			return null;
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	}
274 274
 
275 275
 	public function clearCache() {
276
-		if(!is_null($this->cache)) {
276
+		if (!is_null($this->cache)) {
277 277
 			$this->cache->clear($this->getCacheKey(null));
278 278
 		}
279 279
 	}
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 	 * @return null
286 286
 	 */
287 287
 	private function readConfiguration($force = false) {
288
-		if((!$this->configured || $force) && !is_null($this->configID)) {
288
+		if ((!$this->configured || $force) && !is_null($this->configID)) {
289 289
 			$this->configuration->readConfiguration();
290 290
 			$this->configured = $this->validateConfiguration();
291 291
 		}
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 	 * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
299 299
 	 */
300 300
 	public function setConfiguration($config, &$setParameters = null) {
301
-		if(is_null($setParameters)) {
301
+		if (is_null($setParameters)) {
302 302
 			$setParameters = [];
303 303
 		}
304 304
 		$this->doNotValidate = false;
305 305
 		$this->configuration->setConfiguration($config, $setParameters);
306
-		if(count($setParameters) > 0) {
306
+		if (count($setParameters) > 0) {
307 307
 			$this->configured = $this->validateConfiguration();
308 308
 		}
309 309
 
@@ -330,10 +330,10 @@  discard block
 block discarded – undo
330 330
 		$config = $this->configuration->getConfiguration();
331 331
 		$cta = $this->configuration->getConfigTranslationArray();
332 332
 		$result = [];
333
-		foreach($cta as $dbkey => $configkey) {
334
-			switch($configkey) {
333
+		foreach ($cta as $dbkey => $configkey) {
334
+			switch ($configkey) {
335 335
 				case 'homeFolderNamingRule':
336
-					if(strpos($config[$configkey], 'attr:') === 0) {
336
+					if (strpos($config[$configkey], 'attr:') === 0) {
337 337
 						$result[$dbkey] = substr($config[$configkey], 5);
338 338
 					} else {
339 339
 						$result[$dbkey] = '';
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 				case 'ldapBaseGroups':
345 345
 				case 'ldapAttributesForUserSearch':
346 346
 				case 'ldapAttributesForGroupSearch':
347
-					if(is_array($config[$configkey])) {
347
+					if (is_array($config[$configkey])) {
348 348
 						$result[$dbkey] = implode("\n", $config[$configkey]);
349 349
 						break;
350 350
 					} //else follows default
@@ -357,23 +357,23 @@  discard block
 block discarded – undo
357 357
 
358 358
 	private function doSoftValidation() {
359 359
 		//if User or Group Base are not set, take over Base DN setting
360
-		foreach(['ldapBaseUsers', 'ldapBaseGroups'] as $keyBase) {
360
+		foreach (['ldapBaseUsers', 'ldapBaseGroups'] as $keyBase) {
361 361
 			$val = $this->configuration->$keyBase;
362
-			if(empty($val)) {
362
+			if (empty($val)) {
363 363
 				$this->configuration->$keyBase = $this->configuration->ldapBase;
364 364
 			}
365 365
 		}
366 366
 
367
-		foreach(['ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
367
+		foreach (['ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
368 368
 			'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute']
369 369
 				as $expertSetting => $effectiveSetting) {
370 370
 			$uuidOverride = $this->configuration->$expertSetting;
371
-			if(!empty($uuidOverride)) {
371
+			if (!empty($uuidOverride)) {
372 372
 				$this->configuration->$effectiveSetting = $uuidOverride;
373 373
 			} else {
374 374
 				$uuidAttributes = Access::UUID_ATTRIBUTES;
375 375
 				array_unshift($uuidAttributes, 'auto');
376
-				if(!in_array($this->configuration->$effectiveSetting,
376
+				if (!in_array($this->configuration->$effectiveSetting,
377 377
 							$uuidAttributes)
378 378
 					&& (!is_null($this->configID))) {
379 379
 					$this->configuration->$effectiveSetting = 'auto';
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 			}
388 388
 		}
389 389
 
390
-		$backupPort = (int)$this->configuration->ldapBackupPort;
390
+		$backupPort = (int) $this->configuration->ldapBackupPort;
391 391
 		if ($backupPort <= 0) {
392 392
 			$this->configuration->backupPort = $this->configuration->ldapPort;
393 393
 		}
@@ -395,14 +395,14 @@  discard block
 block discarded – undo
395 395
 		//make sure empty search attributes are saved as simple, empty array
396 396
 		$saKeys = ['ldapAttributesForUserSearch',
397 397
 			'ldapAttributesForGroupSearch'];
398
-		foreach($saKeys as $key) {
398
+		foreach ($saKeys as $key) {
399 399
 			$val = $this->configuration->$key;
400
-			if(is_array($val) && count($val) === 1 && empty($val[0])) {
400
+			if (is_array($val) && count($val) === 1 && empty($val[0])) {
401 401
 				$this->configuration->$key = [];
402 402
 			}
403 403
 		}
404 404
 
405
-		if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
405
+		if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
406 406
 			&& $this->configuration->ldapTLS) {
407 407
 			$this->configuration->ldapTLS = false;
408 408
 			\OCP\Util::writeLog(
@@ -419,15 +419,15 @@  discard block
 block discarded – undo
419 419
 	private function doCriticalValidation() {
420 420
 		$configurationOK = true;
421 421
 		$errorStr = 'Configuration Error (prefix '.
422
-			(string)$this->configPrefix .'): ';
422
+			(string) $this->configPrefix.'): ';
423 423
 
424 424
 		//options that shall not be empty
425 425
 		$options = ['ldapHost', 'ldapPort', 'ldapUserDisplayName',
426 426
 			'ldapGroupDisplayName', 'ldapLoginFilter'];
427
-		foreach($options as $key) {
427
+		foreach ($options as $key) {
428 428
 			$val = $this->configuration->$key;
429
-			if(empty($val)) {
430
-				switch($key) {
429
+			if (empty($val)) {
430
+				switch ($key) {
431 431
 					case 'ldapHost':
432 432
 						$subj = 'LDAP Host';
433 433
 						break;
@@ -460,12 +460,12 @@  discard block
 block discarded – undo
460 460
 		$agent = $this->configuration->ldapAgentName;
461 461
 		$pwd = $this->configuration->ldapAgentPassword;
462 462
 		if (
463
-			($agent === ''  && $pwd !== '')
463
+			($agent === '' && $pwd !== '')
464 464
 			|| ($agent !== '' && $pwd === '')
465 465
 		) {
466 466
 			\OCP\Util::writeLog(
467 467
 				'user_ldap',
468
-				$errorStr.'either no password is given for the user ' .
468
+				$errorStr.'either no password is given for the user '.
469 469
 					'agent or a password is given, but not an LDAP agent.',
470 470
 				ILogger::WARN);
471 471
 			$configurationOK = false;
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 		$baseUsers = $this->configuration->ldapBaseUsers;
476 476
 		$baseGroups = $this->configuration->ldapBaseGroups;
477 477
 
478
-		if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
478
+		if (empty($base) && empty($baseUsers) && empty($baseGroups)) {
479 479
 			\OCP\Util::writeLog(
480 480
 				'user_ldap',
481 481
 				$errorStr.'Not a single Base DN given.',
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 			$configurationOK = false;
485 485
 		}
486 486
 
487
-		if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
487
+		if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
488 488
 		   === false) {
489 489
 			\OCP\Util::writeLog(
490 490
 				'user_ldap',
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 	 */
504 504
 	private function validateConfiguration() {
505 505
 
506
-		if($this->doNotValidate) {
506
+		if ($this->doNotValidate) {
507 507
 			//don't do a validation if it is a new configuration with pure
508 508
 			//default values. Will be allowed on changes via __set or
509 509
 			//setConfiguration
@@ -526,14 +526,14 @@  discard block
 block discarded – undo
526 526
 	 * @throws ServerNotAvailableException
527 527
 	 */
528 528
 	private function establishConnection() {
529
-		if(!$this->configuration->ldapConfigurationActive) {
529
+		if (!$this->configuration->ldapConfigurationActive) {
530 530
 			return null;
531 531
 		}
532 532
 		static $phpLDAPinstalled = true;
533
-		if(!$phpLDAPinstalled) {
533
+		if (!$phpLDAPinstalled) {
534 534
 			return false;
535 535
 		}
536
-		if(!$this->ignoreValidation && !$this->configured) {
536
+		if (!$this->ignoreValidation && !$this->configured) {
537 537
 			\OCP\Util::writeLog(
538 538
 				'user_ldap',
539 539
 				'Configuration is invalid, cannot connect',
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
 			);
542 542
 			return false;
543 543
 		}
544
-		if(!$this->ldapConnectionRes) {
545
-			if(!$this->ldap->areLDAPFunctionsAvailable()) {
544
+		if (!$this->ldapConnectionRes) {
545
+			if (!$this->ldap->areLDAPFunctionsAvailable()) {
546 546
 				$phpLDAPinstalled = false;
547 547
 				\OCP\Util::writeLog(
548 548
 					'user_ldap',
@@ -552,8 +552,8 @@  discard block
 block discarded – undo
552 552
 
553 553
 				return false;
554 554
 			}
555
-			if($this->configuration->turnOffCertCheck) {
556
-				if(putenv('LDAPTLS_REQCERT=never')) {
555
+			if ($this->configuration->turnOffCertCheck) {
556
+				if (putenv('LDAPTLS_REQCERT=never')) {
557 557
 					\OCP\Util::writeLog('user_ldap',
558 558
 						'Turned off SSL certificate validation successfully.',
559 559
 						ILogger::DEBUG);
@@ -577,20 +577,20 @@  discard block
 block discarded – undo
577 577
 					return $this->bind();
578 578
 				}
579 579
 			} catch (ServerNotAvailableException $e) {
580
-				if(!$isBackupHost) {
580
+				if (!$isBackupHost) {
581 581
 					throw $e;
582 582
 				}
583 583
 			}
584 584
 
585 585
 			//if LDAP server is not reachable, try the Backup (Replica!) Server
586
-			if($isBackupHost || $isOverrideMainServer) {
586
+			if ($isBackupHost || $isOverrideMainServer) {
587 587
 				$this->doConnect($this->configuration->ldapBackupHost,
588 588
 								 $this->configuration->ldapBackupPort);
589 589
 				$this->bindResult = [];
590 590
 				$bindStatus = $this->bind();
591 591
 				$error = $this->ldap->isResource($this->ldapConnectionRes) ?
592 592
 					$this->ldap->errno($this->ldapConnectionRes) : -1;
593
-				if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) {
593
+				if ($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) {
594 594
 					//when bind to backup server succeeded and failed to main server,
595 595
 					//skip contacting him until next cache refresh
596 596
 					$this->writeToCache('overrideMainServer', true);
@@ -615,17 +615,17 @@  discard block
 block discarded – undo
615 615
 
616 616
 		$this->ldapConnectionRes = $this->ldap->connect($host, $port);
617 617
 
618
-		if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
618
+		if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
619 619
 			throw new ServerNotAvailableException('Could not set required LDAP Protocol version.');
620 620
 		}
621 621
 
622
-		if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
622
+		if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
623 623
 			throw new ServerNotAvailableException('Could not disable LDAP referrals.');
624 624
 		}
625 625
 
626
-		if($this->configuration->ldapTLS) {
627
-			if(!$this->ldap->startTls($this->ldapConnectionRes)) {
628
-				throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.');
626
+		if ($this->configuration->ldapTLS) {
627
+			if (!$this->ldap->startTls($this->ldapConnectionRes)) {
628
+				throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host '.$host.'.');
629 629
 			}
630 630
 		}
631 631
 
@@ -636,19 +636,19 @@  discard block
 block discarded – undo
636 636
 	 * Binds to LDAP
637 637
 	 */
638 638
 	public function bind() {
639
-		if(!$this->configuration->ldapConfigurationActive) {
639
+		if (!$this->configuration->ldapConfigurationActive) {
640 640
 			return false;
641 641
 		}
642 642
 		$cr = $this->ldapConnectionRes;
643
-		if(!$this->ldap->isResource($cr)) {
643
+		if (!$this->ldap->isResource($cr)) {
644 644
 			$cr = $this->getConnectionResource();
645 645
 		}
646 646
 
647
-		if(
647
+		if (
648 648
 			count($this->bindResult) !== 0
649 649
 			&& $this->bindResult['dn'] === $this->configuration->ldapAgentName
650 650
 			&& \OC::$server->getHasher()->verify(
651
-				$this->configPrefix . $this->configuration->ldapAgentPassword,
651
+				$this->configPrefix.$this->configuration->ldapAgentPassword,
652 652
 				$this->bindResult['hash']
653 653
 			)
654 654
 		) {
@@ -664,20 +664,20 @@  discard block
 block discarded – undo
664 664
 
665 665
 		$this->bindResult = [
666 666
 			'dn' => $this->configuration->ldapAgentName,
667
-			'hash' => \OC::$server->getHasher()->hash($this->configPrefix . $this->configuration->ldapAgentPassword),
667
+			'hash' => \OC::$server->getHasher()->hash($this->configPrefix.$this->configuration->ldapAgentPassword),
668 668
 			'result' => $ldapLogin,
669 669
 		];
670 670
 
671
-		if(!$ldapLogin) {
671
+		if (!$ldapLogin) {
672 672
 			$errno = $this->ldap->errno($cr);
673 673
 
674 674
 			\OCP\Util::writeLog('user_ldap',
675
-				'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr),
675
+				'Bind failed: '.$errno.': '.$this->ldap->error($cr),
676 676
 				ILogger::WARN);
677 677
 
678 678
 			// Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS
679 679
 			// or (needed for Apple Open Directory:) LDAP_INSUFFICIENT_ACCESS
680
-			if($errno !== 0 && $errno !== 49 && $errno !== 50) {
680
+			if ($errno !== 0 && $errno !== 49 && $errno !== 50) {
681 681
 				$this->ldapConnectionRes = null;
682 682
 			}
683 683
 
Please login to merge, or discard this patch.
apps/user_ldap/lib/LDAPProvider.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 		$this->deletedUsersIndex = $deletedUsersIndex;
59 59
 		$userBackendFound = false;
60 60
 		$groupBackendFound = false;
61
-		foreach ($serverContainer->getUserManager()->getBackends() as $backend){
61
+		foreach ($serverContainer->getUserManager()->getBackends() as $backend) {
62 62
 			$this->logger->debug('instance '.get_class($backend).' user backend.', ['app' => 'user_ldap']);
63 63
 			if ($backend instanceof IUserLDAP) {
64 64
 				$this->userBackend = $backend;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 				break;
67 67
 			}
68 68
 		}
69
-		foreach ($serverContainer->getGroupManager()->getBackends() as $backend){
69
+		foreach ($serverContainer->getGroupManager()->getBackends() as $backend) {
70 70
 			$this->logger->debug('instance '.get_class($backend).' group backend.', ['app' => 'user_ldap']);
71 71
 			if ($backend instanceof IGroupLDAP) {
72 72
 				$this->groupBackend = $backend;
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
 	 * @throws \Exception if translation was unsuccessful
88 88
 	 */
89 89
 	public function getUserDN($uid) {
90
-		if(!$this->userBackend->userExists($uid)){
90
+		if (!$this->userBackend->userExists($uid)) {
91 91
 			throw new \Exception('User id not found in LDAP');
92 92
 		}
93 93
 		$result = $this->userBackend->getLDAPAccess($uid)->username2dn($uid);
94
-		if(!$result){
94
+		if (!$result) {
95 95
 			throw new \Exception('Translation to LDAP DN unsuccessful');
96 96
 		}
97 97
 		return $result;
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
 	 * @throws \Exception
105 105
 	 */
106 106
 	public function getGroupDN($gid) {
107
-		if(!$this->groupBackend->groupExists($gid)){
107
+		if (!$this->groupBackend->groupExists($gid)) {
108 108
 			throw new \Exception('Group id not found in LDAP');
109 109
 		}
110 110
 		$result = $this->groupBackend->getLDAPAccess($gid)->groupname2dn($gid);
111
-		if(!$result){
111
+		if (!$result) {
112 112
 			throw new \Exception('Translation to LDAP DN unsuccessful');
113 113
 		}
114 114
 		return $result;	
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 */
124 124
 	public function getUserName($dn) {
125 125
 		$result = $this->userBackend->dn2UserName($dn);
126
-		if(!$result){
126
+		if (!$result) {
127 127
 			throw new \Exception('Translation to internal user name unsuccessful');
128 128
 		}
129 129
 		return $result;
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @throws \Exception if user id was not found in LDAP
156 156
 	 */
157 157
 	public function getLDAPConnection($uid) {
158
-		if(!$this->userBackend->userExists($uid)){
158
+		if (!$this->userBackend->userExists($uid)) {
159 159
 			throw new \Exception('User id not found in LDAP');
160 160
 		}
161 161
 		return $this->userBackend->getNewLDAPConnection($uid);
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 * @throws \Exception if group id was not found in LDAP
170 170
 	 */
171 171
 	public function getGroupLDAPConnection($gid) {
172
-		if(!$this->groupBackend->groupExists($gid)){
172
+		if (!$this->groupBackend->groupExists($gid)) {
173 173
 			throw new \Exception('Group id not found in LDAP');
174 174
 		}
175 175
 		return $this->groupBackend->getNewLDAPConnection($gid);
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 	 * @throws \Exception if user id was not found in LDAP
183 183
 	 */
184 184
 	public function getLDAPBaseUsers($uid) {
185
-		if(!$this->userBackend->userExists($uid)){
185
+		if (!$this->userBackend->userExists($uid)) {
186 186
 			throw new \Exception('User id not found in LDAP');
187 187
 		}
188 188
 		$access = $this->userBackend->getLDAPAccess($uid);
189 189
 		$bases = $access->getConnection()->ldapBaseUsers;
190 190
 		$dn = $this->getUserDN($uid);
191 191
 		foreach ($bases as $base) {
192
-			if($access->isDNPartOfBase($dn, [$base])) {
192
+			if ($access->isDNPartOfBase($dn, [$base])) {
193 193
 				return $base;
194 194
 			}
195 195
 		}
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	 * @throws \Exception if user id was not found in LDAP
213 213
 	 */
214 214
 	public function getLDAPBaseGroups($uid) {
215
-		if(!$this->userBackend->userExists($uid)){
215
+		if (!$this->userBackend->userExists($uid)) {
216 216
 			throw new \Exception('User id not found in LDAP');
217 217
 		}
218 218
 		$bases = $this->userBackend->getLDAPAccess($uid)->getConnection()->ldapBaseGroups;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 * @throws \Exception if user id was not found in LDAP
226 226
 	 */
227 227
 	public function clearCache($uid) {
228
-		if(!$this->userBackend->userExists($uid)){
228
+		if (!$this->userBackend->userExists($uid)) {
229 229
 			throw new \Exception('User id not found in LDAP');
230 230
 		}
231 231
 		$this->userBackend->getLDAPAccess($uid)->getConnection()->clearCache();
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 	 * @throws \Exception if user id was not found in LDAP
239 239
 	 */
240 240
 	public function clearGroupCache($gid) {
241
-		if(!$this->groupBackend->groupExists($gid)){
241
+		if (!$this->groupBackend->groupExists($gid)) {
242 242
 			throw new \Exception('Group id not found in LDAP');
243 243
 		}
244 244
 		$this->groupBackend->getLDAPAccess($gid)->getConnection()->clearCache();
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 	 * @throws \Exception if user id was not found in LDAP
278 278
 	 */
279 279
 	public function getLDAPDisplayNameField($uid) {
280
-		if(!$this->userBackend->userExists($uid)){
280
+		if (!$this->userBackend->userExists($uid)) {
281 281
 			throw new \Exception('User id not found in LDAP');
282 282
 		}
283 283
 		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_display_name'];
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * @throws \Exception if user id was not found in LDAP
291 291
 	 */
292 292
 	public function getLDAPEmailField($uid) {
293
-		if(!$this->userBackend->userExists($uid)){
293
+		if (!$this->userBackend->userExists($uid)) {
294 294
 			throw new \Exception('User id not found in LDAP');
295 295
 		}
296 296
 		return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_email_attr'];
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	 * @throws \Exception if group id was not found in LDAP
304 304
 	 */
305 305
 	public function getLDAPGroupMemberAssoc($gid) {
306
-		if(!$this->groupBackend->groupExists($gid)){
306
+		if (!$this->groupBackend->groupExists($gid)) {
307 307
 			throw new \Exception('Group id not found in LDAP');
308 308
 		}
309 309
 		return $this->groupBackend->getLDAPAccess($gid)->getConnection()->getConfiguration()['ldap_group_member_assoc_attribute'];
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/User.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -156,17 +156,17 @@  discard block
 block discarded – undo
156 156
 	 * @return null
157 157
 	 */
158 158
 	public function update() {
159
-		if(is_null($this->dn)) {
159
+		if (is_null($this->dn)) {
160 160
 			return null;
161 161
 		}
162 162
 
163 163
 		$hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap',
164 164
 				self::USER_PREFKEY_FIRSTLOGIN, 0);
165 165
 
166
-		if($this->needsRefresh()) {
166
+		if ($this->needsRefresh()) {
167 167
 			$this->updateEmail();
168 168
 			$this->updateQuota();
169
-			if($hasLoggedIn !== 0) {
169
+			if ($hasLoggedIn !== 0) {
170 170
 				//we do not need to try it, when the user has not been logged in
171 171
 				//before, because the file system will not be ready.
172 172
 				$this->updateAvatar();
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
 	 */
185 185
 	public function markUser() {
186 186
 		$curValue = $this->config->getUserValue($this->getUsername(), 'user_ldap', 'isDeleted', '0');
187
-		if($curValue === '1') {
187
+		if ($curValue === '1') {
188 188
 			// the user is already marked, do not write to DB again
189 189
 			return;
190 190
 		}
191 191
 		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'isDeleted', '1');
192
-		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'foundDeleted', (string)time());
192
+		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'foundDeleted', (string) time());
193 193
 	}
194 194
 
195 195
 	/**
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 		$this->markRefreshTime();
201 201
 		//Quota
202 202
 		$attr = strtolower($this->connection->ldapQuotaAttribute);
203
-		if(isset($ldapEntry[$attr])) {
203
+		if (isset($ldapEntry[$attr])) {
204 204
 			$this->updateQuota($ldapEntry[$attr][0]);
205 205
 		} else {
206 206
 			if ($this->connection->ldapQuotaDefault !== '') {
@@ -212,12 +212,12 @@  discard block
 block discarded – undo
212 212
 		//displayName
213 213
 		$displayName = $displayName2 = '';
214 214
 		$attr = strtolower($this->connection->ldapUserDisplayName);
215
-		if(isset($ldapEntry[$attr])) {
216
-			$displayName = (string)$ldapEntry[$attr][0];
215
+		if (isset($ldapEntry[$attr])) {
216
+			$displayName = (string) $ldapEntry[$attr][0];
217 217
 		}
218 218
 		$attr = strtolower($this->connection->ldapUserDisplayName2);
219
-		if(isset($ldapEntry[$attr])) {
220
-			$displayName2 = (string)$ldapEntry[$attr][0];
219
+		if (isset($ldapEntry[$attr])) {
220
+			$displayName2 = (string) $ldapEntry[$attr][0];
221 221
 		}
222 222
 		if ($displayName !== '') {
223 223
 			$this->composeAndStoreDisplayName($displayName, $displayName2);
@@ -233,22 +233,22 @@  discard block
 block discarded – undo
233 233
 		//email must be stored after displayname, because it would cause a user
234 234
 		//change event that will trigger fetching the display name again
235 235
 		$attr = strtolower($this->connection->ldapEmailAttribute);
236
-		if(isset($ldapEntry[$attr])) {
236
+		if (isset($ldapEntry[$attr])) {
237 237
 			$this->updateEmail($ldapEntry[$attr][0]);
238 238
 		}
239 239
 		unset($attr);
240 240
 
241 241
 		// LDAP Username, needed for s2s sharing
242
-		if(isset($ldapEntry['uid'])) {
242
+		if (isset($ldapEntry['uid'])) {
243 243
 			$this->storeLDAPUserName($ldapEntry['uid'][0]);
244
-		} else if(isset($ldapEntry['samaccountname'])) {
244
+		} else if (isset($ldapEntry['samaccountname'])) {
245 245
 			$this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
246 246
 		}
247 247
 
248 248
 		//homePath
249
-		if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
249
+		if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
250 250
 			$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
251
-			if(isset($ldapEntry[$attr])) {
251
+			if (isset($ldapEntry[$attr])) {
252 252
 				$this->access->cacheUserHome(
253 253
 					$this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
254 254
 			}
@@ -257,14 +257,14 @@  discard block
 block discarded – undo
257 257
 		//memberOf groups
258 258
 		$cacheKey = 'getMemberOf'.$this->getUsername();
259 259
 		$groups = false;
260
-		if(isset($ldapEntry['memberof'])) {
260
+		if (isset($ldapEntry['memberof'])) {
261 261
 			$groups = $ldapEntry['memberof'];
262 262
 		}
263 263
 		$this->connection->writeToCache($cacheKey, $groups);
264 264
 
265 265
 		//external storage var
266 266
 		$attr = strtolower($this->connection->ldapExtStorageHomeAttribute);
267
-		if(isset($ldapEntry[$attr])) {
267
+		if (isset($ldapEntry[$attr])) {
268 268
 			$this->updateExtStorageHome($ldapEntry[$attr][0]);
269 269
 		}
270 270
 		unset($attr);
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 		/** @var Connection $connection */
274 274
 		$connection = $this->access->getConnection();
275 275
 		$attributes = $connection->resolveRule('avatar');
276
-		foreach ($attributes as $attribute)  {
277
-			if(isset($ldapEntry[$attribute])) {
276
+		foreach ($attributes as $attribute) {
277
+			if (isset($ldapEntry[$attribute])) {
278 278
 				$this->avatarImage = $ldapEntry[$attribute][0];
279 279
 				// the call to the method that saves the avatar in the file
280 280
 				// system must be postponed after the login. It is to ensure
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 * @throws \Exception
310 310
 	 */
311 311
 	public function getHomePath($valueFromLDAP = null) {
312
-		$path = (string)$valueFromLDAP;
312
+		$path = (string) $valueFromLDAP;
313 313
 		$attr = null;
314 314
 
315 315
 		if (is_null($valueFromLDAP)
@@ -327,12 +327,12 @@  discard block
 block discarded – undo
327 327
 		if ($path !== '') {
328 328
 			//if attribute's value is an absolute path take this, otherwise append it to data dir
329 329
 			//check for / at the beginning or pattern c:\ resp. c:/
330
-			if(   '/' !== $path[0]
330
+			if ('/' !== $path[0]
331 331
 			   && !(3 < strlen($path) && ctype_alpha($path[0])
332 332
 				   && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))
333 333
 			) {
334 334
 				$path = $this->config->getSystemValue('datadirectory',
335
-						\OC::$SERVERROOT.'/data' ) . '/' . $path;
335
+						\OC::$SERVERROOT.'/data').'/'.$path;
336 336
 			}
337 337
 			//we need it to store it in the DB as well in case a user gets
338 338
 			//deleted so we can clean up afterwards
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
 			return $path;
343 343
 		}
344 344
 
345
-		if(    !is_null($attr)
345
+		if (!is_null($attr)
346 346
 			&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
347 347
 		) {
348 348
 			// a naming rule attribute is defined, but it doesn't exist for that LDAP user
349
-			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
349
+			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername());
350 350
 		}
351 351
 
352 352
 		//false will apply default behaviour as defined and done by OC_User
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 	public function getMemberOfGroups() {
358 358
 		$cacheKey = 'getMemberOf'.$this->getUsername();
359 359
 		$memberOfGroups = $this->connection->getFromCache($cacheKey);
360
-		if(!is_null($memberOfGroups)) {
360
+		if (!is_null($memberOfGroups)) {
361 361
 			return $memberOfGroups;
362 362
 		}
363 363
 		$groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf');
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	 * @return string data (provided by LDAP) | false
371 371
 	 */
372 372
 	public function getAvatarImage() {
373
-		if(!is_null($this->avatarImage)) {
373
+		if (!is_null($this->avatarImage)) {
374 374
 			return $this->avatarImage;
375 375
 		}
376 376
 
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
 		/** @var Connection $connection */
379 379
 		$connection = $this->access->getConnection();
380 380
 		$attributes = $connection->resolveRule('avatar');
381
-		foreach($attributes as $attribute) {
381
+		foreach ($attributes as $attribute) {
382 382
 			$result = $this->access->readAttribute($this->dn, $attribute);
383
-			if($result !== false && is_array($result) && isset($result[0])) {
383
+			if ($result !== false && is_array($result) && isset($result[0])) {
384 384
 				$this->avatarImage = $result[0];
385 385
 				break;
386 386
 			}
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 		$lastChecked = $this->config->getUserValue($this->uid, 'user_ldap',
418 418
 			self::USER_PREFKEY_LASTREFRESH, 0);
419 419
 
420
-		if((time() - (int)$lastChecked) < (int)$this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) {
420
+		if ((time() - (int) $lastChecked) < (int) $this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) {
421 421
 			return false;
422 422
 		}
423 423
 		return  true;
@@ -442,12 +442,12 @@  discard block
 block discarded – undo
442 442
 	 * @return string the effective display name
443 443
 	 */
444 444
 	public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
445
-		$displayName2 = (string)$displayName2;
446
-		if($displayName2 !== '') {
447
-			$displayName .= ' (' . $displayName2 . ')';
445
+		$displayName2 = (string) $displayName2;
446
+		if ($displayName2 !== '') {
447
+			$displayName .= ' ('.$displayName2.')';
448 448
 		}
449 449
 		$oldName = $this->config->getUserValue($this->uid, 'user_ldap', 'displayName', null);
450
-		if ($oldName !== $displayName)  {
450
+		if ($oldName !== $displayName) {
451 451
 			$this->store('displayName', $displayName);
452 452
 			$user = $this->userManager->get($this->getUsername());
453 453
 			if (!empty($oldName) && $user instanceof \OC\User\User) {
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 	 * @return bool
476 476
 	 */
477 477
 	private function wasRefreshed($feature) {
478
-		if(isset($this->refreshedFeatures[$feature])) {
478
+		if (isset($this->refreshedFeatures[$feature])) {
479 479
 			return true;
480 480
 		}
481 481
 		$this->refreshedFeatures[$feature] = 1;
@@ -488,23 +488,23 @@  discard block
 block discarded – undo
488 488
 	 * @return null
489 489
 	 */
490 490
 	public function updateEmail($valueFromLDAP = null) {
491
-		if($this->wasRefreshed('email')) {
491
+		if ($this->wasRefreshed('email')) {
492 492
 			return;
493 493
 		}
494
-		$email = (string)$valueFromLDAP;
495
-		if(is_null($valueFromLDAP)) {
494
+		$email = (string) $valueFromLDAP;
495
+		if (is_null($valueFromLDAP)) {
496 496
 			$emailAttribute = $this->connection->ldapEmailAttribute;
497 497
 			if ($emailAttribute !== '') {
498 498
 				$aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
499
-				if(is_array($aEmail) && (count($aEmail) > 0)) {
500
-					$email = (string)$aEmail[0];
499
+				if (is_array($aEmail) && (count($aEmail) > 0)) {
500
+					$email = (string) $aEmail[0];
501 501
 				}
502 502
 			}
503 503
 		}
504 504
 		if ($email !== '') {
505 505
 			$user = $this->userManager->get($this->uid);
506 506
 			if (!is_null($user)) {
507
-				$currentEmail = (string)$user->getEMailAddress();
507
+				$currentEmail = (string) $user->getEMailAddress();
508 508
 				if ($currentEmail !== $email) {
509 509
 					$user->setEMailAddress($email);
510 510
 				}
@@ -533,35 +533,35 @@  discard block
 block discarded – undo
533 533
 	 * @return null
534 534
 	 */
535 535
 	public function updateQuota($valueFromLDAP = null) {
536
-		if($this->wasRefreshed('quota')) {
536
+		if ($this->wasRefreshed('quota')) {
537 537
 			return;
538 538
 		}
539 539
 
540 540
 		$quotaAttribute = $this->connection->ldapQuotaAttribute;
541 541
 		$defaultQuota = $this->connection->ldapQuotaDefault;
542
-		if($quotaAttribute === '' && $defaultQuota === '') {
542
+		if ($quotaAttribute === '' && $defaultQuota === '') {
543 543
 			return;
544 544
 		}
545 545
 
546 546
 		$quota = false;
547
-		if(is_null($valueFromLDAP) && $quotaAttribute !== '') {
547
+		if (is_null($valueFromLDAP) && $quotaAttribute !== '') {
548 548
 			$aQuota = $this->access->readAttribute($this->dn, $quotaAttribute);
549
-			if($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) {
549
+			if ($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) {
550 550
 				$quota = $aQuota[0];
551
-			} else if(is_array($aQuota) && isset($aQuota[0])) {
552
-				$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ILogger::DEBUG);
551
+			} else if (is_array($aQuota) && isset($aQuota[0])) {
552
+				$this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$aQuota[0].']', ILogger::DEBUG);
553 553
 			}
554 554
 		} else if ($this->verifyQuotaValue($valueFromLDAP)) {
555 555
 			$quota = $valueFromLDAP;
556 556
 		} else {
557
-			$this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', ILogger::DEBUG);
557
+			$this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$valueFromLDAP.']', ILogger::DEBUG);
558 558
 		}
559 559
 
560 560
 		if ($quota === false && $this->verifyQuotaValue($defaultQuota)) {
561 561
 			// quota not found using the LDAP attribute (or not parseable). Try the default quota
562 562
 			$quota = $defaultQuota;
563
-		} else if($quota === false) {
564
-			$this->log->log('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ILogger::DEBUG);
563
+		} else if ($quota === false) {
564
+			$this->log->log('no suitable default quota found for user '.$this->uid.': ['.$defaultQuota.']', ILogger::DEBUG);
565 565
 			return;
566 566
 		}
567 567
 
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
 		if ($targetUser instanceof IUser) {
570 570
 			$targetUser->setQuota($quota);
571 571
 		} else {
572
-			$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', ILogger::INFO);
572
+			$this->log->log('trying to set a quota for user '.$this->uid.' but the user is missing', ILogger::INFO);
573 573
 		}
574 574
 	}
575 575
 
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 	 * @param array $params
584 584
 	 */
585 585
 	public function updateAvatarPostLogin($params) {
586
-		if(isset($params['uid']) && $params['uid'] === $this->getUsername()) {
586
+		if (isset($params['uid']) && $params['uid'] === $this->getUsername()) {
587 587
 			$this->updateAvatar();
588 588
 		}
589 589
 	}
@@ -593,29 +593,29 @@  discard block
 block discarded – undo
593 593
 	 * @return bool
594 594
 	 */
595 595
 	public function updateAvatar($force = false) {
596
-		if(!$force && $this->wasRefreshed('avatar')) {
596
+		if (!$force && $this->wasRefreshed('avatar')) {
597 597
 			return false;
598 598
 		}
599 599
 		$avatarImage = $this->getAvatarImage();
600
-		if($avatarImage === false) {
600
+		if ($avatarImage === false) {
601 601
 			//not set, nothing left to do;
602 602
 			return false;
603 603
 		}
604 604
 
605
-		if(!$this->image->loadFromBase64(base64_encode($avatarImage))) {
605
+		if (!$this->image->loadFromBase64(base64_encode($avatarImage))) {
606 606
 			return false;
607 607
 		}
608 608
 
609 609
 		// use the checksum before modifications
610 610
 		$checksum = md5($this->image->data());
611 611
 
612
-		if($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '')) {
612
+		if ($checksum === $this->config->getUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', '')) {
613 613
 			return true;
614 614
 		}
615 615
 
616 616
 		$isSet = $this->setOwnCloudAvatar();
617 617
 
618
-		if($isSet) {
618
+		if ($isSet) {
619 619
 			// save checksum only after successful setting
620 620
 			$this->config->setUserValue($this->uid, 'user_ldap', 'lastAvatarChecksum', $checksum);
621 621
 		}
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
 	 * @return bool
629 629
 	 */
630 630
 	private function setOwnCloudAvatar() {
631
-		if(!$this->image->valid()) {
631
+		if (!$this->image->valid()) {
632 632
 			$this->log->log('avatar image data from LDAP invalid for '.$this->dn, ILogger::ERROR);
633 633
 			return false;
634 634
 		}
@@ -636,12 +636,12 @@  discard block
 block discarded – undo
636 636
 
637 637
 		//make sure it is a square and not bigger than 128x128
638 638
 		$size = min([$this->image->width(), $this->image->height(), 128]);
639
-		if(!$this->image->centerCrop($size)) {
639
+		if (!$this->image->centerCrop($size)) {
640 640
 			$this->log->log('croping image for avatar failed for '.$this->dn, ILogger::ERROR);
641 641
 			return false;
642 642
 		}
643 643
 
644
-		if(!$this->fs->isLoaded()) {
644
+		if (!$this->fs->isLoaded()) {
645 645
 			$this->fs->setup($this->uid);
646 646
 		}
647 647
 
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 			return true;
652 652
 		} catch (\Exception $e) {
653 653
 			\OC::$server->getLogger()->logException($e, [
654
-				'message' => 'Could not set avatar for ' . $this->dn,
654
+				'message' => 'Could not set avatar for '.$this->dn,
655 655
 				'level' => ILogger::INFO,
656 656
 				'app' => 'user_ldap',
657 657
 			]);
@@ -707,8 +707,8 @@  discard block
 block discarded – undo
707 707
 	 */
708 708
 	public function handlePasswordExpiry($params) {
709 709
 		$ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
710
-		if (empty($ppolicyDN) || ((int)$this->connection->turnOnPasswordChange !== 1)) {
711
-			return;//password expiry handling disabled
710
+		if (empty($ppolicyDN) || ((int) $this->connection->turnOnPasswordChange !== 1)) {
711
+			return; //password expiry handling disabled
712 712
 		}
713 713
 		$uid = $params['uid'];
714 714
 		if (isset($uid) && $uid === $this->getUsername()) {
@@ -717,8 +717,8 @@  discard block
 block discarded – undo
717 717
 
718 718
 			if (array_key_exists('pwdpolicysubentry', $result[0])) {
719 719
 				$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
720
-				if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
721
-					$ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
720
+				if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)) {
721
+					$ppolicyDN = $pwdPolicySubentry[0]; //custom ppolicy DN
722 722
 				}
723 723
 			}
724 724
 
@@ -727,9 +727,9 @@  discard block
 block discarded – undo
727 727
 			$pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : [];
728 728
 
729 729
 			//retrieve relevant password policy attributes
730
-			$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
730
+			$cacheKey = 'ppolicyAttributes'.$ppolicyDN;
731 731
 			$result = $this->connection->getFromCache($cacheKey);
732
-			if(is_null($result)) {
732
+			if (is_null($result)) {
733 733
 				$result = $this->access->search('objectclass=*', [$ppolicyDN], ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
734 734
 				$this->connection->writeToCache($cacheKey, $result);
735 735
 			}
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 			//handle grace login
742 742
 			if (!empty($pwdGraceUseTime)) { //was this a grace login?
743 743
 				if (!empty($pwdGraceAuthNLimit)
744
-					&& count($pwdGraceUseTime) < (int)$pwdGraceAuthNLimit[0]) { //at least one more grace login available?
744
+					&& count($pwdGraceUseTime) < (int) $pwdGraceAuthNLimit[0]) { //at least one more grace login available?
745 745
 					$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
746 746
 					header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
747 747
 					'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid]));
@@ -762,9 +762,9 @@  discard block
 block discarded – undo
762 762
 			if (!empty($pwdChangedTime)) {
763 763
 				if (!empty($pwdMaxAge)
764 764
 					&& !empty($pwdExpireWarning)) {
765
-					$pwdMaxAgeInt = (int)$pwdMaxAge[0];
766
-					$pwdExpireWarningInt = (int)$pwdExpireWarning[0];
767
-					if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
765
+					$pwdMaxAgeInt = (int) $pwdMaxAge[0];
766
+					$pwdExpireWarningInt = (int) $pwdExpireWarning[0];
767
+					if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0) {
768 768
 						$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
769 769
 						$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
770 770
 						$currentDateTime = new \DateTime();
Please login to merge, or discard this patch.
apps/user_ldap/lib/Group_LDAP.php 1 patch
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		parent::__construct($access);
74 74
 		$filter = $this->access->connection->ldapGroupFilter;
75 75
 		$gassoc = $this->access->connection->ldapGroupMemberAssocAttr;
76
-		if(!empty($filter) && !empty($gassoc)) {
76
+		if (!empty($filter) && !empty($gassoc)) {
77 77
 			$this->enabled = true;
78 78
 		}
79 79
 
@@ -92,25 +92,25 @@  discard block
 block discarded – undo
92 92
 	 * Checks whether the user is member of a group or not.
93 93
 	 */
94 94
 	public function inGroup($uid, $gid) {
95
-		if(!$this->enabled) {
95
+		if (!$this->enabled) {
96 96
 			return false;
97 97
 		}
98 98
 		$cacheKey = 'inGroup'.$uid.':'.$gid;
99 99
 		$inGroup = $this->access->connection->getFromCache($cacheKey);
100
-		if(!is_null($inGroup)) {
101
-			return (bool)$inGroup;
100
+		if (!is_null($inGroup)) {
101
+			return (bool) $inGroup;
102 102
 		}
103 103
 
104 104
 		$userDN = $this->access->username2dn($uid);
105 105
 
106
-		if(isset($this->cachedGroupMembers[$gid])) {
106
+		if (isset($this->cachedGroupMembers[$gid])) {
107 107
 			$isInGroup = in_array($userDN, $this->cachedGroupMembers[$gid]);
108 108
 			return $isInGroup;
109 109
 		}
110 110
 
111 111
 		$cacheKeyMembers = 'inGroup-members:'.$gid;
112 112
 		$members = $this->access->connection->getFromCache($cacheKeyMembers);
113
-		if(!is_null($members)) {
113
+		if (!is_null($members)) {
114 114
 			$this->cachedGroupMembers[$gid] = $members;
115 115
 			$isInGroup = in_array($userDN, $members, true);
116 116
 			$this->access->connection->writeToCache($cacheKey, $isInGroup);
@@ -119,34 +119,34 @@  discard block
 block discarded – undo
119 119
 
120 120
 		$groupDN = $this->access->groupname2dn($gid);
121 121
 		// just in case
122
-		if(!$groupDN || !$userDN) {
122
+		if (!$groupDN || !$userDN) {
123 123
 			$this->access->connection->writeToCache($cacheKey, false);
124 124
 			return false;
125 125
 		}
126 126
 
127 127
 		//check primary group first
128
-		if($gid === $this->getUserPrimaryGroup($userDN)) {
128
+		if ($gid === $this->getUserPrimaryGroup($userDN)) {
129 129
 			$this->access->connection->writeToCache($cacheKey, true);
130 130
 			return true;
131 131
 		}
132 132
 
133 133
 		//usually, LDAP attributes are said to be case insensitive. But there are exceptions of course.
134 134
 		$members = $this->_groupMembers($groupDN);
135
-		if(!is_array($members) || count($members) === 0) {
135
+		if (!is_array($members) || count($members) === 0) {
136 136
 			$this->access->connection->writeToCache($cacheKey, false);
137 137
 			return false;
138 138
 		}
139 139
 
140 140
 		//extra work if we don't get back user DNs
141
-		if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
141
+		if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
142 142
 			$dns = [];
143 143
 			$filterParts = [];
144 144
 			$bytes = 0;
145
-			foreach($members as $mid) {
145
+			foreach ($members as $mid) {
146 146
 				$filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter);
147 147
 				$filterParts[] = $filter;
148 148
 				$bytes += strlen($filter);
149
-				if($bytes >= 9000000) {
149
+				if ($bytes >= 9000000) {
150 150
 					// AD has a default input buffer of 10 MB, we do not want
151 151
 					// to take even the chance to exceed it
152 152
 					$filter = $this->access->combineFilterWithOr($filterParts);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 					$dns = array_merge($dns, $users);
157 157
 				}
158 158
 			}
159
-			if(count($filterParts) > 0) {
159
+			if (count($filterParts) > 0) {
160 160
 				$filter = $this->access->combineFilterWithOr($filterParts);
161 161
 				$users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts));
162 162
 				$dns = array_merge($dns, $users);
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
 			$pos = strpos($memberURLs[0], '(');
200 200
 			if ($pos !== false) {
201 201
 				$memberUrlFilter = substr($memberURLs[0], $pos);
202
-				$foundMembers = $this->access->searchUsers($memberUrlFilter,'dn');
202
+				$foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn');
203 203
 				$dynamicMembers = [];
204
-				foreach($foundMembers as $value) {
204
+				foreach ($foundMembers as $value) {
205 205
 					$dynamicMembers[$value['dn'][0]] = 1;
206 206
 				}
207 207
 			} else {
208 208
 				\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
209
-					'of group ' . $dnGroup, ILogger::DEBUG);
209
+					'of group '.$dnGroup, ILogger::DEBUG);
210 210
 			}
211 211
 		}
212 212
 		return $dynamicMembers;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		// used extensively in cron job, caching makes sense for nested groups
231 231
 		$cacheKey = '_groupMembers'.$dnGroup;
232 232
 		$groupMembers = $this->access->connection->getFromCache($cacheKey);
233
-		if($groupMembers !== null) {
233
+		if ($groupMembers !== null) {
234 234
 			return $groupMembers;
235 235
 		}
236 236
 		$seen[$dnGroup] = 1;
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
 		$recordMode = is_array($list) && isset($list[0]) && is_array($list[0]) && isset($list[0]['dn'][0]);
291 291
 
292 292
 		if ($nesting !== 1) {
293
-			if($recordMode) {
293
+			if ($recordMode) {
294 294
 				// the keys are numeric, but should hold the DN
295
-				return array_reduce($list, function ($transformed, $record) use ($dn) {
296
-					if($record['dn'][0] != $dn) {
295
+				return array_reduce($list, function($transformed, $record) use ($dn) {
296
+					if ($record['dn'][0] != $dn) {
297 297
 						$transformed[$record['dn'][0]] = $record;
298 298
 					}
299 299
 					return $transformed;
@@ -324,9 +324,9 @@  discard block
 block discarded – undo
324 324
 	 * @return string|bool
325 325
 	 */
326 326
 	public function gidNumber2Name($gid, $dn) {
327
-		$cacheKey = 'gidNumberToName' . $gid;
327
+		$cacheKey = 'gidNumberToName'.$gid;
328 328
 		$groupName = $this->access->connection->getFromCache($cacheKey);
329
-		if(!is_null($groupName) && isset($groupName)) {
329
+		if (!is_null($groupName) && isset($groupName)) {
330 330
 			return $groupName;
331 331
 		}
332 332
 
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
 		$filter = $this->access->combineFilterWithAnd([
335 335
 			$this->access->connection->ldapGroupFilter,
336 336
 			'objectClass=posixGroup',
337
-			$this->access->connection->ldapGidNumber . '=' . $gid
337
+			$this->access->connection->ldapGidNumber.'='.$gid
338 338
 		]);
339 339
 		$result = $this->access->searchGroups($filter, ['dn'], 1);
340
-		if(empty($result)) {
340
+		if (empty($result)) {
341 341
 			return false;
342 342
 		}
343 343
 		$dn = $result[0]['dn'][0];
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 */
361 361
 	private function getEntryGidNumber($dn, $attribute) {
362 362
 		$value = $this->access->readAttribute($dn, $attribute);
363
-		if(is_array($value) && !empty($value)) {
363
+		if (is_array($value) && !empty($value)) {
364 364
 			return $value[0];
365 365
 		}
366 366
 		return false;
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
 	 */
383 383
 	public function getUserGidNumber($dn) {
384 384
 		$gidNumber = false;
385
-		if($this->access->connection->hasGidNumber) {
385
+		if ($this->access->connection->hasGidNumber) {
386 386
 			$gidNumber = $this->getEntryGidNumber($dn, $this->access->connection->ldapGidNumber);
387
-			if($gidNumber === false) {
387
+			if ($gidNumber === false) {
388 388
 				$this->access->connection->hasGidNumber = false;
389 389
 			}
390 390
 		}
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 	 */
402 402
 	private function prepareFilterForUsersHasGidNumber($groupDN, $search = '') {
403 403
 		$groupID = $this->getGroupGidNumber($groupDN);
404
-		if($groupID === false) {
404
+		if ($groupID === false) {
405 405
 			throw new \Exception('Not a valid group');
406 406
 		}
407 407
 
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 		if ($search !== '') {
411 411
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
412 412
 		}
413
-		$filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID;
413
+		$filterParts[] = $this->access->connection->ldapGidNumber.'='.$groupID;
414 414
 
415 415
 		return $this->access->combineFilterWithAnd($filterParts);
416 416
 	}
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 		try {
453 453
 			$filter = $this->prepareFilterForUsersHasGidNumber($groupDN, $search);
454 454
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
455
-			return (int)$users;
455
+			return (int) $users;
456 456
 		} catch (\Exception $e) {
457 457
 			return 0;
458 458
 		}
@@ -465,9 +465,9 @@  discard block
 block discarded – undo
465 465
 	 */
466 466
 	public function getUserGroupByGid($dn) {
467 467
 		$groupID = $this->getUserGidNumber($dn);
468
-		if($groupID !== false) {
468
+		if ($groupID !== false) {
469 469
 			$groupName = $this->gidNumber2Name($groupID, $dn);
470
-			if($groupName !== false) {
470
+			if ($groupName !== false) {
471 471
 				return $groupName;
472 472
 			}
473 473
 		}
@@ -484,22 +484,22 @@  discard block
 block discarded – undo
484 484
 	public function primaryGroupID2Name($gid, $dn) {
485 485
 		$cacheKey = 'primaryGroupIDtoName';
486 486
 		$groupNames = $this->access->connection->getFromCache($cacheKey);
487
-		if(!is_null($groupNames) && isset($groupNames[$gid])) {
487
+		if (!is_null($groupNames) && isset($groupNames[$gid])) {
488 488
 			return $groupNames[$gid];
489 489
 		}
490 490
 
491 491
 		$domainObjectSid = $this->access->getSID($dn);
492
-		if($domainObjectSid === false) {
492
+		if ($domainObjectSid === false) {
493 493
 			return false;
494 494
 		}
495 495
 
496 496
 		//we need to get the DN from LDAP
497 497
 		$filter = $this->access->combineFilterWithAnd([
498 498
 			$this->access->connection->ldapGroupFilter,
499
-			'objectsid=' . $domainObjectSid . '-' . $gid
499
+			'objectsid='.$domainObjectSid.'-'.$gid
500 500
 		]);
501 501
 		$result = $this->access->searchGroups($filter, ['dn'], 1);
502
-		if(empty($result)) {
502
+		if (empty($result)) {
503 503
 			return false;
504 504
 		}
505 505
 		$dn = $result[0]['dn'][0];
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 	 */
523 523
 	private function getEntryGroupID($dn, $attribute) {
524 524
 		$value = $this->access->readAttribute($dn, $attribute);
525
-		if(is_array($value) && !empty($value)) {
525
+		if (is_array($value) && !empty($value)) {
526 526
 			return $value[0];
527 527
 		}
528 528
 		return false;
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
 	 */
545 545
 	public function getUserPrimaryGroupIDs($dn) {
546 546
 		$primaryGroupID = false;
547
-		if($this->access->connection->hasPrimaryGroups) {
547
+		if ($this->access->connection->hasPrimaryGroups) {
548 548
 			$primaryGroupID = $this->getEntryGroupID($dn, 'primaryGroupID');
549
-			if($primaryGroupID === false) {
549
+			if ($primaryGroupID === false) {
550 550
 				$this->access->connection->hasPrimaryGroups = false;
551 551
 			}
552 552
 		}
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 	 */
564 564
 	private function prepareFilterForUsersInPrimaryGroup($groupDN, $search = '') {
565 565
 		$groupID = $this->getGroupPrimaryGroupID($groupDN);
566
-		if($groupID === false) {
566
+		if ($groupID === false) {
567 567
 			throw new \Exception('Not a valid group');
568 568
 		}
569 569
 
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 		if ($search !== '') {
573 573
 			$filterParts[] = $this->access->getFilterPartForUserSearch($search);
574 574
 		}
575
-		$filterParts[] = 'primaryGroupID=' . $groupID;
575
+		$filterParts[] = 'primaryGroupID='.$groupID;
576 576
 
577 577
 		return $this->access->combineFilterWithAnd($filterParts);
578 578
 	}
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 		try {
615 615
 			$filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search);
616 616
 			$users = $this->access->countUsers($filter, ['dn'], $limit, $offset);
617
-			return (int)$users;
617
+			return (int) $users;
618 618
 		} catch (\Exception $e) {
619 619
 			return 0;
620 620
 		}
@@ -627,9 +627,9 @@  discard block
 block discarded – undo
627 627
 	 */
628 628
 	public function getUserPrimaryGroup($dn) {
629 629
 		$groupID = $this->getUserPrimaryGroupIDs($dn);
630
-		if($groupID !== false) {
630
+		if ($groupID !== false) {
631 631
 			$groupName = $this->primaryGroupID2Name($groupID, $dn);
632
-			if($groupName !== false) {
632
+			if ($groupName !== false) {
633 633
 				return $groupName;
634 634
 			}
635 635
 		}
@@ -648,16 +648,16 @@  discard block
 block discarded – undo
648 648
 	 * This function includes groups based on dynamic group membership.
649 649
 	 */
650 650
 	public function getUserGroups($uid) {
651
-		if(!$this->enabled) {
651
+		if (!$this->enabled) {
652 652
 			return [];
653 653
 		}
654 654
 		$cacheKey = 'getUserGroups'.$uid;
655 655
 		$userGroups = $this->access->connection->getFromCache($cacheKey);
656
-		if(!is_null($userGroups)) {
656
+		if (!is_null($userGroups)) {
657 657
 			return $userGroups;
658 658
 		}
659 659
 		$userDN = $this->access->username2dn($uid);
660
-		if(!$userDN) {
660
+		if (!$userDN) {
661 661
 			$this->access->connection->writeToCache($cacheKey, []);
662 662
 			return [];
663 663
 		}
@@ -671,14 +671,14 @@  discard block
 block discarded – undo
671 671
 		if (!empty($dynamicGroupMemberURL)) {
672 672
 			// look through dynamic groups to add them to the result array if needed
673 673
 			$groupsToMatch = $this->access->fetchListOfGroups(
674
-				$this->access->connection->ldapGroupFilter,['dn',$dynamicGroupMemberURL]);
675
-			foreach($groupsToMatch as $dynamicGroup) {
674
+				$this->access->connection->ldapGroupFilter, ['dn', $dynamicGroupMemberURL]);
675
+			foreach ($groupsToMatch as $dynamicGroup) {
676 676
 				if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) {
677 677
 					continue;
678 678
 				}
679 679
 				$pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '(');
680 680
 				if ($pos !== false) {
681
-					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos);
681
+					$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos);
682 682
 					// apply filter via ldap search to see if this user is in this
683 683
 					// dynamic group
684 684
 					$userMatch = $this->access->readAttribute(
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 					if ($userMatch !== false) {
690 690
 						// match found so this user is in this group
691 691
 						$groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]);
692
-						if(is_string($groupName)) {
692
+						if (is_string($groupName)) {
693 693
 							// be sure to never return false if the dn could not be
694 694
 							// resolved to a name, for whatever reason.
695 695
 							$groups[] = $groupName;
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 					}
698 698
 				} else {
699 699
 					\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
700
-						'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG);
700
+						'of group '.print_r($dynamicGroup, true), ILogger::DEBUG);
701 701
 				}
702 702
 			}
703 703
 		}
@@ -705,15 +705,15 @@  discard block
 block discarded – undo
705 705
 		// if possible, read out membership via memberOf. It's far faster than
706 706
 		// performing a search, which still is a fallback later.
707 707
 		// memberof doesn't support memberuid, so skip it here.
708
-		if((int)$this->access->connection->hasMemberOfFilterSupport === 1
709
-			&& (int)$this->access->connection->useMemberOfToDetectMembership === 1
708
+		if ((int) $this->access->connection->hasMemberOfFilterSupport === 1
709
+			&& (int) $this->access->connection->useMemberOfToDetectMembership === 1
710 710
 			&& strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid'
711 711
 			) {
712 712
 			$groupDNs = $this->_getGroupDNsFromMemberOf($userDN);
713 713
 			if (is_array($groupDNs)) {
714 714
 				foreach ($groupDNs as $dn) {
715 715
 					$groupName = $this->access->dn2groupname($dn);
716
-					if(is_string($groupName)) {
716
+					if (is_string($groupName)) {
717 717
 						// be sure to never return false if the dn could not be
718 718
 						// resolved to a name, for whatever reason.
719 719
 						$groups[] = $groupName;
@@ -721,10 +721,10 @@  discard block
 block discarded – undo
721 721
 				}
722 722
 			}
723 723
 
724
-			if($primaryGroup !== false) {
724
+			if ($primaryGroup !== false) {
725 725
 				$groups[] = $primaryGroup;
726 726
 			}
727
-			if($gidGroupName !== false) {
727
+			if ($gidGroupName !== false) {
728 728
 				$groups[] = $gidGroupName;
729 729
 			}
730 730
 			$this->access->connection->writeToCache($cacheKey, $groups);
@@ -732,14 +732,14 @@  discard block
 block discarded – undo
732 732
 		}
733 733
 
734 734
 		//uniqueMember takes DN, memberuid the uid, so we need to distinguish
735
-		if((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
735
+		if ((strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'uniquemember')
736 736
 			|| (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'member')
737 737
 		) {
738 738
 			$uid = $userDN;
739
-		} else if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
739
+		} else if (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
740 740
 			$result = $this->access->readAttribute($userDN, 'uid');
741 741
 			if ($result === false) {
742
-				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '.
742
+				\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN '.$userDN.' on '.
743 743
 					$this->access->connection->ldapHost, ILogger::DEBUG);
744 744
 				$uid = false;
745 745
 			} else {
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 			$uid = $userDN;
751 751
 		}
752 752
 
753
-		if($uid !== false) {
753
+		if ($uid !== false) {
754 754
 			if (isset($this->cachedGroupsByMember[$uid])) {
755 755
 				$groups = array_merge($groups, $this->cachedGroupsByMember[$uid]);
756 756
 			} else {
@@ -761,10 +761,10 @@  discard block
 block discarded – undo
761 761
 			}
762 762
 		}
763 763
 
764
-		if($primaryGroup !== false) {
764
+		if ($primaryGroup !== false) {
765 765
 			$groups[] = $primaryGroup;
766 766
 		}
767
-		if($gidGroupName !== false) {
767
+		if ($gidGroupName !== false) {
768 768
 			$groups[] = $gidGroupName;
769 769
 		}
770 770
 
@@ -793,8 +793,8 @@  discard block
 block discarded – undo
793 793
 		$groups = $this->access->fetchListOfGroups($filter,
794 794
 			[$this->access->connection->ldapGroupDisplayName, 'dn']);
795 795
 		if (is_array($groups)) {
796
-			$fetcher = function ($dn, &$seen) {
797
-				if(is_array($dn) && isset($dn['dn'][0])) {
796
+			$fetcher = function($dn, &$seen) {
797
+				if (is_array($dn) && isset($dn['dn'][0])) {
798 798
 					$dn = $dn['dn'][0];
799 799
 				}
800 800
 				return $this->getGroupsByMember($dn, $seen);
@@ -816,33 +816,33 @@  discard block
 block discarded – undo
816 816
 	 * @throws \Exception
817 817
 	 */
818 818
 	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
819
-		if(!$this->enabled) {
819
+		if (!$this->enabled) {
820 820
 			return [];
821 821
 		}
822
-		if(!$this->groupExists($gid)) {
822
+		if (!$this->groupExists($gid)) {
823 823
 			return [];
824 824
 		}
825 825
 		$search = $this->access->escapeFilterPart($search, true);
826 826
 		$cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset;
827 827
 		// check for cache of the exact query
828 828
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
829
-		if(!is_null($groupUsers)) {
829
+		if (!is_null($groupUsers)) {
830 830
 			return $groupUsers;
831 831
 		}
832 832
 
833 833
 		// check for cache of the query without limit and offset
834 834
 		$groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search);
835
-		if(!is_null($groupUsers)) {
835
+		if (!is_null($groupUsers)) {
836 836
 			$groupUsers = array_slice($groupUsers, $offset, $limit);
837 837
 			$this->access->connection->writeToCache($cacheKey, $groupUsers);
838 838
 			return $groupUsers;
839 839
 		}
840 840
 
841
-		if($limit === -1) {
841
+		if ($limit === -1) {
842 842
 			$limit = null;
843 843
 		}
844 844
 		$groupDN = $this->access->groupname2dn($gid);
845
-		if(!$groupDN) {
845
+		if (!$groupDN) {
846 846
 			// group couldn't be found, return empty resultset
847 847
 			$this->access->connection->writeToCache($cacheKey, []);
848 848
 			return [];
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 		$primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset);
852 852
 		$posixGroupUsers = $this->getUsersInGidNumber($groupDN, $search, $limit, $offset);
853 853
 		$members = $this->_groupMembers($groupDN);
854
-		if(!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
854
+		if (!$members && empty($posixGroupUsers) && empty($primaryUsers)) {
855 855
 			//in case users could not be retrieved, return empty result set
856 856
 			$this->access->connection->writeToCache($cacheKey, []);
857 857
 			return [];
@@ -860,8 +860,8 @@  discard block
 block discarded – undo
860 860
 		$groupUsers = [];
861 861
 		$isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid');
862 862
 		$attrs = $this->access->userManager->getAttributes(true);
863
-		foreach($members as $member) {
864
-			if($isMemberUid) {
863
+		foreach ($members as $member) {
864
+			if ($isMemberUid) {
865 865
 				//we got uids, need to get their DNs to 'translate' them to user names
866 866
 				$filter = $this->access->combineFilterWithAnd([
867 867
 					str_replace('%uid', trim($member), $this->access->connection->ldapLoginFilter),
@@ -871,23 +871,23 @@  discard block
 block discarded – undo
871 871
 					])
872 872
 				]);
873 873
 				$ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1);
874
-				if(count($ldap_users) < 1) {
874
+				if (count($ldap_users) < 1) {
875 875
 					continue;
876 876
 				}
877 877
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
878 878
 			} else {
879 879
 				//we got DNs, check if we need to filter by search or we can give back all of them
880 880
 				$uid = $this->access->dn2username($member);
881
-				if(!$uid) {
881
+				if (!$uid) {
882 882
 					continue;
883 883
 				}
884 884
 
885
-				$cacheKey = 'userExistsOnLDAP' . $uid;
885
+				$cacheKey = 'userExistsOnLDAP'.$uid;
886 886
 				$userExists = $this->access->connection->getFromCache($cacheKey);
887
-				if($userExists === false) {
887
+				if ($userExists === false) {
888 888
 					continue;
889 889
 				}
890
-				if($userExists === null || $search !== '') {
890
+				if ($userExists === null || $search !== '') {
891 891
 					if (!$this->access->readAttribute($member,
892 892
 						$this->access->connection->ldapUserDisplayName,
893 893
 						$this->access->combineFilterWithAnd([
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 							$this->access->connection->ldapUserFilter
896 896
 						])))
897 897
 					{
898
-						if($search === '') {
898
+						if ($search === '') {
899 899
 							$this->access->connection->writeToCache($cacheKey, false);
900 900
 						}
901 901
 						continue;
@@ -928,16 +928,16 @@  discard block
 block discarded – undo
928 928
 		}
929 929
 
930 930
 		$cacheKey = 'countUsersInGroup-'.$gid.'-'.$search;
931
-		if(!$this->enabled || !$this->groupExists($gid)) {
931
+		if (!$this->enabled || !$this->groupExists($gid)) {
932 932
 			return false;
933 933
 		}
934 934
 		$groupUsers = $this->access->connection->getFromCache($cacheKey);
935
-		if(!is_null($groupUsers)) {
935
+		if (!is_null($groupUsers)) {
936 936
 			return $groupUsers;
937 937
 		}
938 938
 
939 939
 		$groupDN = $this->access->groupname2dn($gid);
940
-		if(!$groupDN) {
940
+		if (!$groupDN) {
941 941
 			// group couldn't be found, return empty result set
942 942
 			$this->access->connection->writeToCache($cacheKey, false);
943 943
 			return false;
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
 
946 946
 		$members = $this->_groupMembers($groupDN);
947 947
 		$primaryUserCount = $this->countUsersInPrimaryGroup($groupDN, '');
948
-		if(!$members && $primaryUserCount === 0) {
948
+		if (!$members && $primaryUserCount === 0) {
949 949
 			//in case users could not be retrieved, return empty result set
950 950
 			$this->access->connection->writeToCache($cacheKey, false);
951 951
 			return false;
@@ -970,27 +970,27 @@  discard block
 block discarded – undo
970 970
 		//For now this is not important, because the only use of this method
971 971
 		//does not supply a search string
972 972
 		$groupUsers = [];
973
-		foreach($members as $member) {
974
-			if($isMemberUid) {
973
+		foreach ($members as $member) {
974
+			if ($isMemberUid) {
975 975
 				//we got uids, need to get their DNs to 'translate' them to user names
976 976
 				$filter = $this->access->combineFilterWithAnd([
977 977
 					str_replace('%uid', $member, $this->access->connection->ldapLoginFilter),
978 978
 					$this->access->getFilterPartForUserSearch($search)
979 979
 				]);
980 980
 				$ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1);
981
-				if(count($ldap_users) < 1) {
981
+				if (count($ldap_users) < 1) {
982 982
 					continue;
983 983
 				}
984 984
 				$groupUsers[] = $this->access->dn2username($ldap_users[0]);
985 985
 			} else {
986 986
 				//we need to apply the search filter now
987
-				if(!$this->access->readAttribute($member,
987
+				if (!$this->access->readAttribute($member,
988 988
 					$this->access->connection->ldapUserDisplayName,
989 989
 					$this->access->getFilterPartForUserSearch($search))) {
990 990
 					continue;
991 991
 				}
992 992
 				// dn2username will also check if the users belong to the allowed base
993
-				if($ocname = $this->access->dn2username($member)) {
993
+				if ($ocname = $this->access->dn2username($member)) {
994 994
 					$groupUsers[] = $ocname;
995 995
 				}
996 996
 			}
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 	 * Returns a list with all groups (used by getGroups)
1014 1014
 	 */
1015 1015
 	protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) {
1016
-		if(!$this->enabled) {
1016
+		if (!$this->enabled) {
1017 1017
 			return [];
1018 1018
 		}
1019 1019
 		$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
@@ -1021,13 +1021,13 @@  discard block
 block discarded – undo
1021 1021
 		//Check cache before driving unnecessary searches
1022 1022
 		\OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, ILogger::DEBUG);
1023 1023
 		$ldap_groups = $this->access->connection->getFromCache($cacheKey);
1024
-		if(!is_null($ldap_groups)) {
1024
+		if (!is_null($ldap_groups)) {
1025 1025
 			return $ldap_groups;
1026 1026
 		}
1027 1027
 
1028 1028
 		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
1029 1029
 		// error. With a limit of 0, we get 0 results. So we pass null.
1030
-		if($limit <= 0) {
1030
+		if ($limit <= 0) {
1031 1031
 			$limit = null;
1032 1032
 		}
1033 1033
 		$filter = $this->access->combineFilterWithAnd([
@@ -1059,11 +1059,11 @@  discard block
 block discarded – undo
1059 1059
 	 * (active directory has a limit of 1000 by default)
1060 1060
 	 */
1061 1061
 	public function getGroups($search = '', $limit = -1, $offset = 0) {
1062
-		if(!$this->enabled) {
1062
+		if (!$this->enabled) {
1063 1063
 			return [];
1064 1064
 		}
1065 1065
 		$search = $this->access->escapeFilterPart($search, true);
1066
-		$pagingSize = (int)$this->access->connection->ldapPagingSize;
1066
+		$pagingSize = (int) $this->access->connection->ldapPagingSize;
1067 1067
 		if ($pagingSize <= 0) {
1068 1068
 			return $this->getGroupsChunk($search, $limit, $offset);
1069 1069
 		}
@@ -1106,20 +1106,20 @@  discard block
 block discarded – undo
1106 1106
 	 */
1107 1107
 	public function groupExists($gid) {
1108 1108
 		$groupExists = $this->access->connection->getFromCache('groupExists'.$gid);
1109
-		if(!is_null($groupExists)) {
1110
-			return (bool)$groupExists;
1109
+		if (!is_null($groupExists)) {
1110
+			return (bool) $groupExists;
1111 1111
 		}
1112 1112
 
1113 1113
 		//getting dn, if false the group does not exist. If dn, it may be mapped
1114 1114
 		//only, requires more checking.
1115 1115
 		$dn = $this->access->groupname2dn($gid);
1116
-		if(!$dn) {
1116
+		if (!$dn) {
1117 1117
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1118 1118
 			return false;
1119 1119
 		}
1120 1120
 
1121 1121
 		//if group really still exists, we will be able to read its objectclass
1122
-		if(!is_array($this->access->readAttribute($dn, ''))) {
1122
+		if (!is_array($this->access->readAttribute($dn, ''))) {
1123 1123
 			$this->access->connection->writeToCache('groupExists'.$gid, false);
1124 1124
 			return false;
1125 1125
 		}
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 	 * compared with GroupInterface::CREATE_GROUP etc.
1138 1138
 	 */
1139 1139
 	public function implementsActions($actions) {
1140
-		return (bool)((GroupInterface::COUNT_USERS |
1140
+		return (bool) ((GroupInterface::COUNT_USERS |
1141 1141
 				$this->groupPluginManager->getImplementedActions()) & $actions);
1142 1142
 	}
1143 1143
 
@@ -1160,7 +1160,7 @@  discard block
 block discarded – undo
1160 1160
 			if ($dn = $this->groupPluginManager->createGroup($gid)) {
1161 1161
 				//updates group mapping
1162 1162
 				$uuid = $this->access->getUUID($dn, false);
1163
-				if(is_string($uuid)) {
1163
+				if (is_string($uuid)) {
1164 1164
 					$this->access->mapAndAnnounceIfApplicable(
1165 1165
 						$this->access->getGroupMapper(),
1166 1166
 						$dn,
@@ -1263,7 +1263,7 @@  discard block
 block discarded – undo
1263 1263
 			return $this->groupPluginManager->getDisplayName($gid);
1264 1264
 		}
1265 1265
 
1266
-		$cacheKey = 'group_getDisplayName' . $gid;
1266
+		$cacheKey = 'group_getDisplayName'.$gid;
1267 1267
 		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
1268 1268
 			return $displayName;
1269 1269
 		}
Please login to merge, or discard this patch.
apps/user_ldap/lib/Wizard.php 1 patch
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) {
73 73
 		parent::__construct($ldap);
74 74
 		$this->configuration = $configuration;
75
-		if(is_null(Wizard::$l)) {
75
+		if (is_null(Wizard::$l)) {
76 76
 			Wizard::$l = \OC::$server->getL10N('user_ldap');
77 77
 		}
78 78
 		$this->access = $access;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	}
81 81
 
82 82
 	public function  __destruct() {
83
-		if($this->result->hasChanges()) {
83
+		if ($this->result->hasChanges()) {
84 84
 			$this->configuration->saveConfiguration();
85 85
 		}
86 86
 	}
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	public function countEntries(string $filter, string $type): int {
97 97
 		$reqs = ['ldapHost', 'ldapPort', 'ldapBase'];
98
-		if($type === 'users') {
98
+		if ($type === 'users') {
99 99
 			$reqs[] = 'ldapUserFilter';
100 100
 		}
101
-		if(!$this->checkRequirements($reqs)) {
101
+		if (!$this->checkRequirements($reqs)) {
102 102
 			throw new \Exception('Requirements not met', 400);
103 103
 		}
104 104
 
105 105
 		$attr = ['dn']; // default
106 106
 		$limit = 1001;
107
-		if($type === 'groups') {
108
-			$result =  $this->access->countGroups($filter, $attr, $limit);
109
-		} else if($type === 'users') {
107
+		if ($type === 'groups') {
108
+			$result = $this->access->countGroups($filter, $attr, $limit);
109
+		} else if ($type === 'users') {
110 110
 			$result = $this->access->countUsers($filter, $attr, $limit);
111 111
 		} else if ($type === 'objects') {
112 112
 			$result = $this->access->countObjects($limit);
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 			throw new \Exception('Internal error: Invalid object type', 500);
115 115
 		}
116 116
 
117
-		return (int)$result;
117
+		return (int) $result;
118 118
 	}
119 119
 
120 120
 	/**
@@ -125,16 +125,16 @@  discard block
 block discarded – undo
125 125
 	 * @return string
126 126
 	 */
127 127
 	private function formatCountResult(int $count): string {
128
-		if($count > 1000) {
128
+		if ($count > 1000) {
129 129
 			return '> 1000';
130 130
 		}
131
-		return (string)$count;
131
+		return (string) $count;
132 132
 	}
133 133
 
134 134
 	public function countGroups() {
135 135
 		$filter = $this->configuration->ldapGroupFilter;
136 136
 
137
-		if(empty($filter)) {
137
+		if (empty($filter)) {
138 138
 			$output = self::$l->n('%s group found', '%s groups found', 0, [0]);
139 139
 			$this->result->addChange('ldap_group_count', $output);
140 140
 			return $this->result;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			$groupsTotal = $this->countEntries($filter, 'groups');
145 145
 		} catch (\Exception $e) {
146 146
 			//400 can be ignored, 500 is forwarded
147
-			if($e->getCode() === 500) {
147
+			if ($e->getCode() === 500) {
148 148
 				throw $e;
149 149
 			}
150 150
 			return false;
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	public function countInBaseDN() {
187 187
 		// we don't need to provide a filter in this case
188 188
 		$total = $this->countEntries('', 'objects');
189
-		if($total === false) {
189
+		if ($total === false) {
190 190
 			throw new \Exception('invalid results received');
191 191
 		}
192 192
 		$this->result->addChange('ldap_test_base', $total);
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * @return int|bool
201 201
 	 */
202 202
 	public function countUsersWithAttribute($attr, $existsCheck = false) {
203
-		if(!$this->checkRequirements(['ldapHost',
203
+		if (!$this->checkRequirements(['ldapHost',
204 204
 			'ldapPort',
205 205
 			'ldapBase',
206 206
 			'ldapUserFilter',
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 
211 211
 		$filter = $this->access->combineFilterWithAnd([
212 212
 			$this->configuration->ldapUserFilter,
213
-			$attr . '=*'
213
+			$attr.'=*'
214 214
 		]);
215 215
 
216 216
 		$limit = ($existsCheck === false) ? null : 1;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 * @throws \Exception
226 226
 	 */
227 227
 	public function detectUserDisplayNameAttribute() {
228
-		if(!$this->checkRequirements(['ldapHost',
228
+		if (!$this->checkRequirements(['ldapHost',
229 229
 			'ldapPort',
230 230
 			'ldapBase',
231 231
 			'ldapUserFilter',
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 		if ($attr !== '' && $attr !== 'displayName') {
238 238
 			// most likely not the default value with upper case N,
239 239
 			// verify it still produces a result
240
-			$count = (int)$this->countUsersWithAttribute($attr, true);
241
-			if($count > 0) {
240
+			$count = (int) $this->countUsersWithAttribute($attr, true);
241
+			if ($count > 0) {
242 242
 				//no change, but we sent it back to make sure the user interface
243 243
 				//is still correct, even if the ajax call was cancelled meanwhile
244 244
 				$this->result->addChange('ldap_display_name', $attr);
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
 		// first attribute that has at least one result wins
250 250
 		$displayNameAttrs = ['displayname', 'cn'];
251 251
 		foreach ($displayNameAttrs as $attr) {
252
-			$count = (int)$this->countUsersWithAttribute($attr, true);
252
+			$count = (int) $this->countUsersWithAttribute($attr, true);
253 253
 
254
-			if($count > 0) {
254
+			if ($count > 0) {
255 255
 				$this->applyFind('ldap_display_name', $attr);
256 256
 				return $this->result;
257 257
 			}
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return WizardResult|bool
268 268
 	 */
269 269
 	public function detectEmailAttribute() {
270
-		if(!$this->checkRequirements(['ldapHost',
270
+		if (!$this->checkRequirements(['ldapHost',
271 271
 			'ldapPort',
272 272
 			'ldapBase',
273 273
 			'ldapUserFilter',
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 
278 278
 		$attr = $this->configuration->ldapEmailAttribute;
279 279
 		if ($attr !== '') {
280
-			$count = (int)$this->countUsersWithAttribute($attr, true);
281
-			if($count > 0) {
280
+			$count = (int) $this->countUsersWithAttribute($attr, true);
281
+			if ($count > 0) {
282 282
 				return false;
283 283
 			}
284 284
 			$writeLog = true;
@@ -289,19 +289,19 @@  discard block
 block discarded – undo
289 289
 		$emailAttributes = ['mail', 'mailPrimaryAddress'];
290 290
 		$winner = '';
291 291
 		$maxUsers = 0;
292
-		foreach($emailAttributes as $attr) {
292
+		foreach ($emailAttributes as $attr) {
293 293
 			$count = $this->countUsersWithAttribute($attr);
294
-			if($count > $maxUsers) {
294
+			if ($count > $maxUsers) {
295 295
 				$maxUsers = $count;
296 296
 				$winner = $attr;
297 297
 			}
298 298
 		}
299 299
 
300
-		if($winner !== '') {
300
+		if ($winner !== '') {
301 301
 			$this->applyFind('ldap_email_attr', $winner);
302
-			if($writeLog) {
303
-				\OCP\Util::writeLog('user_ldap', 'The mail attribute has ' .
304
-					'automatically been reset, because the original value ' .
302
+			if ($writeLog) {
303
+				\OCP\Util::writeLog('user_ldap', 'The mail attribute has '.
304
+					'automatically been reset, because the original value '.
305 305
 					'did not return any results.', ILogger::INFO);
306 306
 			}
307 307
 		}
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 * @throws \Exception
315 315
 	 */
316 316
 	public function determineAttributes() {
317
-		if(!$this->checkRequirements(['ldapHost',
317
+		if (!$this->checkRequirements(['ldapHost',
318 318
 			'ldapPort',
319 319
 			'ldapBase',
320 320
 			'ldapUserFilter',
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 		$this->result->addOptions('ldap_loginfilter_attributes', $attributes);
331 331
 
332 332
 		$selected = $this->configuration->ldapLoginFilterAttributes;
333
-		if(is_array($selected) && !empty($selected)) {
333
+		if (is_array($selected) && !empty($selected)) {
334 334
 			$this->result->addChange('ldap_loginfilter_attributes', $selected);
335 335
 		}
336 336
 
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 	 * @throws \Exception
344 344
 	 */
345 345
 	private function getUserAttributes() {
346
-		if(!$this->checkRequirements(['ldapHost',
346
+		if (!$this->checkRequirements(['ldapHost',
347 347
 			'ldapPort',
348 348
 			'ldapBase',
349 349
 			'ldapUserFilter',
@@ -351,20 +351,20 @@  discard block
 block discarded – undo
351 351
 			return  false;
352 352
 		}
353 353
 		$cr = $this->getConnection();
354
-		if(!$cr) {
354
+		if (!$cr) {
355 355
 			throw new \Exception('Could not connect to LDAP');
356 356
 		}
357 357
 
358 358
 		$base = $this->configuration->ldapBase[0];
359 359
 		$filter = $this->configuration->ldapUserFilter;
360 360
 		$rr = $this->ldap->search($cr, $base, $filter, [], 1, 1);
361
-		if(!$this->ldap->isResource($rr)) {
361
+		if (!$this->ldap->isResource($rr)) {
362 362
 			return false;
363 363
 		}
364 364
 		$er = $this->ldap->firstEntry($cr, $rr);
365 365
 		$attributes = $this->ldap->getAttributes($cr, $er);
366 366
 		$pureAttributes = [];
367
-		for($i = 0; $i < $attributes['count']; $i++) {
367
+		for ($i = 0; $i < $attributes['count']; $i++) {
368 368
 			$pureAttributes[] = $attributes[$i];
369 369
 		}
370 370
 
@@ -399,23 +399,23 @@  discard block
 block discarded – undo
399 399
 	 * @throws \Exception
400 400
 	 */
401 401
 	private function determineGroups($dbKey, $confKey, $testMemberOf = true) {
402
-		if(!$this->checkRequirements(['ldapHost',
402
+		if (!$this->checkRequirements(['ldapHost',
403 403
 			'ldapPort',
404 404
 			'ldapBase',
405 405
 		])) {
406 406
 			return  false;
407 407
 		}
408 408
 		$cr = $this->getConnection();
409
-		if(!$cr) {
409
+		if (!$cr) {
410 410
 			throw new \Exception('Could not connect to LDAP');
411 411
 		}
412 412
 
413 413
 		$this->fetchGroups($dbKey, $confKey);
414 414
 
415
-		if($testMemberOf) {
415
+		if ($testMemberOf) {
416 416
 			$this->configuration->hasMemberOfFilterSupport = $this->testMemberOf();
417 417
 			$this->result->markChange();
418
-			if(!$this->configuration->hasMemberOfFilterSupport) {
418
+			if (!$this->configuration->hasMemberOfFilterSupport) {
419 419
 				throw new \Exception('memberOf is not supported by the server');
420 420
 			}
421 421
 		}
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 		$obclasses = ['posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'];
436 436
 
437 437
 		$filterParts = [];
438
-		foreach($obclasses as $obclass) {
438
+		foreach ($obclasses as $obclass) {
439 439
 			$filterParts[] = 'objectclass='.$obclass;
440 440
 		}
441 441
 		//we filter for everything
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
 			// we need to request dn additionally here, otherwise memberOf
453 453
 			// detection will fail later
454 454
 			$result = $this->access->searchGroups($filter, ['cn', 'dn'], $limit, $offset);
455
-			foreach($result as $item) {
456
-				if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) {
455
+			foreach ($result as $item) {
456
+				if (!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) {
457 457
 					// just in case - no issue known
458 458
 					continue;
459 459
 				}
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 			$offset += $limit;
464 464
 		} while ($this->access->hasMoreResults());
465 465
 
466
-		if(count($groupNames) > 0) {
466
+		if (count($groupNames) > 0) {
467 467
 			natsort($groupNames);
468 468
 			$this->result->addOptions($dbKey, array_values($groupNames));
469 469
 		} else {
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 		}
472 472
 
473 473
 		$setFeatures = $this->configuration->$confKey;
474
-		if(is_array($setFeatures) && !empty($setFeatures)) {
474
+		if (is_array($setFeatures) && !empty($setFeatures)) {
475 475
 			//something is already configured? pre-select it.
476 476
 			$this->result->addChange($dbKey, $setFeatures);
477 477
 		}
@@ -479,14 +479,14 @@  discard block
 block discarded – undo
479 479
 	}
480 480
 
481 481
 	public function determineGroupMemberAssoc() {
482
-		if(!$this->checkRequirements(['ldapHost',
482
+		if (!$this->checkRequirements(['ldapHost',
483 483
 			'ldapPort',
484 484
 			'ldapGroupFilter',
485 485
 		])) {
486 486
 			return  false;
487 487
 		}
488 488
 		$attribute = $this->detectGroupMemberAssoc();
489
-		if($attribute === false) {
489
+		if ($attribute === false) {
490 490
 			return false;
491 491
 		}
492 492
 		$this->configuration->setConfiguration(['ldapGroupMemberAssocAttr' => $attribute]);
@@ -501,14 +501,14 @@  discard block
 block discarded – undo
501 501
 	 * @throws \Exception
502 502
 	 */
503 503
 	public function determineGroupObjectClasses() {
504
-		if(!$this->checkRequirements(['ldapHost',
504
+		if (!$this->checkRequirements(['ldapHost',
505 505
 			'ldapPort',
506 506
 			'ldapBase',
507 507
 		])) {
508 508
 			return  false;
509 509
 		}
510 510
 		$cr = $this->getConnection();
511
-		if(!$cr) {
511
+		if (!$cr) {
512 512
 			throw new \Exception('Could not connect to LDAP');
513 513
 		}
514 514
 
@@ -528,14 +528,14 @@  discard block
 block discarded – undo
528 528
 	 * @throws \Exception
529 529
 	 */
530 530
 	public function determineUserObjectClasses() {
531
-		if(!$this->checkRequirements(['ldapHost',
531
+		if (!$this->checkRequirements(['ldapHost',
532 532
 			'ldapPort',
533 533
 			'ldapBase',
534 534
 		])) {
535 535
 			return  false;
536 536
 		}
537 537
 		$cr = $this->getConnection();
538
-		if(!$cr) {
538
+		if (!$cr) {
539 539
 			throw new \Exception('Could not connect to LDAP');
540 540
 		}
541 541
 
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 	 * @throws \Exception
559 559
 	 */
560 560
 	public function getGroupFilter() {
561
-		if(!$this->checkRequirements(['ldapHost',
561
+		if (!$this->checkRequirements(['ldapHost',
562 562
 			'ldapPort',
563 563
 			'ldapBase',
564 564
 		])) {
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 	 * @throws \Exception
583 583
 	 */
584 584
 	public function getUserListFilter() {
585
-		if(!$this->checkRequirements(['ldapHost',
585
+		if (!$this->checkRequirements(['ldapHost',
586 586
 			'ldapPort',
587 587
 			'ldapBase',
588 588
 		])) {
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 			$this->applyFind('ldap_display_name', $d['ldap_display_name']);
596 596
 		}
597 597
 		$filter = $this->composeLdapFilter(self::LFILTER_USER_LIST);
598
-		if(!$filter) {
598
+		if (!$filter) {
599 599
 			throw new \Exception('Cannot create filter');
600 600
 		}
601 601
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 	 * @throws \Exception
609 609
 	 */
610 610
 	public function getUserLoginFilter() {
611
-		if(!$this->checkRequirements(['ldapHost',
611
+		if (!$this->checkRequirements(['ldapHost',
612 612
 			'ldapPort',
613 613
 			'ldapBase',
614 614
 			'ldapUserFilter',
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 		}
618 618
 
619 619
 		$filter = $this->composeLdapFilter(self::LFILTER_LOGIN);
620
-		if(!$filter) {
620
+		if (!$filter) {
621 621
 			throw new \Exception('Cannot create filter');
622 622
 		}
623 623
 
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 	 * @throws \Exception
632 632
 	 */
633 633
 	public function testLoginName($loginName) {
634
-		if(!$this->checkRequirements(['ldapHost',
634
+		if (!$this->checkRequirements(['ldapHost',
635 635
 			'ldapPort',
636 636
 			'ldapBase',
637 637
 			'ldapLoginFilter',
@@ -640,17 +640,17 @@  discard block
 block discarded – undo
640 640
 		}
641 641
 
642 642
 		$cr = $this->access->connection->getConnectionResource();
643
-		if(!$this->ldap->isResource($cr)) {
643
+		if (!$this->ldap->isResource($cr)) {
644 644
 			throw new \Exception('connection error');
645 645
 		}
646 646
 
647
-		if(mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8')
647
+		if (mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8')
648 648
 			=== false) {
649 649
 			throw new \Exception('missing placeholder');
650 650
 		}
651 651
 
652 652
 		$users = $this->access->countUsersByLoginName($loginName);
653
-		if($this->ldap->errno($cr) !== 0) {
653
+		if ($this->ldap->errno($cr) !== 0) {
654 654
 			throw new \Exception($this->ldap->error($cr));
655 655
 		}
656 656
 		$filter = str_replace('%uid', $loginName, $this->access->connection->ldapLoginFilter);
@@ -665,22 +665,22 @@  discard block
 block discarded – undo
665 665
 	 * @throws \Exception
666 666
 	 */
667 667
 	public function guessPortAndTLS() {
668
-		if(!$this->checkRequirements(['ldapHost',
668
+		if (!$this->checkRequirements(['ldapHost',
669 669
 		])) {
670 670
 			return false;
671 671
 		}
672 672
 		$this->checkHost();
673 673
 		$portSettings = $this->getPortSettingsToTry();
674 674
 
675
-		if(!is_array($portSettings)) {
675
+		if (!is_array($portSettings)) {
676 676
 			throw new \Exception(print_r($portSettings, true));
677 677
 		}
678 678
 
679 679
 		//proceed from the best configuration and return on first success
680
-		foreach($portSettings as $setting) {
680
+		foreach ($portSettings as $setting) {
681 681
 			$p = $setting['port'];
682 682
 			$t = $setting['tls'];
683
-			\OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, ILogger::DEBUG);
683
+			\OCP\Util::writeLog('user_ldap', 'Wiz: trying port '.$p.', TLS '.$t, ILogger::DEBUG);
684 684
 			//connectAndBind may throw Exception, it needs to be catched by the
685 685
 			//callee of this method
686 686
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 				// any reply other than -1 (= cannot connect) is already okay,
691 691
 				// because then we found the server
692 692
 				// unavailable startTLS returns -11
693
-				if($e->getCode() > 0) {
693
+				if ($e->getCode() > 0) {
694 694
 					$settingsFound = true;
695 695
 				} else {
696 696
 					throw $e;
@@ -700,10 +700,10 @@  discard block
 block discarded – undo
700 700
 			if ($settingsFound === true) {
701 701
 				$config = [
702 702
 					'ldapPort' => $p,
703
-					'ldapTLS' => (int)$t
703
+					'ldapTLS' => (int) $t
704 704
 				];
705 705
 				$this->configuration->setConfiguration($config);
706
-				\OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, ILogger::DEBUG);
706
+				\OCP\Util::writeLog('user_ldap', 'Wiz: detected Port '.$p, ILogger::DEBUG);
707 707
 				$this->result->addChange('ldap_port', $p);
708 708
 				return $this->result;
709 709
 			}
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 	 * @return WizardResult|false WizardResult on success, false otherwise
719 719
 	 */
720 720
 	public function guessBaseDN() {
721
-		if(!$this->checkRequirements(['ldapHost',
721
+		if (!$this->checkRequirements(['ldapHost',
722 722
 			'ldapPort',
723 723
 		])) {
724 724
 			return false;
@@ -727,9 +727,9 @@  discard block
 block discarded – undo
727 727
 		//check whether a DN is given in the agent name (99.9% of all cases)
728 728
 		$base = null;
729 729
 		$i = stripos($this->configuration->ldapAgentName, 'dc=');
730
-		if($i !== false) {
730
+		if ($i !== false) {
731 731
 			$base = substr($this->configuration->ldapAgentName, $i);
732
-			if($this->testBaseDN($base)) {
732
+			if ($this->testBaseDN($base)) {
733 733
 				$this->applyFind('ldap_base', $base);
734 734
 				return $this->result;
735 735
 			}
@@ -740,13 +740,13 @@  discard block
 block discarded – undo
740 740
 		//a base DN
741 741
 		$helper = new Helper(\OC::$server->getConfig());
742 742
 		$domain = $helper->getDomainFromURL($this->configuration->ldapHost);
743
-		if(!$domain) {
743
+		if (!$domain) {
744 744
 			return false;
745 745
 		}
746 746
 
747 747
 		$dparts = explode('.', $domain);
748
-		while(count($dparts) > 0) {
749
-			$base2 = 'dc=' . implode(',dc=', $dparts);
748
+		while (count($dparts) > 0) {
749
+			$base2 = 'dc='.implode(',dc=', $dparts);
750 750
 			if ($base !== $base2 && $this->testBaseDN($base2)) {
751 751
 				$this->applyFind('ldap_base', $base2);
752 752
 				return $this->result;
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 		$hostInfo = parse_url($host);
780 780
 
781 781
 		//removes Port from Host
782
-		if(is_array($hostInfo) && isset($hostInfo['port'])) {
782
+		if (is_array($hostInfo) && isset($hostInfo['port'])) {
783 783
 			$port = $hostInfo['port'];
784 784
 			$host = str_replace(':'.$port, '', $host);
785 785
 			$this->applyFind('ldap_host', $host);
@@ -796,30 +796,30 @@  discard block
 block discarded – undo
796 796
 	private function detectGroupMemberAssoc() {
797 797
 		$possibleAttrs = ['uniqueMember', 'memberUid', 'member', 'gidNumber'];
798 798
 		$filter = $this->configuration->ldapGroupFilter;
799
-		if(empty($filter)) {
799
+		if (empty($filter)) {
800 800
 			return false;
801 801
 		}
802 802
 		$cr = $this->getConnection();
803
-		if(!$cr) {
803
+		if (!$cr) {
804 804
 			throw new \Exception('Could not connect to LDAP');
805 805
 		}
806 806
 		$base = $this->configuration->ldapBaseGroups[0] ?: $this->configuration->ldapBase[0];
807 807
 		$rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs, 0, 1000);
808
-		if(!$this->ldap->isResource($rr)) {
808
+		if (!$this->ldap->isResource($rr)) {
809 809
 			return false;
810 810
 		}
811 811
 		$er = $this->ldap->firstEntry($cr, $rr);
812
-		while(is_resource($er)) {
812
+		while (is_resource($er)) {
813 813
 			$this->ldap->getDN($cr, $er);
814 814
 			$attrs = $this->ldap->getAttributes($cr, $er);
815 815
 			$result = [];
816 816
 			$possibleAttrsCount = count($possibleAttrs);
817
-			for($i = 0; $i < $possibleAttrsCount; $i++) {
818
-				if(isset($attrs[$possibleAttrs[$i]])) {
817
+			for ($i = 0; $i < $possibleAttrsCount; $i++) {
818
+				if (isset($attrs[$possibleAttrs[$i]])) {
819 819
 					$result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count'];
820 820
 				}
821 821
 			}
822
-			if(!empty($result)) {
822
+			if (!empty($result)) {
823 823
 				natsort($result);
824 824
 				return key($result);
825 825
 			}
@@ -838,14 +838,14 @@  discard block
 block discarded – undo
838 838
 	 */
839 839
 	private function testBaseDN($base) {
840 840
 		$cr = $this->getConnection();
841
-		if(!$cr) {
841
+		if (!$cr) {
842 842
 			throw new \Exception('Could not connect to LDAP');
843 843
 		}
844 844
 
845 845
 		//base is there, let's validate it. If we search for anything, we should
846 846
 		//get a result set > 0 on a proper base
847 847
 		$rr = $this->ldap->search($cr, $base, 'objectClass=*', ['dn'], 0, 1);
848
-		if(!$this->ldap->isResource($rr)) {
848
+		if (!$this->ldap->isResource($rr)) {
849 849
 			$errorNo  = $this->ldap->errno($cr);
850 850
 			$errorMsg = $this->ldap->error($cr);
851 851
 			\OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base.
@@ -867,11 +867,11 @@  discard block
 block discarded – undo
867 867
 	 */
868 868
 	private function testMemberOf() {
869 869
 		$cr = $this->getConnection();
870
-		if(!$cr) {
870
+		if (!$cr) {
871 871
 			throw new \Exception('Could not connect to LDAP');
872 872
 		}
873 873
 		$result = $this->access->countUsers('memberOf=*', ['memberOf'], 1);
874
-		if(is_int($result) &&  $result > 0) {
874
+		if (is_int($result) && $result > 0) {
875 875
 			return true;
876 876
 		}
877 877
 		return false;
@@ -892,27 +892,27 @@  discard block
 block discarded – undo
892 892
 			case self::LFILTER_USER_LIST:
893 893
 				$objcs = $this->configuration->ldapUserFilterObjectclass;
894 894
 				//glue objectclasses
895
-				if(is_array($objcs) && count($objcs) > 0) {
895
+				if (is_array($objcs) && count($objcs) > 0) {
896 896
 					$filter .= '(|';
897
-					foreach($objcs as $objc) {
898
-						$filter .= '(objectclass=' . $objc . ')';
897
+					foreach ($objcs as $objc) {
898
+						$filter .= '(objectclass='.$objc.')';
899 899
 					}
900 900
 					$filter .= ')';
901 901
 					$parts++;
902 902
 				}
903 903
 				//glue group memberships
904
-				if($this->configuration->hasMemberOfFilterSupport) {
904
+				if ($this->configuration->hasMemberOfFilterSupport) {
905 905
 					$cns = $this->configuration->ldapUserFilterGroups;
906
-					if(is_array($cns) && count($cns) > 0) {
906
+					if (is_array($cns) && count($cns) > 0) {
907 907
 						$filter .= '(|';
908 908
 						$cr = $this->getConnection();
909
-						if(!$cr) {
909
+						if (!$cr) {
910 910
 							throw new \Exception('Could not connect to LDAP');
911 911
 						}
912 912
 						$base = $this->configuration->ldapBase[0];
913
-						foreach($cns as $cn) {
914
-							$rr = $this->ldap->search($cr, $base, 'cn=' . $cn, ['dn', 'primaryGroupToken']);
915
-							if(!$this->ldap->isResource($rr)) {
913
+						foreach ($cns as $cn) {
914
+							$rr = $this->ldap->search($cr, $base, 'cn='.$cn, ['dn', 'primaryGroupToken']);
915
+							if (!$this->ldap->isResource($rr)) {
916 916
 								continue;
917 917
 							}
918 918
 							$er = $this->ldap->firstEntry($cr, $rr);
@@ -921,11 +921,11 @@  discard block
 block discarded – undo
921 921
 							if ($dn === false || $dn === '') {
922 922
 								continue;
923 923
 							}
924
-							$filterPart = '(memberof=' . $dn . ')';
925
-							if(isset($attrs['primaryGroupToken'])) {
924
+							$filterPart = '(memberof='.$dn.')';
925
+							if (isset($attrs['primaryGroupToken'])) {
926 926
 								$pgt = $attrs['primaryGroupToken'][0];
927
-								$primaryFilterPart = '(primaryGroupID=' . $pgt .')';
928
-								$filterPart = '(|' . $filterPart . $primaryFilterPart . ')';
927
+								$primaryFilterPart = '(primaryGroupID='.$pgt.')';
928
+								$filterPart = '(|'.$filterPart.$primaryFilterPart.')';
929 929
 							}
930 930
 							$filter .= $filterPart;
931 931
 						}
@@ -934,8 +934,8 @@  discard block
 block discarded – undo
934 934
 					$parts++;
935 935
 				}
936 936
 				//wrap parts in AND condition
937
-				if($parts > 1) {
938
-					$filter = '(&' . $filter . ')';
937
+				if ($parts > 1) {
938
+					$filter = '(&'.$filter.')';
939 939
 				}
940 940
 				if ($filter === '') {
941 941
 					$filter = '(objectclass=*)';
@@ -945,27 +945,27 @@  discard block
 block discarded – undo
945 945
 			case self::LFILTER_GROUP_LIST:
946 946
 				$objcs = $this->configuration->ldapGroupFilterObjectclass;
947 947
 				//glue objectclasses
948
-				if(is_array($objcs) && count($objcs) > 0) {
948
+				if (is_array($objcs) && count($objcs) > 0) {
949 949
 					$filter .= '(|';
950
-					foreach($objcs as $objc) {
951
-						$filter .= '(objectclass=' . $objc . ')';
950
+					foreach ($objcs as $objc) {
951
+						$filter .= '(objectclass='.$objc.')';
952 952
 					}
953 953
 					$filter .= ')';
954 954
 					$parts++;
955 955
 				}
956 956
 				//glue group memberships
957 957
 				$cns = $this->configuration->ldapGroupFilterGroups;
958
-				if(is_array($cns) && count($cns) > 0) {
958
+				if (is_array($cns) && count($cns) > 0) {
959 959
 					$filter .= '(|';
960
-					foreach($cns as $cn) {
961
-						$filter .= '(cn=' . $cn . ')';
960
+					foreach ($cns as $cn) {
961
+						$filter .= '(cn='.$cn.')';
962 962
 					}
963 963
 					$filter .= ')';
964 964
 				}
965 965
 				$parts++;
966 966
 				//wrap parts in AND condition
967
-				if($parts > 1) {
968
-					$filter = '(&' . $filter . ')';
967
+				if ($parts > 1) {
968
+					$filter = '(&'.$filter.')';
969 969
 				}
970 970
 				break;
971 971
 
@@ -977,47 +977,47 @@  discard block
 block discarded – undo
977 977
 				$userAttributes = array_change_key_case(array_flip($userAttributes));
978 978
 				$parts = 0;
979 979
 
980
-				if($this->configuration->ldapLoginFilterUsername === '1') {
980
+				if ($this->configuration->ldapLoginFilterUsername === '1') {
981 981
 					$attr = '';
982
-					if(isset($userAttributes['uid'])) {
982
+					if (isset($userAttributes['uid'])) {
983 983
 						$attr = 'uid';
984
-					} else if(isset($userAttributes['samaccountname'])) {
984
+					} else if (isset($userAttributes['samaccountname'])) {
985 985
 						$attr = 'samaccountname';
986
-					} else if(isset($userAttributes['cn'])) {
986
+					} else if (isset($userAttributes['cn'])) {
987 987
 						//fallback
988 988
 						$attr = 'cn';
989 989
 					}
990 990
 					if ($attr !== '') {
991
-						$filterUsername = '(' . $attr . $loginpart . ')';
991
+						$filterUsername = '('.$attr.$loginpart.')';
992 992
 						$parts++;
993 993
 					}
994 994
 				}
995 995
 
996 996
 				$filterEmail = '';
997
-				if($this->configuration->ldapLoginFilterEmail === '1') {
997
+				if ($this->configuration->ldapLoginFilterEmail === '1') {
998 998
 					$filterEmail = '(|(mailPrimaryAddress=%uid)(mail=%uid))';
999 999
 					$parts++;
1000 1000
 				}
1001 1001
 
1002 1002
 				$filterAttributes = '';
1003 1003
 				$attrsToFilter = $this->configuration->ldapLoginFilterAttributes;
1004
-				if(is_array($attrsToFilter) && count($attrsToFilter) > 0) {
1004
+				if (is_array($attrsToFilter) && count($attrsToFilter) > 0) {
1005 1005
 					$filterAttributes = '(|';
1006
-					foreach($attrsToFilter as $attribute) {
1007
-						$filterAttributes .= '(' . $attribute . $loginpart . ')';
1006
+					foreach ($attrsToFilter as $attribute) {
1007
+						$filterAttributes .= '('.$attribute.$loginpart.')';
1008 1008
 					}
1009 1009
 					$filterAttributes .= ')';
1010 1010
 					$parts++;
1011 1011
 				}
1012 1012
 
1013 1013
 				$filterLogin = '';
1014
-				if($parts > 1) {
1014
+				if ($parts > 1) {
1015 1015
 					$filterLogin = '(|';
1016 1016
 				}
1017 1017
 				$filterLogin .= $filterUsername;
1018 1018
 				$filterLogin .= $filterEmail;
1019 1019
 				$filterLogin .= $filterAttributes;
1020
-				if($parts > 1) {
1020
+				if ($parts > 1) {
1021 1021
 					$filterLogin .= ')';
1022 1022
 				}
1023 1023
 
@@ -1042,12 +1042,12 @@  discard block
 block discarded – undo
1042 1042
 		//connect, does not really trigger any server communication
1043 1043
 		$host = $this->configuration->ldapHost;
1044 1044
 		$hostInfo = parse_url($host);
1045
-		if(!$hostInfo) {
1045
+		if (!$hostInfo) {
1046 1046
 			throw new \Exception(self::$l->t('Invalid Host'));
1047 1047
 		}
1048 1048
 		\OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', ILogger::DEBUG);
1049 1049
 		$cr = $this->ldap->connect($host, $port);
1050
-		if(!is_resource($cr)) {
1050
+		if (!is_resource($cr)) {
1051 1051
 			throw new \Exception(self::$l->t('Invalid Host'));
1052 1052
 		}
1053 1053
 
@@ -1057,9 +1057,9 @@  discard block
 block discarded – undo
1057 1057
 		$this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT);
1058 1058
 
1059 1059
 		try {
1060
-			if($tls) {
1060
+			if ($tls) {
1061 1061
 				$isTlsWorking = @$this->ldap->startTls($cr);
1062
-				if(!$isTlsWorking) {
1062
+				if (!$isTlsWorking) {
1063 1063
 					return false;
1064 1064
 				}
1065 1065
 			}
@@ -1073,17 +1073,17 @@  discard block
 block discarded – undo
1073 1073
 			$errNo = $this->ldap->errno($cr);
1074 1074
 			$error = ldap_error($cr);
1075 1075
 			$this->ldap->unbind($cr);
1076
-		} catch(ServerNotAvailableException $e) {
1076
+		} catch (ServerNotAvailableException $e) {
1077 1077
 			return false;
1078 1078
 		}
1079 1079
 
1080
-		if($login === true) {
1080
+		if ($login === true) {
1081 1081
 			$this->ldap->unbind($cr);
1082
-			\OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . (int)$tls, ILogger::DEBUG);
1082
+			\OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '.$port.' TLS '.(int) $tls, ILogger::DEBUG);
1083 1083
 			return true;
1084 1084
 		}
1085 1085
 
1086
-		if($errNo === -1) {
1086
+		if ($errNo === -1) {
1087 1087
 			//host, port or TLS wrong
1088 1088
 			return false;
1089 1089
 		}
@@ -1111,9 +1111,9 @@  discard block
 block discarded – undo
1111 1111
 	 */
1112 1112
 	private function checkRequirements($reqs) {
1113 1113
 		$this->checkAgentRequirements();
1114
-		foreach($reqs as $option) {
1114
+		foreach ($reqs as $option) {
1115 1115
 			$value = $this->configuration->$option;
1116
-			if(empty($value)) {
1116
+			if (empty($value)) {
1117 1117
 				return false;
1118 1118
 			}
1119 1119
 		}
@@ -1135,33 +1135,33 @@  discard block
 block discarded – undo
1135 1135
 		$dnRead = [];
1136 1136
 		$foundItems = [];
1137 1137
 		$maxEntries = 0;
1138
-		if(!is_array($this->configuration->ldapBase)
1138
+		if (!is_array($this->configuration->ldapBase)
1139 1139
 		   || !isset($this->configuration->ldapBase[0])) {
1140 1140
 			return false;
1141 1141
 		}
1142 1142
 		$base = $this->configuration->ldapBase[0];
1143 1143
 		$cr = $this->getConnection();
1144
-		if(!$this->ldap->isResource($cr)) {
1144
+		if (!$this->ldap->isResource($cr)) {
1145 1145
 			return false;
1146 1146
 		}
1147 1147
 		$lastFilter = null;
1148
-		if(isset($filters[count($filters)-1])) {
1149
-			$lastFilter = $filters[count($filters)-1];
1148
+		if (isset($filters[count($filters) - 1])) {
1149
+			$lastFilter = $filters[count($filters) - 1];
1150 1150
 		}
1151
-		foreach($filters as $filter) {
1152
-			if($lastFilter === $filter && count($foundItems) > 0) {
1151
+		foreach ($filters as $filter) {
1152
+			if ($lastFilter === $filter && count($foundItems) > 0) {
1153 1153
 				//skip when the filter is a wildcard and results were found
1154 1154
 				continue;
1155 1155
 			}
1156 1156
 			// 20k limit for performance and reason
1157 1157
 			$rr = $this->ldap->search($cr, $base, $filter, [$attr], 0, 20000);
1158
-			if(!$this->ldap->isResource($rr)) {
1158
+			if (!$this->ldap->isResource($rr)) {
1159 1159
 				continue;
1160 1160
 			}
1161 1161
 			$entries = $this->ldap->countEntries($cr, $rr);
1162 1162
 			$getEntryFunc = 'firstEntry';
1163
-			if(($entries !== false) && ($entries > 0)) {
1164
-				if(!is_null($maxF) && $entries > $maxEntries) {
1163
+			if (($entries !== false) && ($entries > 0)) {
1164
+				if (!is_null($maxF) && $entries > $maxEntries) {
1165 1165
 					$maxEntries = $entries;
1166 1166
 					$maxF = $filter;
1167 1167
 				}
@@ -1169,13 +1169,13 @@  discard block
 block discarded – undo
1169 1169
 				do {
1170 1170
 					$entry = $this->ldap->$getEntryFunc($cr, $rr);
1171 1171
 					$getEntryFunc = 'nextEntry';
1172
-					if(!$this->ldap->isResource($entry)) {
1172
+					if (!$this->ldap->isResource($entry)) {
1173 1173
 						continue 2;
1174 1174
 					}
1175 1175
 					$rr = $entry; //will be expected by nextEntry next round
1176 1176
 					$attributes = $this->ldap->getAttributes($cr, $entry);
1177 1177
 					$dn = $this->ldap->getDN($cr, $entry);
1178
-					if($dn === false || in_array($dn, $dnRead)) {
1178
+					if ($dn === false || in_array($dn, $dnRead)) {
1179 1179
 						continue;
1180 1180
 					}
1181 1181
 					$newItems = [];
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
 					$foundItems = array_merge($foundItems, $newItems);
1187 1187
 					$this->resultCache[$dn][$attr] = $newItems;
1188 1188
 					$dnRead[] = $dn;
1189
-				} while(($state === self::LRESULT_PROCESSED_SKIP
1189
+				} while (($state === self::LRESULT_PROCESSED_SKIP
1190 1190
 						|| $this->ldap->isResource($entry))
1191 1191
 						&& ($dnReadLimit === 0 || $dnReadCount < $dnReadLimit));
1192 1192
 			}
@@ -1209,11 +1209,11 @@  discard block
 block discarded – undo
1209 1209
 	 */
1210 1210
 	private function determineFeature($objectclasses, $attr, $dbkey, $confkey, $po = false) {
1211 1211
 		$cr = $this->getConnection();
1212
-		if(!$cr) {
1212
+		if (!$cr) {
1213 1213
 			throw new \Exception('Could not connect to LDAP');
1214 1214
 		}
1215 1215
 		$p = 'objectclass=';
1216
-		foreach($objectclasses as $key => $value) {
1216
+		foreach ($objectclasses as $key => $value) {
1217 1217
 			$objectclasses[$key] = $p.$value;
1218 1218
 		}
1219 1219
 		$maxEntryObjC = '';
@@ -1225,7 +1225,7 @@  discard block
 block discarded – undo
1225 1225
 		$availableFeatures =
1226 1226
 			$this->cumulativeSearchOnAttribute($objectclasses, $attr,
1227 1227
 											   $dig, $maxEntryObjC);
1228
-		if(is_array($availableFeatures)
1228
+		if (is_array($availableFeatures)
1229 1229
 		   && count($availableFeatures) > 0) {
1230 1230
 			natcasesort($availableFeatures);
1231 1231
 			//natcasesort keeps indices, but we must get rid of them for proper
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
 		}
1237 1237
 
1238 1238
 		$setFeatures = $this->configuration->$confkey;
1239
-		if(is_array($setFeatures) && !empty($setFeatures)) {
1239
+		if (is_array($setFeatures) && !empty($setFeatures)) {
1240 1240
 			//something is already configured? pre-select it.
1241 1241
 			$this->result->addChange($dbkey, $setFeatures);
1242 1242
 		} else if ($po && $maxEntryObjC !== '') {
@@ -1258,7 +1258,7 @@  discard block
 block discarded – undo
1258 1258
 	 * LRESULT_PROCESSED_INVALID or LRESULT_PROCESSED_SKIP
1259 1259
 	 */
1260 1260
 	private function getAttributeValuesFromEntry($result, $attribute, &$known) {
1261
-		if(!is_array($result)
1261
+		if (!is_array($result)
1262 1262
 		   || !isset($result['count'])
1263 1263
 		   || !$result['count'] > 0) {
1264 1264
 			return self::LRESULT_PROCESSED_INVALID;
@@ -1267,12 +1267,12 @@  discard block
 block discarded – undo
1267 1267
 		// strtolower on all keys for proper comparison
1268 1268
 		$result = \OCP\Util::mb_array_change_key_case($result);
1269 1269
 		$attribute = strtolower($attribute);
1270
-		if(isset($result[$attribute])) {
1271
-			foreach($result[$attribute] as $key => $val) {
1272
-				if($key === 'count') {
1270
+		if (isset($result[$attribute])) {
1271
+			foreach ($result[$attribute] as $key => $val) {
1272
+				if ($key === 'count') {
1273 1273
 					continue;
1274 1274
 				}
1275
-				if(!in_array($val, $known)) {
1275
+				if (!in_array($val, $known)) {
1276 1276
 					$known[] = $val;
1277 1277
 				}
1278 1278
 			}
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
 	 * @return bool|mixed
1287 1287
 	 */
1288 1288
 	private function getConnection() {
1289
-		if(!is_null($this->cr)) {
1289
+		if (!is_null($this->cr)) {
1290 1290
 			return $this->cr;
1291 1291
 		}
1292 1292
 
@@ -1298,14 +1298,14 @@  discard block
 block discarded – undo
1298 1298
 		$this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
1299 1299
 		$this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0);
1300 1300
 		$this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT);
1301
-		if($this->configuration->ldapTLS === 1) {
1301
+		if ($this->configuration->ldapTLS === 1) {
1302 1302
 			$this->ldap->startTls($cr);
1303 1303
 		}
1304 1304
 
1305 1305
 		$lo = @$this->ldap->bind($cr,
1306 1306
 								 $this->configuration->ldapAgentName,
1307 1307
 								 $this->configuration->ldapAgentPassword);
1308
-		if($lo === true) {
1308
+		if ($lo === true) {
1309 1309
 			$this->$cr = $cr;
1310 1310
 			return $cr;
1311 1311
 		}
@@ -1336,18 +1336,18 @@  discard block
 block discarded – undo
1336 1336
 		//636 ← LDAPS / SSL
1337 1337
 		//7xxx ← UCS. need to be checked first, because both ports may be open
1338 1338
 		$host = $this->configuration->ldapHost;
1339
-		$port = (int)$this->configuration->ldapPort;
1339
+		$port = (int) $this->configuration->ldapPort;
1340 1340
 		$portSettings = [];
1341 1341
 
1342 1342
 		//In case the port is already provided, we will check this first
1343
-		if($port > 0) {
1343
+		if ($port > 0) {
1344 1344
 			$hostInfo = parse_url($host);
1345
-			if(!(is_array($hostInfo)
1345
+			if (!(is_array($hostInfo)
1346 1346
 				&& isset($hostInfo['scheme'])
1347 1347
 				&& stripos($hostInfo['scheme'], 'ldaps') !== false)) {
1348 1348
 				$portSettings[] = ['port' => $port, 'tls' => true];
1349 1349
 			}
1350
-			$portSettings[] =['port' => $port, 'tls' => false];
1350
+			$portSettings[] = ['port' => $port, 'tls' => false];
1351 1351
 		}
1352 1352
 
1353 1353
 		//default ports
Please login to merge, or discard this patch.
apps/user_ldap/ajax/setConfiguration.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@
 block discarded – undo
30 30
 \OC_JSON::checkAppEnabled('user_ldap');
31 31
 \OC_JSON::callCheck();
32 32
 
33
-$prefix = (string)$_POST['ldap_serverconfig_chooser'];
33
+$prefix = (string) $_POST['ldap_serverconfig_chooser'];
34 34
 
35 35
 // Checkboxes are not submitted, when they are unchecked. Set them manually.
36 36
 // only legacy checkboxes (Advanced and Expert tab) need to be handled here,
37 37
 // the Wizard-like tabs handle it on their own
38 38
 $chkboxes = ['ldap_configuration_active', 'ldap_override_main_server',
39 39
 	'ldap_turn_off_cert_check'];
40
-foreach($chkboxes as $boxid) {
41
-	if(!isset($_POST[$boxid])) {
40
+foreach ($chkboxes as $boxid) {
41
+	if (!isset($_POST[$boxid])) {
42 42
 		$_POST[$boxid] = 0;
43 43
 	}
44 44
 }
Please login to merge, or discard this patch.
apps/dav/lib/DAV/Sharing/Xml/ShareRequest.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	static function xmlDeserialize(Reader $reader) {
50 50
 
51 51
 		$elements = $reader->parseInnerTree([
52
-			'{' . Plugin::NS_OWNCLOUD. '}set'    => 'Sabre\\Xml\\Element\\KeyValue',
53
-			'{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue',
52
+			'{'.Plugin::NS_OWNCLOUD.'}set'    => 'Sabre\\Xml\\Element\\KeyValue',
53
+			'{'.Plugin::NS_OWNCLOUD.'}remove' => 'Sabre\\Xml\\Element\\KeyValue',
54 54
 		]);
55 55
 
56 56
 		$set = [];
@@ -59,21 +59,21 @@  discard block
 block discarded – undo
59 59
 		foreach ($elements as $elem) {
60 60
 			switch ($elem['name']) {
61 61
 
62
-				case '{' . Plugin::NS_OWNCLOUD . '}set' :
62
+				case '{'.Plugin::NS_OWNCLOUD.'}set' :
63 63
 					$sharee = $elem['value'];
64 64
 
65
-					$sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary';
66
-					$commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name';
65
+					$sumElem = '{'.Plugin::NS_OWNCLOUD.'}summary';
66
+					$commonName = '{'.Plugin::NS_OWNCLOUD.'}common-name';
67 67
 
68 68
 					$set[] = [
69 69
 						'href'       => $sharee['{DAV:}href'],
70 70
 						'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null,
71 71
 						'summary'    => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null,
72
-						'readOnly'   => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee),
72
+						'readOnly'   => !array_key_exists('{'.Plugin::NS_OWNCLOUD.'}read-write', $sharee),
73 73
 					];
74 74
 					break;
75 75
 
76
-				case '{' . Plugin::NS_OWNCLOUD . '}remove' :
76
+				case '{'.Plugin::NS_OWNCLOUD.'}remove' :
77 77
 					$remove[] = $elem['value']['{DAV:}href'];
78 78
 					break;
79 79
 
Please login to merge, or discard this patch.