Code Duplication    Length = 13-17 lines in 2 locations

src/Http/Controllers/GoogleAppsUsersController.php 1 location

@@ 147-163 (lines=17) @@
144
        $directory = Google::make('directory');
145
        $count = 0;
146
        $pageToken = null;
147
        do {
148
            try {
149
                $r = $directory->users->listUsers([
150
                    'domain' => 'iesebre.com',
151
                    'maxResults' => 500,
152
                    'pageToken' => $pageToken
153
                ]);
154
                $pageToken = $r->nextPageToken;
155
//                dump($pageToken);
156
//                dump($r);
157
//                dump($r->users);
158
                $count = $count + count($r->users);
159
                dump('count: ' . $count);
160
            } catch (\Exception $e) {
161
                dd($e);
162
            }
163
        } while ($pageToken);
164
165
        dd($count);
166
    }

src/Services/GoogleApps/GoogleAppsService.php 1 location

@@ 65-77 (lines=13) @@
62
        $directory = Google::make('directory');
63
        $pageToken = null;
64
        $users = [];
65
        do {
66
            try {
67
                $r = $directory->users->listUsers([
68
                    'domain' => config('users.google_apps_domain'),
69
                    'maxResults' => config('users.google_apps_users_maxResults'),
70
                    'pageToken' => $pageToken
71
                ]);
72
                $pageToken = $r->nextPageToken;
73
                $users = array_merge($users, $r->users);
74
            } catch (\Exception $e) {
75
                return json_decode($e->getMessage());
76
            }
77
        } while ($pageToken);
78
        return $users;
79
    }
80