Conditions | 2 |
Paths | 1 |
Total Lines | 23 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | 6 | public static function allOnlineModels(bool $onlySingles = false): array |
|
17 | { |
||
18 | return chiefMemoize('all-online-models', function () use($onlySingles) { |
||
19 | |||
20 | 6 | $builder = UrlRecord::whereNull('redirect_id')->select('model_type', 'model_id')->groupBy('model_type', 'model_id'); |
|
21 | |||
22 | 6 | if($onlySingles) { |
|
23 | 5 | $builder->where('model_type', 'singles'); |
|
24 | } |
||
25 | |||
26 | $liveUrlRecords = $builder->get()->mapToGroups(function($record) { |
||
27 | 1 | return [$record->model_type => $record->model_id]; |
|
28 | 6 | }); |
|
29 | |||
30 | // Get model for each of these records... |
||
31 | $models = $liveUrlRecords->map(function($record, $key){ |
||
32 | 1 | return Morphables::instance($key)->find($record->toArray()); |
|
33 | })->each->reject(function ($model) { |
||
34 | // Invalid references to archived or removed models where url record still exists. |
||
35 | 1 | return is_null($model); |
|
36 | 6 | })->flatten(); |
|
37 | |||
38 | 6 | return FlatReferencePresenter::toGroupedSelectValues($models)->toArray(); |
|
39 | 6 | }); |
|
46 | } |