Paths   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 3 2
A fromString() 0 3 1
A toString() 0 3 1
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