Code Duplication    Length = 10-10 lines in 6 locations

src/Services/LDAPService.php 6 locations

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