Passed
Pull Request — master (#24)
by Damian
01:51
created

PathResolver::resolve()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Firesphere\GraphQLJWT\Helpers;
4
5
class PathResolver
6
{
7
    /**
8
     * Return an absolute path from a relative one
9
     * If the path doesn't exist, returns null
10
     *
11
     * @param string $path
12
     * @param string $base
13
     * @return string|null
14
     */
15
    public static function resolve(string $path, string $base = BASE_PATH): ?string
16
    {
17
        if (strstr($path, '/') !== 0) {
18
            $path = $base . '/' . $path;
19
        }
20
        return realpath($path) ?: null;
21
    }
22
}
23