Code Duplication    Length = 6-10 lines in 3 locations

src/Services/LDAPService.php 3 locations

@@ 259-268 (lines=10) @@
256
257
        if (!$results || !$cached) {
258
            $results = [];
259
            foreach ($searchLocations as $searchLocation) {
260
                $records = $this->gateway->getGroups($searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
261
                if (!$records) {
262
                    continue;
263
                }
264
265
                foreach ($records as $record) {
266
                    $results[$record[$indexBy]] = $record;
267
                }
268
            }
269
270
            $cache->set($cacheKey, $results);
271
        }
@@ 296-301 (lines=6) @@
293
294
        $searchLocations = $this->config()->groups_search_locations ?: [null];
295
        $results = [];
296
        foreach ($searchLocations as $searchLocation) {
297
            $records = $this->gateway->getNestedGroups($dn, $searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
298
            foreach ($records as $record) {
299
                $results[$record['dn']] = $record;
300
            }
301
        }
302
303
        self::$_cache_nested_groups[$dn] = $results;
304
        return $results;
@@ 356-365 (lines=10) @@
353
        $searchLocations = $this->config()->users_search_locations ?: [null];
354
        $results = [];
355
356
        foreach ($searchLocations as $searchLocation) {
357
            $records = $this->gateway->getUsers($searchLocation, Ldap::SEARCH_SCOPE_SUB, $attributes);
358
            if (!$records) {
359
                continue;
360
            }
361
362
            foreach ($records as $record) {
363
                $results[$record['objectguid']] = $record;
364
            }
365
        }
366
367
        return $results;
368
    }