PhpFileLoader::includeFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the awurth/config package.
5
 *
6
 * (c) Alexis Wurth <[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 AWurth\Config\Loader;
13
14
use Symfony\Component\Config\Loader\Loader;
15
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
16
17
/**
18
 * PHP File Loader.
19
 *
20
 * @author Alexis Wurth <[email protected]>
21
 */
22
class PhpFileLoader extends Loader
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function load($file, $type = null)
28
    {
29
        if (!file_exists($file)) {
30
            throw new FileNotFoundException(sprintf('File "%s" not found.', $file));
31
        }
32
33
        return self::includeFile($file);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function supports($resource, $type = null)
40
    {
41
        return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'php' === $type);
42
    }
43
44
    /**
45
     * Includes a PHP file.
46
     *
47
     * @param string $file
48
     *
49
     * @return mixed
50
     */
51
    private static function includeFile($file)
52
    {
53
        return require $file;
54
    }
55
}
56