PathParserTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A parsePath() 0 17 4
1
<?php
2
3
/**
4
 * Copyright MediaCT. All rights reserved.
5
 * https://www.mediact.nl
6
 */
7
8
namespace Mediact\DataContainer;
9
10
trait PathParserTrait
11
{
12
    /**
13
     * Parse a path.
14
     *
15
     * @param string $path
16
     *
17
     * @return array
18
     */
19 13
    private function parsePath(string $path): array
20
    {
21 13
        return array_map(
22
            function (string $key) {
23 12
                return ctype_digit($key) && (strlen($key) === 1 || substr($key, 0, 1) !== "0")
24 6
                    ? intval($key)
25 12
                    : $key;
26 13
            },
27 13
            array_values(
28 13
                array_filter(
29 13
                    str_getcsv(
30 13
                        $path,
31 13
                        DataContainerInterface::SEPARATOR,
32 13
                        DataContainerInterface::ENCLOSURE,
33 13
                        DataContainerInterface::ESCAPE
34
                    ),
35 13
                    'strlen'
36
                )
37
            )
38
        );
39
    }
40
}
41