Code Duplication    Length = 10-15 lines in 6 locations

src/Services/LDAPService.php 6 locations

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