Completed
Push — master ( d621a8...b2ef5f )
by Hong
02:39
created

XmlReader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A readFromFile() 0 5 2
A getError() 0 6 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Shared
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Shared\Reader;
16
17
/**
18
 * Read & parse xml formatted file and return the result
19
 *
20
 * @package Phossa2\Shared
21
 * @author  Hong Zhang <[email protected]>
22
 * @version 2.0.1
23
 * @since   2.0.1 added
24
 */
25
class XmlReader extends ReaderAbstract
26
{
27
    /**
28
     * {@inheritDoc}
29
     */
30
    protected static function readFromFile($path)
31
    {
32
        $data = @simplexml_load_file($path);
33
        return $data ? @json_decode(json_encode($data), true) : false;
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    protected static function getError(/*# string */ $path)/*#: string */
40
    {
41
        libxml_use_internal_errors(true);
42
        simplexml_load_file($path, null, \LIBXML_NOERROR);
43
        return libxml_get_errors()[0]->message;
44
    }
45
}
46