Util::joinPaths()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 10
1
<?php
2
3
namespace SilverStripe\VendorPlugin;
4
5
class Util
6
{
7
    /**
8
     * Join paths
9
     *
10
     * @param array ...$parts
11
     * @return string
12
     */
13
    public static function joinPaths(...$parts)
14
    {
15
        $combined = null;
16
        $parts = array_filter($parts);
17
        array_walk_recursive($parts, function ($part) use (&$combined) {
18
            // Normalise path
19
            $part = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $part);
20
            $combined = $combined
21
                ? (rtrim($combined, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $part)
22
                : $part;
23
        });
24
        return $combined;
25
    }
26
}
27