YMLParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 8
Bugs 1 Features 0
Metric Value
c 8
b 1
f 0
dl 0
loc 44
wmc 5
lcom 1
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A open() 0 8 3
A __call() 0 4 1
1
<?php
2
3
/**
4
 * @author Serkin Alexander <[email protected]>
5
 * @license https://github.com/serkin/ymlparser/LICENSE MIT
6
 */
7
8
namespace YMLParser;
9
10
class YMLParser
11
{
12
    /**
13
     * Driver for parsing xml.
14
     *
15
     * @var Driver\DriverInterface
16
     */
17
    private $driver;
18
19
    /**
20
     *
21
     * @param \YMLParser\Driver\DriverInterface $driver
22
     */
23
    public function __construct(Driver\DriverInterface $driver)
24
    {
25
        $this->driver = $driver;
26
    }
27
28
29
    /**
30
     * OpeС‚s and creates XML DOM tree.
31
     *
32
     * Sets error for YMLParser if cannot open file or xml is invalid
33
     *
34
     * @param string $filename Path to file
35
     *
36
     * @throws \Exception Throws exception if file doesn't exist or its size = 0
37
     *
38
     * @return bool
39
     */
40
    public function open($filename)
41
    {
42
        if (file_exists($filename) === false || filesize($filename) === 0):
43
            throw new \Exception("File: {$filename} does not exist or empty.");
44
        endif;
45
46
        return $this->driver->open($filename);
47
    }
48
49
    public function __call($method, $args = null)
50
    {
51
        return call_user_func_array([$this->driver, $method], $args);
52
    }
53
}
54