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

PathParserTrait   A

Complexity

Total Complexity 2

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 2

1 Method

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