Completed
Push — stable8.2 ( 458a90...47a1fb )
by Morris
115:41
created

Connection::getConfiguration()   D

Complexity

Conditions 10
Paths 14

Size

Total Lines 29
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110
Metric Value
dl 0
loc 29
ccs 0
cts 25
cp 0
rs 4.8197
cc 10
eloc 24
nc 14
nop 0
crap 110

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @author Arthur Schiwon <[email protected]>
4
 * @author Bart Visscher <[email protected]>
5
 * @author Jörn Friedrich Dreyer <[email protected]>
6
 * @author Lukas Reschke <[email protected]>
7
 * @author Lyonel Vincent <[email protected]>
8
 * @author Morris Jobke <[email protected]>
9
 * @author Robin Appelman <[email protected]>
10
 * @author Robin McCorkell <[email protected]>
11
 * @author Scrutinizer Auto-Fixer <[email protected]>
12
 *
13
 * @copyright Copyright (c) 2015, ownCloud, Inc.
14
 * @license AGPL-3.0
15
 *
16
 * This code is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License, version 3,
18
 * as published by the Free Software Foundation.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License, version 3,
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
27
 *
28
 */
29
30
namespace OCA\user_ldap\lib;
31
32
use OC\ServerNotAvailableException;
33
34
/**
35
 * magic properties (incomplete)
36
 * responsible for LDAP connections in context with the provided configuration
37
 *
38
 * @property string ldapUserFilter
39
 * @property string ldapUserDisplayName
40
 * @property boolean hasPagedResultSupport
41
 * @property string[] ldapBaseUsers
42
 * @property int|string ldapPagingSize holds an integer
43
 * @property bool|mixed|void ldapGroupMemberAssocAttr
44
 */
45
class Connection extends LDAPUtility {
46
	private $ldapConnectionRes = null;
47
	private $configPrefix;
48
	private $configID;
49
	private $configured = false;
50
51
	//whether connection should be kept on __destruct
52
	private $dontDestruct = false;
53
	private $hasPagedResultSupport = true;
54
55
	/**
56
	 * @var bool runtime flag that indicates whether supported primary groups are available
57
	 */
58
	public $hasPrimaryGroups = true;
59
60
	//cache handler
61
	protected $cache;
62
63
	/** @var Configuration settings handler **/
64
	protected $configuration;
65
66
	protected $doNotValidate = false;
67
68
	protected $ignoreValidation = false;
69
70
	/**
71
	 * Constructor
72
	 * @param ILDAPWrapper $ldap
73
	 * @param string $configPrefix a string with the prefix for the configkey column (appconfig table)
74
	 * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
75
	 */
76 100
	public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') {
77 100
		parent::__construct($ldap);
78 100
		$this->configPrefix = $configPrefix;
79 100
		$this->configID = $configID;
80 100
		$this->configuration = new Configuration($configPrefix,
81 100
												 !is_null($configID));
82 100
		$memcache = \OC::$server->getMemCacheFactory();
83 100
		if($memcache->isAvailable()) {
84 100
			$this->cache = $memcache->create();
85 100
		}
86 100
		$this->hasPagedResultSupport =
87 100
			$this->ldap->hasPagedResultSupport();
88 100
		$helper = new Helper();
89 100
		$this->doNotValidate = !in_array($this->configPrefix,
90 100
			$helper->getServerConfigurationPrefixes());
91 100
	}
92
93 9
	public function __destruct() {
94 9
		if(!$this->dontDestruct &&
95 9
			$this->ldap->isResource($this->ldapConnectionRes)) {
96
			@$this->ldap->unbind($this->ldapConnectionRes);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
97 9
		};
98 9
	}
99
100
	/**
101
	 * defines behaviour when the instance is cloned
102
	 */
103 1
	public function __clone() {
104
		//a cloned instance inherits the connection resource. It may use it,
105
		//but it may not disconnect it
106 1
		$this->dontDestruct = true;
107 1
		$this->configuration = new Configuration($this->configPrefix,
108 1
												 !is_null($this->configID));
109 1
	}
110
111
	/**
112
	 * @param string $name
113
	 * @return bool|mixed|void
114
	 */
115 3
	public function __get($name) {
116 3
		if(!$this->configured) {
117 3
			$this->readConfiguration();
118 3
		}
119
120 3
		if($name === 'hasPagedResultSupport') {
121
			return $this->hasPagedResultSupport;
122
		}
123
124 3
		return $this->configuration->$name;
125
	}
126
127
	/**
128
	 * @param string $name
129
	 * @param mixed $value
130
	 */
131
	public function __set($name, $value) {
132
		$this->doNotValidate = false;
133
		$before = $this->configuration->$name;
134
		$this->configuration->$name = $value;
135
		$after = $this->configuration->$name;
136
		if($before !== $after) {
137
			if(!empty($this->configID)) {
138
				$this->configuration->saveConfiguration();
139
			}
140
			$this->validateConfiguration();
141
		}
142
	}
143
144
	/**
145
	 * sets whether the result of the configuration validation shall
146
	 * be ignored when establishing the connection. Used by the Wizard
147
	 * in early configuration state.
148
	 * @param bool $state
149
	 */
150
	public function setIgnoreValidation($state) {
151
		$this->ignoreValidation = (bool)$state;
152
	}
153
154
	/**
155
	 * initializes the LDAP backend
156
	 * @param bool $force read the config settings no matter what
157
	 */
158
	public function init($force = false) {
159
		$this->readConfiguration($force);
160
		$this->establishConnection();
161
	}
162
163
	/**
164
	 * Returns the LDAP handler
165
	 */
166
	public function getConnectionResource() {
167
		if(!$this->ldapConnectionRes) {
168
			$this->init();
169
		} else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
170
			$this->ldapConnectionRes = null;
171
			$this->establishConnection();
172
		}
173
		if(is_null($this->ldapConnectionRes)) {
174
			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR);
0 ignored issues
show
Documentation introduced by
The property ldapHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
175
			throw new ServerNotAvailableException('Connection to LDAP server could not be established');
176
		}
177
		return $this->ldapConnectionRes;
178
	}
179
180
	/**
181
	 * @param string|null $key
182
	 * @return string
183
	 */
184
	private function getCacheKey($key) {
185
		$prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
186
		if(is_null($key)) {
187
			return $prefix;
188
		}
189
		return $prefix.md5($key);
190
	}
191
192
	/**
193
	 * @param string $key
194
	 * @return mixed|null
195
	 */
196
	public function getFromCache($key) {
197
		if(!$this->configured) {
198
			$this->readConfiguration();
199
		}
200
		if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
0 ignored issues
show
Documentation introduced by
The property ldapCacheTTL does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
201
			return null;
202
		}
203
		if(!$this->isCached($key)) {
204
			return null;
205
206
		}
207
		$key = $this->getCacheKey($key);
208
209
		return json_decode(base64_decode($this->cache->get($key)));
210
	}
211
212
	/**
213
	 * @param string $key
214
	 * @return bool
215
	 */
216
	public function isCached($key) {
217
		if(!$this->configured) {
218
			$this->readConfiguration();
219
		}
220
		if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
0 ignored issues
show
Documentation introduced by
The property ldapCacheTTL does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
221
			return false;
222
		}
223
		$key = $this->getCacheKey($key);
224
		return $this->cache->hasKey($key);
225
	}
226
227
	/**
228
	 * @param string $key
229
	 * @param mixed $value
230
	 *
231
	 * @return string
232
	 */
233
	public function writeToCache($key, $value) {
234
		if(!$this->configured) {
235
			$this->readConfiguration();
236
		}
237
		if(is_null($this->cache)
238
			|| !$this->configuration->ldapCacheTTL
0 ignored issues
show
Documentation introduced by
The property ldapCacheTTL does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
239
			|| !$this->configuration->ldapConfigurationActive) {
0 ignored issues
show
Bug introduced by
The property ldapConfigurationActive does not seem to exist. Did you mean config?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
240
			return null;
241
		}
242
		$key   = $this->getCacheKey($key);
243
		$value = base64_encode(json_encode($value));
244
		$this->cache->set($key, $value, $this->configuration->ldapCacheTTL);
0 ignored issues
show
Documentation introduced by
The property ldapCacheTTL does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
245
	}
246
247
	public function clearCache() {
248
		if(!is_null($this->cache)) {
249
			$this->cache->clear($this->getCacheKey(null));
250
		}
251
	}
252
253
	/**
254
	 * Caches the general LDAP configuration.
255
	 * @param bool $force optional. true, if the re-read should be forced. defaults
256
	 * to false.
257
	 * @return null
258
	 */
259 3
	private function readConfiguration($force = false) {
260 3
		if((!$this->configured || $force) && !is_null($this->configID)) {
261
			$this->configuration->readConfiguration();
262
			$this->configured = $this->validateConfiguration();
263
		}
264 3
	}
265
266
	/**
267
	 * set LDAP configuration with values delivered by an array, not read from configuration
268
	 * @param array $config array that holds the config parameters in an associated array
269
	 * @param array &$setParameters optional; array where the set fields will be given to
270
	 * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
271
	 */
272 2
	public function setConfiguration($config, &$setParameters = null) {
273 2
		if(is_null($setParameters)) {
274 2
			$setParameters = array();
275 2
		}
276 2
		$this->doNotValidate = false;
277 2
		$this->configuration->setConfiguration($config, $setParameters);
278 2
		if(count($setParameters) > 0) {
279 2
			$this->configured = $this->validateConfiguration();
280 2
		}
281
282
283 2
		return $this->configured;
284
	}
285
286
	/**
287
	 * saves the current Configuration in the database and empties the
288
	 * cache
289
	 * @return null
290
	 */
291
	public function saveConfiguration() {
292
		$this->configuration->saveConfiguration();
293
		$this->clearCache();
294
	}
295
296
	/**
297
	 * get the current LDAP configuration
298
	 * @return array
299
	 */
300
	public function getConfiguration() {
301
		$this->readConfiguration();
302
		$config = $this->configuration->getConfiguration();
303
		$cta = $this->configuration->getConfigTranslationArray();
304
		$result = array();
305
		foreach($cta as $dbkey => $configkey) {
306
			switch($configkey) {
307
				case 'homeFolderNamingRule':
308
					if(strpos($config[$configkey], 'attr:') === 0) {
309
						$result[$dbkey] = substr($config[$configkey], 5);
310
					} else {
311
						$result[$dbkey] = '';
312
					}
313
					break;
314
				case 'ldapBase':
315
				case 'ldapBaseUsers':
316
				case 'ldapBaseGroups':
317
				case 'ldapAttributesForUserSearch':
318
				case 'ldapAttributesForGroupSearch':
319
					if(is_array($config[$configkey])) {
320
						$result[$dbkey] = implode("\n", $config[$configkey]);
321
						break;
322
					} //else follows default
323
				default:
324
					$result[$dbkey] = $config[$configkey];
325
			}
326
		}
327
		return $result;
328
	}
329
330 2
	private function doSoftValidation() {
331
		//if User or Group Base are not set, take over Base DN setting
332 2
		foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
333 2
			$val = $this->configuration->$keyBase;
334 2
			if(empty($val)) {
335 2
				$obj = strpos('Users', $keyBase) !== false ? 'Users' : 'Groups';
336 2
				\OCP\Util::writeLog('user_ldap',
337 2
									'Base tree for '.$obj.
338 2
									' is empty, using Base DN',
339 2
									\OCP\Util::INFO);
340 2
				$this->configuration->$keyBase = $this->configuration->ldapBase;
0 ignored issues
show
Documentation introduced by
The property ldapBase does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
341 2
			}
342 2
		}
343
344 2
		foreach(array('ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
345 2
					  'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute')
346 2
				as $expertSetting => $effectiveSetting) {
347 2
			$uuidOverride = $this->configuration->$expertSetting;
348 2
			if(!empty($uuidOverride)) {
349
				$this->configuration->$effectiveSetting = $uuidOverride;
350
			} else {
351 2
				$uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid',
352 2
										'objectguid', 'guid');
353 2
				if(!in_array($this->configuration->$effectiveSetting,
354 2
							$uuidAttributes)
355 2
					&& (!is_null($this->configID))) {
356
					$this->configuration->$effectiveSetting = 'auto';
357
					$this->configuration->saveConfiguration();
358
					\OCP\Util::writeLog('user_ldap',
359
										'Illegal value for the '.
360
										$effectiveSetting.', '.'reset to '.
361
										'autodetect.', \OCP\Util::INFO);
362
				}
363
364
			}
365 2
		}
366
367 2
		$backupPort = $this->configuration->ldapBackupPort;
0 ignored issues
show
Documentation introduced by
The property ldapBackupPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
368 2
		if(empty($backupPort)) {
369 2
			$this->configuration->backupPort = $this->configuration->ldapPort;
0 ignored issues
show
Documentation introduced by
The property backupPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property ldapPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
370 2
		}
371
372
		//make sure empty search attributes are saved as simple, empty array
373 2
		$saKeys = array('ldapAttributesForUserSearch',
374 2
						'ldapAttributesForGroupSearch');
375 2
		foreach($saKeys as $key) {
376 2
			$val = $this->configuration->$key;
377 2
			if(is_array($val) && count($val) === 1 && empty($val[0])) {
378
				$this->configuration->$key = array();
379
			}
380 2
		}
381
382 2
		if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
0 ignored issues
show
Documentation introduced by
The property ldapHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
383 2
			&& $this->configuration->ldapTLS) {
0 ignored issues
show
Documentation introduced by
The property ldapTLS does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
384
			$this->configuration->ldapTLS = false;
0 ignored issues
show
Documentation introduced by
The property ldapTLS does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
385
			\OCP\Util::writeLog('user_ldap',
386
								'LDAPS (already using secure connection) and '.
387
								'TLS do not work together. Switched off TLS.',
388
								\OCP\Util::INFO);
389
		}
390 2
	}
391
392
	/**
393
	 * @return bool
394
	 */
395 2
	private function doCriticalValidation() {
396 2
		$configurationOK = true;
397
		$errorStr = 'Configuration Error (prefix '.
398 2
					strval($this->configPrefix).'): ';
399
400
		//options that shall not be empty
401 2
		$options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName',
402 2
						 'ldapGroupDisplayName', 'ldapLoginFilter');
403 2
		foreach($options as $key) {
404 2
			$val = $this->configuration->$key;
405 2
			if(empty($val)) {
406
				switch($key) {
407 2
					case 'ldapHost':
408 2
						$subj = 'LDAP Host';
409 2
						break;
410 2
					case 'ldapPort':
411 2
						$subj = 'LDAP Port';
412 2
						break;
413 2
					case 'ldapUserDisplayName':
414 2
						$subj = 'LDAP User Display Name';
415 2
						break;
416 2
					case 'ldapGroupDisplayName':
417 2
						$subj = 'LDAP Group Display Name';
418 2
						break;
419 2
					case 'ldapLoginFilter':
420 2
						$subj = 'LDAP Login Filter';
421 2
						break;
422
					default:
423
						$subj = $key;
424
						break;
425
				}
426 2
				$configurationOK = false;
427 2
				\OCP\Util::writeLog('user_ldap',
428 2
									$errorStr.'No '.$subj.' given!',
429 2
									\OCP\Util::WARN);
430 2
			}
431 2
		}
432
433
		//combinations
434 2
		$agent = $this->configuration->ldapAgentName;
0 ignored issues
show
Documentation introduced by
The property ldapAgentName does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
435 2
		$pwd = $this->configuration->ldapAgentPassword;
0 ignored issues
show
Documentation introduced by
The property ldapAgentPassword does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
436 2
		if((empty($agent) && !empty($pwd)) || (!empty($agent) && empty($pwd))) {
437
			\OCP\Util::writeLog('user_ldap',
438
								$errorStr.'either no password is given for the'.
439
								'user agent or a password is given, but not an'.
440
								'LDAP agent.',
441
				\OCP\Util::WARN);
442
			$configurationOK = false;
443
		}
444
445 2
		$base = $this->configuration->ldapBase;
0 ignored issues
show
Documentation introduced by
The property ldapBase does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
446 2
		$baseUsers = $this->configuration->ldapBaseUsers;
0 ignored issues
show
Documentation introduced by
The property ldapBaseUsers does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
447 2
		$baseGroups = $this->configuration->ldapBaseGroups;
0 ignored issues
show
Documentation introduced by
The property ldapBaseGroups does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
448
449 2
		if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
450 2
			\OCP\Util::writeLog('user_ldap',
451 2
								$errorStr.'Not a single Base DN given.',
452 2
								\OCP\Util::WARN);
453 2
			$configurationOK = false;
454 2
		}
455
456 2
		if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
0 ignored issues
show
Documentation introduced by
The property ldapLoginFilter does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
457 2
		   === false) {
458 2
			\OCP\Util::writeLog('user_ldap',
459 2
								$errorStr.'login filter does not contain %uid '.
460 2
								'place holder.',
461 2
								\OCP\Util::WARN);
462 2
			$configurationOK = false;
463 2
		}
464
465 2
		return $configurationOK;
466
	}
467
468
	/**
469
	 * Validates the user specified configuration
470
	 * @return bool true if configuration seems OK, false otherwise
471
	 */
472 2
	private function validateConfiguration() {
473
474 2
		if($this->doNotValidate) {
475
			//don't do a validation if it is a new configuration with pure
476
			//default values. Will be allowed on changes via __set or
477
			//setConfiguration
478
			return false;
479
		}
480
481
		// first step: "soft" checks: settings that are not really
482
		// necessary, but advisable. If left empty, give an info message
483 2
		$this->doSoftValidation();
484
485
		//second step: critical checks. If left empty or filled wrong, mark as
486
		//not configured and give a warning.
487 2
		return $this->doCriticalValidation();
488
	}
489
490
491
	/**
492
	 * Connects and Binds to LDAP
493
	 */
494
	private function establishConnection() {
495
		if(!$this->configuration->ldapConfigurationActive) {
0 ignored issues
show
Bug introduced by
The property ldapConfigurationActive does not seem to exist. Did you mean config?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
496
			return null;
497
		}
498
		static $phpLDAPinstalled = true;
499
		if(!$phpLDAPinstalled) {
500
			return false;
501
		}
502
		if(!$this->ignoreValidation && !$this->configured) {
503
			\OCP\Util::writeLog('user_ldap',
504
								'Configuration is invalid, cannot connect',
505
								\OCP\Util::WARN);
506
			return false;
507
		}
508
		if(!$this->ldapConnectionRes) {
509
			if(!$this->ldap->areLDAPFunctionsAvailable()) {
510
				$phpLDAPinstalled = false;
511
				\OCP\Util::writeLog('user_ldap',
512
									'function ldap_connect is not available. Make '.
513
									'sure that the PHP ldap module is installed.',
514
									\OCP\Util::ERROR);
515
516
				return false;
517
			}
518
			if($this->configuration->turnOffCertCheck) {
0 ignored issues
show
Documentation introduced by
The property turnOffCertCheck does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
519
				if(putenv('LDAPTLS_REQCERT=never')) {
520
					\OCP\Util::writeLog('user_ldap',
521
						'Turned off SSL certificate validation successfully.',
522
						\OCP\Util::DEBUG);
523
				} else {
524
					\OCP\Util::writeLog('user_ldap',
525
										'Could not turn off SSL certificate validation.',
526
										\OCP\Util::WARN);
527
				}
528
			}
529
530
			$bindStatus = false;
531
			$error = null;
532
			try {
533
				if (!$this->configuration->ldapOverrideMainServer
0 ignored issues
show
Documentation introduced by
The property ldapOverrideMainServer does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
534
					&& !$this->getFromCache('overrideMainServer')
535
				) {
536
					$this->doConnect($this->configuration->ldapHost,
0 ignored issues
show
Documentation introduced by
The property ldapHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
537
						$this->configuration->ldapPort);
0 ignored issues
show
Documentation introduced by
The property ldapPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
538
					$bindStatus = $this->bind();
539
					$error = $this->ldap->isResource($this->ldapConnectionRes) ?
0 ignored issues
show
Documentation introduced by
$this->ldapConnectionRes is of type null, but the function expects a resource.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
540
						$this->ldap->errno($this->ldapConnectionRes) : -1;
0 ignored issues
show
Documentation introduced by
$this->ldapConnectionRes is of type null, but the function expects a resource.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
541
				}
542
				if($bindStatus === true) {
543
					return $bindStatus;
544
				}
545
			} catch (\OC\ServerNotAvailableException $e) {
546
				if(trim($this->configuration->ldapBackupHost) === "") {
0 ignored issues
show
Documentation introduced by
The property ldapBackupHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
547
					throw $e;
548
				}
549
			}
550
551
			//if LDAP server is not reachable, try the Backup (Replica!) Server
552
			if(    $error !== 0
553
				|| $this->configuration->ldapOverrideMainServer
0 ignored issues
show
Documentation introduced by
The property ldapOverrideMainServer does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
554
				|| $this->getFromCache('overrideMainServer'))
555
			{
556
				$this->doConnect($this->configuration->ldapBackupHost,
0 ignored issues
show
Documentation introduced by
The property ldapBackupHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
557
								 $this->configuration->ldapBackupPort);
0 ignored issues
show
Documentation introduced by
The property ldapBackupPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
558
				$bindStatus = $this->bind();
559
				if($bindStatus && $error === -1) {
560
					//when bind to backup server succeeded and failed to main server,
561
					//skip contacting him until next cache refresh
562
					$this->writeToCache('overrideMainServer', true);
563
				}
564
			}
565
			return $bindStatus;
566
		}
567
	}
568
569
	/**
570
	 * @param string $host
571
	 * @param string $port
572
	 * @return false|void
573
	 */
574
	private function doConnect($host, $port) {
575
		if(empty($host)) {
576
			return false;
577
		}
578
		$this->ldapConnectionRes = $this->ldap->connect($host, $port);
579
		if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
580
			if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
581
				if($this->configuration->ldapTLS) {
0 ignored issues
show
Documentation introduced by
The property ldapTLS does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
582
					$this->ldap->startTls($this->ldapConnectionRes);
583
				}
584
			}
585
		}
586
	}
587
588
	/**
589
	 * Binds to LDAP
590
	 */
591
	public function bind() {
592
		static $getConnectionResourceAttempt = false;
593
		if(!$this->configuration->ldapConfigurationActive) {
0 ignored issues
show
Bug introduced by
The property ldapConfigurationActive does not seem to exist. Did you mean config?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
594
			return false;
595
		}
596
		if($getConnectionResourceAttempt) {
597
			$getConnectionResourceAttempt = false;
598
			return false;
599
		}
600
		$getConnectionResourceAttempt = true;
601
		$cr = $this->getConnectionResource();
602
		$getConnectionResourceAttempt = false;
603
		if(!$this->ldap->isResource($cr)) {
604
			return false;
605
		}
606
		$ldapLogin = @$this->ldap->bind($cr,
607
										$this->configuration->ldapAgentName,
0 ignored issues
show
Documentation introduced by
The property ldapAgentName does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
608
										$this->configuration->ldapAgentPassword);
0 ignored issues
show
Documentation introduced by
The property ldapAgentPassword does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
609
		if(!$ldapLogin) {
610
			\OCP\Util::writeLog('user_ldap',
611
				'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr),
612
				\OCP\Util::WARN);
613
			$this->ldapConnectionRes = null;
614
			return false;
615
		}
616
		return true;
617
	}
618
619
}
620