PathDefaultFileLocator::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 2
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * For licensing information, please see the LICENSE file accompanied with this file.
4
 *
5
 * @author Gerard van Helden <[email protected]>
6
 * @copyright 2012 Gerard van Helden <http://melp.nl>
7
 */
8
namespace Zicht\Tool\Configuration;
9
10
use Symfony\Component\Config\FileLocator;
11
12
/**
13
 * A FileLocator implementation that uses an environment PATH variable, and defaults to other paths if that
14
 * environment variable does not exist
15
 */
16
class PathDefaultFileLocator extends FileLocator
17
{
18
    /**
19
     * Expand all path elements with globbing.
20
     *
21
     * @param string $paths
22
     * @return array
23
     */
24 2
    private static function expand($paths)
25
    {
26 2
        return array_filter(array_reduce(array_map('glob', $paths), 'array_merge', []));
27
    }
28
29
30
    /**
31
     * Construct the locator based on the passed environment variable.
32
     *
33
     * @param string $envName
34
     * @param array $defaultPaths
35
     */
36 2
    public function __construct($envName, $defaultPaths = array())
37
    {
38 2
        parent::__construct(self::expand(getenv($envName) ? explode(PATH_SEPARATOR, getenv($envName)) : $defaultPaths));
0 ignored issues
show
Documentation introduced by
getenv($envName) ? explo...vName)) : $defaultPaths is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39 2
    }
40
}
41