PathParserTrait::parsePath()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 17
ccs 14
cts 14
cp 1
crap 4
rs 9.8333
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