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

ReverseValues   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
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
 * Reverse order of an array elements. Based on {@see array_reverse}.
11
 *
12
 * Simple usage:
13
 *
14
 * ```php
15
 * $reverse = new ReverseValues('code');
16
 *
17
 * // ['b' => 2, 'a' => 1]
18
 * $result = $reverse->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 ReverseValues()
34
 * );
35
 *
36
 * // [
37
 * //     'options' => [],
38
 * //     'version' => '3.0',
39
 * //     'name' => 'Yii',
40
 * // ],
41
 * $result = ArrayHelper::merge($a, $b);
42
 * ```
43
 */
44
final class ReverseValues extends Modifier implements DataModifierInterface
45
{
46 2
    public function apply(array $data): array
47
    {
48 2
        return array_reverse($data);
49
    }
50
}
51