getDropdownDataSet()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 3
eloc 7
c 2
b 1
f 0
nc 3
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
function getUniqueDropdownName($parent_id = null, $entagle = null)
4
{
5
    $randomNums = Str::random(15);
6
    $uniqueID = 'searchableDropdownData_'.$randomNums;
7
    if($parent_id){
8
        $sess_id = "{$parent_id}_{$entagle}";
9
        // TODO : somehow cleanup session at some point ????
10
        if(session()->has($sess_id)){
11
            $uniqueID = session()->get($sess_id);
12
        } else { 
13
            session()->put($sess_id, $uniqueID);       
14
        }
15
    }
16
    return $uniqueID;
17
}
18
19
function searchableDropdownProps() {
20
    return config('searchable-dropdown-props');
21
}
22
function getTheme() {
23
    return [
24
        'default-text-color' => config('searchable-dropdown-config.styles.theme.default-text-color'),
25
        'default-primary-color' => config('searchable-dropdown-config.styles.theme.default-primary-color'),
26
        'default-secondary-color' => config('searchalbe-dropdown-config.styles.theme.default-secondary-color')
27
    ];
28
}
29
30
function getDropdownDataSet($data)
31
{
32
    if (!$data ) {
33
        return collect()->toJson();
34
    }
35
    $data=collect($data);
36
    if (is_scalar($data->first())) {
37
        $data=collect($data)->map(fn($value,$key)=>['key'=>$key, 'value'=>$value]);
38
    } 
39
    $data = json_encode($data->values()->toArray());
40
    return $data;
41
}
42