NestedArraySorter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 8
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A valueFor() 0 6 2
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