FileLocatorChain::locate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 3
crap 3
1
<?php
2
3
/*
4
 * This file is part of the puli/symfony-bridge package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\SymfonyBridge\Config;
13
14
use InvalidArgumentException;
15
use Symfony\Component\Config\FileLocatorInterface;
16
17
/**
18
 * @since  1.0
19
 *
20
 * @author Bernhard Schussek <[email protected]>
21
 */
22
class FileLocatorChain implements FileLocatorInterface
23
{
24
    /**
25
     * @var ChainableFileLocator[]
26
     */
27
    private $locators = array();
28
29 3
    public function __construct(array $locators = array())
30
    {
31 3
        foreach ($locators as $locator) {
32 3
            $this->addLocator($locator);
33
        }
34 3
    }
35
36 3
    public function addLocator(ChainableFileLocator $locator)
37
    {
38 3
        $this->locators[] = $locator;
39 3
    }
40
41
    /**
42
     * Returns a full path for a given file name.
43
     *
44
     * @param mixed  $name        The file name to locate
45
     * @param string $currentPath The current path
0 ignored issues
show
Documentation introduced by
Should the type for parameter $currentPath not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
46
     * @param bool   $first       Whether to return the first occurrence or an array of filenames
47
     *
48
     * @return string|array The full path to the file|An array of file paths
49
     *
50
     * @throws InvalidArgumentException When file is not found
51
     */
52 3
    public function locate($name, $currentPath = null, $first = true)
53
    {
54 3
        foreach ($this->locators as $locator) {
55 3
            if ($locator->supports($name)) {
56 3
                return $locator->locate($name, $currentPath, $first);
57
            }
58
        }
59
60 1
        throw new InvalidArgumentException(sprintf(
61 1
            'The file "%s" could not be found.',
62
            $name
63
        ));
64
    }
65
}
66