get_path_to()   A
last analyzed

Complexity

Conditions 6
Paths 14

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 10
c 1
b 0
f 0
nc 14
nop 0
dl 0
loc 19
rs 9.2222
1
<?php
2
3
/**
4
 * @return string
5
 */
6
function get_path_to()
7
{
8
    $segments = func_get_args();
9
10
    $finalIndex = count( $segments ) - 1;
11
    $finalIndex = $finalIndex < 0 ? 0 : $finalIndex;
12
    $finalSegment = '';
13
14
    $disabledChars = [ '/', '\\', NULL ];
15
    foreach( $segments as $count => $segment )
16
    {
17
        if ( !in_array( $segment, $disabledChars ) ) $finalSegment .= $count > 0 ? trim( $segment, '/' ) : rtrim( $segment, '/' );
18
19
        if ( $count != $finalIndex ) $finalSegment .= '/';
20
    }
21
22
    $finalSegment = '/'.ltrim( $finalSegment, '/' );
23
24
    return $finalSegment;
25
}