NestedArraySorter::valueFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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