Arr::getToggledValues()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 1
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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