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

ConfigLocator::locate()   B

Complexity

Conditions 7
Paths 16

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nc 16
nop 1
dl 0
loc 21
rs 8.8333
c 0
b 0
f 0
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