Passed
Pull Request — master (#62)
by Alexander
07:46
created

RemoveAllKeys   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
ccs 2
cts 2
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Arrays\Collection\Modifier;
6
7
use Yiisoft\Arrays\Collection\Modifier\ModifierInterface\DataModifierInterface;
8
9
/**
10
 * Re-indexes an array numerically, i. e. removes all information about array keys. Based on {@see array_values}.
11
 *
12
 * Simple usage:
13
 *
14
 * ```php
15
 * $removeKeys = new RemoveAllKeys();
16
 *
17
 * // [1, 2]
18
 * $result = $removeKeys->apply(['a' => 1, 'b' => 2]);
19
 * ```
20
 *
21
 * Usage with merge:
22
 *
23
 * ```php
24
 * $a = [
25
 *     'name' => 'Yii',
26
 *     'version' => '1.0',
27
 * ];
28
 * $b = new ArrayCollection(
29
 *     [
30
 *         'version' => '3.0',
31
 *         'options' => [],
32
 *     ],
33
 *     new RemoveAllKeys()
34
 * );
35
 *
36
 * // [
37
 * //     'Yii',
38
 * //     '3.0',
39
 * //     [],
40
 * // ],
41
 * $result = ArrayHelper::merge($a, $b);
42
 * ```
43
 */
44
final class RemoveAllKeys extends Modifier implements DataModifierInterface
45
{
46
    protected int $priority = Modifier::PRIORITY_LOW;
47
48 4
    public function apply(array $data): array
49
    {
50 4
        return array_values($data);
51
    }
52
}
53