Code Duplication    Length = 10-10 lines in 6 locations

code/services/LDAPService.php 6 locations

@@ 232-241 (lines=10) @@
229
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
230
     * @return array
231
     */
232
    public function getGroupByGUID($guid, $attributes = array())
233
    {
234
        $searchLocations = $this->config()->groups_search_locations ?: array(null);
235
        foreach ($searchLocations as $searchLocation) {
236
            $records = $this->gateway->getGroupByGUID($guid, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
237
            if ($records) {
238
                return $records[0];
239
            }
240
        }
241
    }
242
243
    /**
244
     * Get a particular AD group's data given a DN.
@@ 250-259 (lines=10) @@
247
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
248
     * @return array
249
     */
250
    public function getGroupByDN($dn, $attributes = array())
251
    {
252
        $searchLocations = $this->config()->groups_search_locations ?: array(null);
253
        foreach ($searchLocations as $searchLocation) {
254
            $records = $this->gateway->getGroupByDN($dn, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
255
            if ($records) {
256
                return $records[0];
257
            }
258
        }
259
    }
260
261
    /**
262
     * Return all AD users in configured search locations, including all users in nested groups.
@@ 295-304 (lines=10) @@
292
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
293
     * @return array
294
     */
295
    public function getUserByGUID($guid, $attributes = array())
296
    {
297
        $searchLocations = $this->config()->users_search_locations ?: array(null);
298
        foreach ($searchLocations as $searchLocation) {
299
            $records = $this->gateway->getUserByGUID($guid, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
300
            if ($records) {
301
                return $records[0];
302
            }
303
        }
304
    }
305
306
    /**
307
     * Get a specific AD user's data given a DN.
@@ 314-323 (lines=10) @@
311
     *
312
     * @return array
313
     */
314
    public function getUserByDN($dn, $attributes = array())
315
    {
316
        $searchLocations = $this->config()->users_search_locations ?: array(null);
317
        foreach ($searchLocations as $searchLocation) {
318
            $records = $this->gateway->getUserByDN($dn, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
319
            if ($records) {
320
                return $records[0];
321
            }
322
        }
323
    }
324
325
    /**
326
     * Get a specific user's data given an email.
@@ 332-341 (lines=10) @@
329
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
330
     * @return array
331
     */
332
    public function getUserByEmail($email, $attributes = array())
333
    {
334
        $searchLocations = $this->config()->users_search_locations ?: array(null);
335
        foreach ($searchLocations as $searchLocation) {
336
            $records = $this->gateway->getUserByEmail($email, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
337
            if ($records) {
338
                return $records[0];
339
            }
340
        }
341
    }
342
343
    /**
344
     * Get a specific user's data given a username.
@@ 350-359 (lines=10) @@
347
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
348
     * @return array
349
     */
350
    public function getUserByUsername($username, $attributes = array())
351
    {
352
        $searchLocations = $this->config()->users_search_locations ?: array(null);
353
        foreach ($searchLocations as $searchLocation) {
354
            $records = $this->gateway->getUserByUsername($username, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
355
            if ($records) {
356
                return $records[0];
357
            }
358
        }
359
    }
360
361
    /**
362
     * Get a username for an email.