Passed
Pull Request — master (#301)
by Fabien
02:07
created

FileHelper::toAbsolutePath()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 17
rs 9.2222
c 1
b 0
f 0
cc 6
nc 4
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\File;
6
7
class FileHelper
8
{
9
10
    /**
11
     * @param string $path The path of an item to scan.
12
     * @param string $configurationPath The path of the configuration file.
13
     * @return string The absolute path of the given item.
14
     */
15
    public static function toAbsolutePath(string $path, string $configurationPath): string
16
    {
17
        $path = \trim($path);
18
19
        if (0 === \strpos($path, '/')) {
20
            return $path;
21
        }
22
23
        if ('\\' === $path[0] || (\strlen($path) >= 3 && \preg_match('#^[A-Z]\:[/\\\]#i', \substr($path, 0, 3)))) {
24
            return $path;
25
        }
26
27
        if (false !== \strpos($path, '://')) {
28
            return $path;
29
        }
30
31
        return \dirname($configurationPath) . '/' . $path;
32
    }
33
}
34