Passed
Branch master (baa65a)
by Oliver
09:35
created

ConfigLocator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 31
rs 10
c 0
b 0
f 0
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
    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
     * @return string|null
14
     */
15
    public static function locate($configOption)
16
    {
17
        if (is_null($configOption)) {
0 ignored issues
show
introduced by
The condition is_null($configOption) is always false.
Loading history...
18
            $configOption = '';
19
        }
20
21
        $configurationFile = static::CONFIG_FILENAME;
22
        if (is_dir($configOption)) {
23
            $configurationFile = $configOption . DIRECTORY_SEPARATOR . $configurationFile;
24
        }
25
        if (file_exists($configOption) && is_file($configOption)) {
26
            return realpath($configOption);
27
        }
28
        if (file_exists($configurationFile)) {
29
            return realpath($configurationFile);
30
        }
31
        if (file_exists($configurationFile . '.dist')) {
32
            return realpath($configurationFile . '.dist');
33
        }
34
35
        return null;
36
    }
37
}
38