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

FileHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 9
dl 0
loc 25
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A toAbsolutePath() 0 17 6
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