Arr   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getToggledValues() 0 10 3
1
<?php
2
3
namespace Spatie\Html\Helpers;
4
5
use Illuminate\Support\Collection;
6
7
class Arr
8
{
9
    /**
10
     * Return an array of enabled values. Enabled values are either:
11
     *     - Keys that have a truthy value;
12
     *     - Values that don't have keys.
13
     *
14
     * Example:
15
     *
16
     *     Arr::getToggledValues(['foo' => true, 'bar' => false, 'baz'])
17
     *     // => ['foo', 'baz']
18
     *
19
     * @param mixed $map
20
     *
21
     * @return array
22
     */
23
    public static function getToggledValues($map)
24
    {
25
        return Collection::make($map)->map(function ($condition, $value) {
26
            if (is_numeric($value)) {
27
                return $condition;
28
            }
29
30
            return $condition ? $value : null;
31
        })->filter()->toArray();
32
    }
33
}
34