Passed
Push — master ( d6f30d...0b1185 )
by Jesse
04:37
created

NestedArraySorter::valueFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Sorting;
5
6
use function explode;
7
8
/**
9
 * Sorts a collection of multi-dimensional arrays.
10
 *
11
 * Objects that implement ArrayAccess are considered arrays for this purpose.
12
 *
13
 * @author  Stratadox
14
 * @package Stratadox\Sorting
15
 */
16
class NestedArraySorter extends Sorter
17
{
18
    protected function valueFor($element, string $field)
19
    {
20
        foreach (explode('.', $field) as $offset) {
21
            $element = $element[$offset];
22
        }
23
        return $element;
24
    }
25
}
26