Code Duplication    Length = 10-10 lines in 6 locations

code/services/LDAPService.php 6 locations

@@ 224-233 (lines=10) @@
221
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
222
     * @return array
223
     */
224
    public function getGroupByGUID($guid, $attributes = array())
225
    {
226
        $searchLocations = $this->config()->groups_search_locations ?: array(null);
227
        foreach ($searchLocations as $searchLocation) {
228
            $records = $this->gateway->getGroupByGUID($guid, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
229
            if ($records) {
230
                return $records[0];
231
            }
232
        }
233
    }
234
235
    /**
236
     * Get a particular AD group's data given a DN.
@@ 242-251 (lines=10) @@
239
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
240
     * @return array
241
     */
242
    public function getGroupByDN($dn, $attributes = array())
243
    {
244
        $searchLocations = $this->config()->groups_search_locations ?: array(null);
245
        foreach ($searchLocations as $searchLocation) {
246
            $records = $this->gateway->getGroupByDN($dn, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
247
            if ($records) {
248
                return $records[0];
249
            }
250
        }
251
    }
252
253
    /**
254
     * Return all AD users in configured search locations, including all users in nested groups.
@@ 287-296 (lines=10) @@
284
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
285
     * @return array
286
     */
287
    public function getUserByGUID($guid, $attributes = array())
288
    {
289
        $searchLocations = $this->config()->users_search_locations ?: array(null);
290
        foreach ($searchLocations as $searchLocation) {
291
            $records = $this->gateway->getUserByGUID($guid, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
292
            if ($records) {
293
                return $records[0];
294
            }
295
        }
296
    }
297
298
    /**
299
     * Get a specific AD user's data given a DN.
@@ 306-315 (lines=10) @@
303
     *
304
     * @return array
305
     */
306
    public function getUserByDN($dn, $attributes = array())
307
    {
308
        $searchLocations = $this->config()->users_search_locations ?: array(null);
309
        foreach ($searchLocations as $searchLocation) {
310
            $records = $this->gateway->getUserByDN($dn, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
311
            if ($records) {
312
                return $records[0];
313
            }
314
        }
315
    }
316
317
    /**
318
     * Get a specific user's data given an email.
@@ 324-333 (lines=10) @@
321
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
322
     * @return array
323
     */
324
    public function getUserByEmail($email, $attributes = array())
325
    {
326
        $searchLocations = $this->config()->users_search_locations ?: array(null);
327
        foreach ($searchLocations as $searchLocation) {
328
            $records = $this->gateway->getUserByEmail($email, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
329
            if ($records) {
330
                return $records[0];
331
            }
332
        }
333
    }
334
335
    /**
336
     * Get a specific user's data given a username.
@@ 342-351 (lines=10) @@
339
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
340
     * @return array
341
     */
342
    public function getUserByUsername($username, $attributes = array())
343
    {
344
        $searchLocations = $this->config()->users_search_locations ?: array(null);
345
        foreach ($searchLocations as $searchLocation) {
346
            $records = $this->gateway->getUserByUsername($username, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
347
            if ($records) {
348
                return $records[0];
349
            }
350
        }
351
    }
352
353
    /**
354
     * Get a username for an email.