Code Duplication    Length = 10-10 lines in 6 locations

code/services/LDAPService.php 6 locations

@@ 261-270 (lines=10) @@
258
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
259
     * @return array
260
     */
261
    public function getGroupByGUID($guid, $attributes = [])
262
    {
263
        $searchLocations = $this->config()->groups_search_locations ?: [null];
264
        foreach ($searchLocations as $searchLocation) {
265
            $records = $this->gateway->getGroupByGUID($guid, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
266
            if ($records) {
267
                return $records[0];
268
            }
269
        }
270
    }
271
272
    /**
273
     * Get a particular AD group's data given a DN.
@@ 279-288 (lines=10) @@
276
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
277
     * @return array
278
     */
279
    public function getGroupByDN($dn, $attributes = [])
280
    {
281
        $searchLocations = $this->config()->groups_search_locations ?: [null];
282
        foreach ($searchLocations as $searchLocation) {
283
            $records = $this->gateway->getGroupByDN($dn, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
284
            if ($records) {
285
                return $records[0];
286
            }
287
        }
288
    }
289
290
    /**
291
     * Return all AD users in configured search locations, including all users in nested groups.
@@ 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 getUserByGUID($guid, $attributes = [])
325
    {
326
        $searchLocations = $this->config()->users_search_locations ?: [null];
327
        foreach ($searchLocations as $searchLocation) {
328
            $records = $this->gateway->getUserByGUID($guid, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
329
            if ($records) {
330
                return $records[0];
331
            }
332
        }
333
    }
334
335
    /**
336
     * Get a specific AD user's data given a DN.
@@ 343-352 (lines=10) @@
340
     *
341
     * @return array
342
     */
343
    public function getUserByDN($dn, $attributes = [])
344
    {
345
        $searchLocations = $this->config()->users_search_locations ?: [null];
346
        foreach ($searchLocations as $searchLocation) {
347
            $records = $this->gateway->getUserByDN($dn, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
348
            if ($records) {
349
                return $records[0];
350
            }
351
        }
352
    }
353
354
    /**
355
     * Get a specific user's data given an email.
@@ 361-370 (lines=10) @@
358
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
359
     * @return array
360
     */
361
    public function getUserByEmail($email, $attributes = [])
362
    {
363
        $searchLocations = $this->config()->users_search_locations ?: [null];
364
        foreach ($searchLocations as $searchLocation) {
365
            $records = $this->gateway->getUserByEmail($email, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
366
            if ($records) {
367
                return $records[0];
368
            }
369
        }
370
    }
371
372
    /**
373
     * Get a specific user's data given a username.
@@ 379-388 (lines=10) @@
376
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
377
     * @return array
378
     */
379
    public function getUserByUsername($username, $attributes = [])
380
    {
381
        $searchLocations = $this->config()->users_search_locations ?: [null];
382
        foreach ($searchLocations as $searchLocation) {
383
            $records = $this->gateway->getUserByUsername($username, $searchLocation, Zend\Ldap\Ldap::SEARCH_SCOPE_SUB, $attributes);
384
            if ($records) {
385
                return $records[0];
386
            }
387
        }
388
    }
389
390
    /**
391
     * Get a username for an email.