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

ReverseValues::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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