Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
6 / 8
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
NormalizesInput
75.00% covered (warning)
75.00%
6 / 8
33.33% covered (danger)
33.33%
1 / 3
7.77
0.00% covered (danger)
0.00%
0 / 1
 label
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 items
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 arrayFrom
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Panel;
6
7use Traversable;
8
9trait NormalizesInput
10{
11    private static function label(?string $label): ?string
12    {
13        $label = trim((string) $label);
14
15        return $label === '' ? null : $label;
16    }
17
18    /** @return list<mixed> */
19    private static function items(iterable $items): array
20    {
21        if ($items instanceof Traversable) {
22            return array_values(iterator_to_array($items, false));
23        }
24
25        return array_values($items);
26    }
27
28    /** @return array<array-key, mixed> */
29    private static function arrayFrom(mixed $value): array
30    {
31        if ($value instanceof Traversable) {
32            return iterator_to_array($value);
33        }
34
35        return is_array($value) ? $value : [];
36    }
37}