ConfigLocator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 32
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B locate() 0 21 7
1
<?php
2
3
namespace OckCyp\CoversValidator\Locator;
4
5
class ConfigLocator
6
{
7
    public const CONFIG_FILENAME = 'phpunit.xml';
8
9
    /**
10
     * Locates config file to use in the way PHPUnit does it
11
     *
12
     * @param string $configOption
13
     *
14
     * @return string|null
15
     */
16
    public static function locate($configOption)
17
    {
18
        if (is_null($configOption)) {
0 ignored issues
show
introduced by
The condition is_null($configOption) is always false.
Loading history...
19
            $configOption = '';
20
        }
21
22
        $configurationFile = static::CONFIG_FILENAME;
23
        if (is_dir($configOption)) {
24
            $configurationFile = $configOption.DIRECTORY_SEPARATOR.$configurationFile;
25
        }
26
        if (file_exists($configOption) && is_file($configOption)) {
27
            return realpath($configOption);
28
        }
29
        if (file_exists($configurationFile)) {
30
            return realpath($configurationFile);
31
        }
32
        if (file_exists($configurationFile.'.dist')) {
33
            return realpath($configurationFile.'.dist');
34
        }
35
36
        return null;
37
    }
38
}
39