XmlFileLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 34
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 4 2
A loadFile() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the ConfigCacheBundle package.
5
 *
6
 * Copyright (c) 2015-2016 Yahoo Japan Corporation
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 YahooJapan\ConfigCacheBundle\ConfigCache\Loader;
13
14
use Symfony\Component\Config\Util\XmlUtils;
15
16
/**
17
 * XmlFileLoader loads XML files user configurations.
18
 */
19
class XmlFileLoader extends Loader
20
{
21
    /**
22
     * Returns true if this class supports the given resource.
23
     *
24
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
25
     * @param mixed  $resource A resource
26
     * @param string $type     The resource type
27
     *
28
     * @return bool true if this class supports the given resource, false otherwise
29
     */
30 3
    public function supports($resource, $type = null)
31
    {
32 3
        return is_string($resource) && 'xml' === pathinfo($resource, PATHINFO_EXTENSION);
33
    }
34
35
    /**
36
     * Loads internal.
37
     *
38
     * @param string $file
39
     *
40
     * @return \SimpleXMLElement
41
     */
42 3
    protected function loadFile($file)
43
    {
44
        try {
45 3
            $dom = XmlUtils::loadFile($file);
46 3
        } catch (\Exception $e) {
47 2
            throw new \Exception(sprintf('Unable to parse file "%s".', $file), $e->getCode());
48
        }
49
50 1
        return simplexml_import_dom($dom);
51
    }
52
}
53