Completed
Push — master ( 9cf0f6...8cb16a )
by Nick
02:21
created

ConfigReader::getInstallDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Meanbee\LibMageConf;
4
5
use Meanbee\LibMageConf\Exception\FileNotFound;
6
7
class ConfigReader
8
{
9
    protected $configFile;
10
    protected $xmlDoc;
11
12 8
    public function __construct($configFile)
13
    {
14 8
        $this->configFile = $configFile;
15
16 8
        if (!file_exists($this->configFile)) {
17 1
            throw new FileNotFound(
18 1
                sprintf("Unable to find config file at %s", $this->configFile)
19
            );
20
        }
21
22 7
        $this->xmlDoc = new \SimpleXMLElement(file_get_contents($this->configFile));
23 7
    }
24
25
    /**
26
     * @param $xpath
27
     * @return null|string
28
     */
29 7
    public function xpath($xpath)
30
    {
31 7
        $result = $this->xmlDoc->xpath($xpath);
32
33 7
        if (count($result) > 0) {
34 7
            return (string) $result[0];
35
        }
36
37 1
        return null;
38
    }
39
40
    /**
41
     * @return null|string
42
     */
43 1
    public function getDatabaseHost()
44
    {
45 1
        return $this->xpath('//config/global/resources/default_setup/connection/host');
46
    }
47
48
    /**
49
     * @return null|string
50
     */
51 1
    public function getDatabaseUsername()
52
    {
53 1
        return $this->xpath('//config/global/resources/default_setup/connection/username');
54
    }
55
56
    /**
57
     * @return null|string
58
     */
59 1
    public function getDatabasePassword()
60
    {
61 1
        return $this->xpath('//config/global/resources/default_setup/connection/password');
62
    }
63
64
    /**
65
     * @return null|string
66
     */
67 1
    public function getDatabaseName()
68
    {
69 1
        return $this->xpath('//config/global/resources/default_setup/connection/dbname');
70
    }
71
72
    /**
73
     * @return null|string
74
     */
75 1
    public function getInstallDate()
76
    {
77 1
        return $this->xpath('//config/global/install/date');
78
    }
79
80
    /**
81
     * @return null|string
82
     */
83 1
    public function getAdminFrontName()
84
    {
85 1
        return $this->xpath('//config/admin/routers/adminhtml/args/frontName');
86
    }
87
}