Paths::fromString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AmaTeam\TreeAccess;
4
5
/**
6
 * TODO: support for complex paths that may include dots in segments
7
 */
8
class Paths
9
{
10
    const DELIMITER = '.';
11
12
    /**
13
     * @param string[] $path
14
     * @return string
15
     */
16 6
    public static function toString(array $path)
17
    {
18 6
        return implode(self::DELIMITER, $path);
19
    }
20
21
    /**
22
     * @param string $input
23
     * @return string[]
24
     */
25 17
    public static function fromString($input)
26
    {
27 17
        return array_filter(explode(self::DELIMITER, $input));
28
    }
29
30
    /**
31
     * @param string|string[] $path
32
     * @return string[]
33
     */
34 23
    public static function normalize($path)
35
    {
36 23
        return is_array($path) ? $path : self::fromString($path);
37
    }
38
}
39