Code Duplication    Length = 10-10 lines in 6 locations

src/Services/LDAPService.php 6 locations

@@ 292-301 (lines=10) @@
289
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
290
     * @return array
291
     */
292
    public function getGroupByGUID($guid, $attributes = [])
293
    {
294
        $searchLocations = $this->config()->groups_search_locations ?: [null];
295
        foreach ($searchLocations as $searchLocation) {
296
            $records = $this->gateway->getGroupByGUID($guid, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
297
            if ($records) {
298
                return $records[0];
299
            }
300
        }
301
    }
302
303
    /**
304
     * Get a particular AD group's data given a DN.
@@ 310-319 (lines=10) @@
307
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
308
     * @return array
309
     */
310
    public function getGroupByDN($dn, $attributes = [])
311
    {
312
        $searchLocations = $this->config()->groups_search_locations ?: [null];
313
        foreach ($searchLocations as $searchLocation) {
314
            $records = $this->gateway->getGroupByDN($dn, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
315
            if ($records) {
316
                return $records[0];
317
            }
318
        }
319
    }
320
321
    /**
322
     * Return all AD users in configured search locations, including all users in nested groups.
@@ 355-364 (lines=10) @@
352
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
353
     * @return array
354
     */
355
    public function getUserByGUID($guid, $attributes = [])
356
    {
357
        $searchLocations = $this->config()->users_search_locations ?: [null];
358
        foreach ($searchLocations as $searchLocation) {
359
            $records = $this->gateway->getUserByGUID($guid, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
360
            if ($records) {
361
                return $records[0];
362
            }
363
        }
364
    }
365
366
    /**
367
     * Get a specific AD user's data given a DN.
@@ 374-383 (lines=10) @@
371
     *
372
     * @return array
373
     */
374
    public function getUserByDN($dn, $attributes = [])
375
    {
376
        $searchLocations = $this->config()->users_search_locations ?: [null];
377
        foreach ($searchLocations as $searchLocation) {
378
            $records = $this->gateway->getUserByDN($dn, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
379
            if ($records) {
380
                return $records[0];
381
            }
382
        }
383
    }
384
385
    /**
386
     * Get a specific user's data given an email.
@@ 392-401 (lines=10) @@
389
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
390
     * @return array
391
     */
392
    public function getUserByEmail($email, $attributes = [])
393
    {
394
        $searchLocations = $this->config()->users_search_locations ?: [null];
395
        foreach ($searchLocations as $searchLocation) {
396
            $records = $this->gateway->getUserByEmail($email, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
397
            if ($records) {
398
                return $records[0];
399
            }
400
        }
401
    }
402
403
    /**
404
     * Get a specific user's data given a username.
@@ 410-419 (lines=10) @@
407
     * @param array $attributes List of specific AD attributes to return. Empty array means return everything.
408
     * @return array
409
     */
410
    public function getUserByUsername($username, $attributes = [])
411
    {
412
        $searchLocations = $this->config()->users_search_locations ?: [null];
413
        foreach ($searchLocations as $searchLocation) {
414
            $records = $this->gateway->getUserByUsername($username, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
415
            if ($records) {
416
                return $records[0];
417
            }
418
        }
419
    }
420
421
    /**
422
     * Get a username for an email.