| Total Complexity | 4 | 
| Total Lines | 36 | 
| Duplicated Lines | 0 % | 
| Changes | 2 | ||
| Bugs | 1 | Features | 0 | 
| 1 | <?php  | 
            ||
| 8 | class UrlHelper  | 
            ||
| 9 | { | 
            ||
| 10 | /**  | 
            ||
| 11 | * Internal api for fetching all models that have an active url  | 
            ||
| 12 | *  | 
            ||
| 13 | * @param bool $onlySingles  | 
            ||
| 14 | * @return array  | 
            ||
| 15 | */  | 
            ||
| 16 | public static function allOnlineModels(bool $onlySingles = false): array  | 
            ||
| 17 |     { | 
            ||
| 18 |         return chiefMemoize('all-online-models', function () use ($onlySingles) { | 
            ||
| 19 |             $builder = UrlRecord::whereNull('redirect_id')->select('model_type', 'model_id')->groupBy('model_type', 'model_id'); | 
            ||
| 20 | |||
| 21 |             if ($onlySingles) { | 
            ||
| 22 |                 $builder->where('model_type', 'singles'); | 
            ||
| 23 | }  | 
            ||
| 24 | |||
| 25 |             $liveUrlRecords = $builder->get()->mapToGroups(function ($record) { | 
            ||
| 26 | return [$record->model_type => $record->model_id];  | 
            ||
| 27 | });  | 
            ||
| 28 | |||
| 29 | // Get model for each of these records...  | 
            ||
| 30 |             $models = $liveUrlRecords->map(function ($record, $key) { | 
            ||
| 31 | return Morphables::instance($key)->find($record->toArray());  | 
            ||
| 32 |             })->map->reject(function ($model) { | 
            ||
| 33 | // Invalid references to archived or removed models where url record still exists.  | 
            ||
| 34 | return is_null($model) || !$model->isPublished();  | 
            ||
| 35 | })->flatten();  | 
            ||
| 36 | |||
| 37 | return FlatReferencePresenter::toGroupedSelectValues($models)->toArray();  | 
            ||
| 38 | });  | 
            ||
| 39 | }  | 
            ||
| 40 | |||
| 41 | public static function allOnlineSingles()  | 
            ||
| 44 | }  | 
            ||
| 45 | }  | 
            ||
| 46 |