Failed Conditions
Pull Request — master (#1)
by Yo
01:55
created

PathHelper::appendPathSeparator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 6
1
<?php
2
namespace Yoanm\DefaultPhpRepository\Helper;
3
4
/**
5
 * Class PathHelper
6
 */
7
class PathHelper
8
{
9
    /**
10
     * @param string[] $componentList
11
     *
12
     * @return string
13
     */
14
    public static function implodePathComponentList(array $componentList)
15
    {
16
        $path = '';
17
        foreach ($componentList as $component) {
18
            $path .= self::appendPathSeparator($component);
19
        }
20
21
        return $path;
22
    }
23
24
    /**
25
     * @param string $component
26
     *
27
     * @return string
28
     */
29
    public static function appendPathSeparator($component)
30
    {
31
        if (strrpos($component, self::separator()) === (strlen($component) - 1)) {
32
            return $component;
33
        }
34
35
        return sprintf(
36
            '%s%s',
37
            $component,
38
            self::separator()
39
        );
40
    }
41
42
    public static function separator()
43
    {
44
        return DIRECTORY_SEPARATOR;
45
    }
46
}
47