Passed
Pull Request — master (#13)
by Ashoka
03:28
created

PathParserTrait::parsePath()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 17
ccs 14
cts 14
cp 1
crap 2
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 6
    private function parsePath(string $path): array
20
    {
21 6
        return array_map(
22
            function (string $key) {
23 5
                return ctype_digit($key)
24 2
                    ? intval($key)
25 5
                    : $key;
26 6
            },
27 6
            array_values(
28 6
                array_filter(
29 6
                    str_getcsv(
30 6
                        $path,
31 6
                        DataContainerInterface::SEPARATOR,
32 6
                        DataContainerInterface::ENCLOSURE,
33 6
                        DataContainerInterface::ESCAPE
34
                    ),
35 6
                    'strlen'
36
                )
37
            )
38
        );
39
    }
40
}
41