Code Duplication    Length = 10-10 lines in 6 locations

src/Services/LDAPService.php 6 locations

@@ 314-323 (lines=10) @@
311
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
312
     * @return array
313
     */
314
    public function getGroupByGUID($guid, $attributes = [])
315
    {
316
        $searchLocations = $this->config()->groups_search_locations ?: [null];
317
        foreach ($searchLocations as $searchLocation) {
318
            $records = $this->gateway->getGroupByGUID($guid, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
319
            if ($records) {
320
                return $records[0];
321
            }
322
        }
323
    }
324
325
    /**
326
     * Get a particular AD group's data given a DN.
@@ 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 getGroupByDN($dn, $attributes = [])
333
    {
334
        $searchLocations = $this->config()->groups_search_locations ?: [null];
335
        foreach ($searchLocations as $searchLocation) {
336
            $records = $this->gateway->getGroupByDN($dn, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
337
            if ($records) {
338
                return $records[0];
339
            }
340
        }
341
    }
342
343
    /**
344
     * Return all AD users in configured search locations, including all users in nested groups.
@@ 377-386 (lines=10) @@
374
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
375
     * @return array
376
     */
377
    public function getUserByGUID($guid, $attributes = [])
378
    {
379
        $searchLocations = $this->config()->users_search_locations ?: [null];
380
        foreach ($searchLocations as $searchLocation) {
381
            $records = $this->gateway->getUserByGUID($guid, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
382
            if ($records) {
383
                return $records[0];
384
            }
385
        }
386
    }
387
388
    /**
389
     * Get a specific AD user's data given a DN.
@@ 396-405 (lines=10) @@
393
     *
394
     * @return array
395
     */
396
    public function getUserByDN($dn, $attributes = [])
397
    {
398
        $searchLocations = $this->config()->users_search_locations ?: [null];
399
        foreach ($searchLocations as $searchLocation) {
400
            $records = $this->gateway->getUserByDN($dn, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
401
            if ($records) {
402
                return $records[0];
403
            }
404
        }
405
    }
406
407
    /**
408
     * Get a specific user's data given an email.
@@ 414-423 (lines=10) @@
411
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
412
     * @return array
413
     */
414
    public function getUserByEmail($email, $attributes = [])
415
    {
416
        $searchLocations = $this->config()->users_search_locations ?: [null];
417
        foreach ($searchLocations as $searchLocation) {
418
            $records = $this->gateway->getUserByEmail($email, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
419
            if ($records) {
420
                return $records[0];
421
            }
422
        }
423
    }
424
425
    /**
426
     * Get a specific user's data given a username.
@@ 432-441 (lines=10) @@
429
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
430
     * @return array
431
     */
432
    public function getUserByUsername($username, $attributes = [])
433
    {
434
        $searchLocations = $this->config()->users_search_locations ?: [null];
435
        foreach ($searchLocations as $searchLocation) {
436
            $records = $this->gateway->getUserByUsername($username, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
437
            if ($records) {
438
                return $records[0];
439
            }
440
        }
441
    }
442
443
    /**
444
     * Get a username for an email.