Test Setup Failed
Push — master ( 7a093e...068245 )
by Nick
05:17
created

MagentoTwo::getDatabasePort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Meanbee\LibMageConf\ConfigReader;
4
5
use Meanbee\LibMageConf\ConfigReader;
6
use Meanbee\LibMageConf\Exception\FileNotFound;
7
use Meanbee\LibMageConf\Util\ArrayQuery;
8
use Meanbee\LibMageConf\Util\DsnParser;
9
10
11
class MagentoTwo implements ConfigReader
12
{
13
    protected $configFile;
14
    protected $configArray;
15
    protected $config;
16
17
    public function __construct($configFile)
18
    {
19
        $this->configFile = $configFile;
20
21
        if (!file_exists($this->configFile)) {
22
            throw new FileNotFound(
23
                sprintf("Unable to find config file at %s", $this->configFile)
24
            );
25
        }
26
27
        $this->configArray = include $this->configFile;
28
        $this->config = new ArrayQuery($this->configArray);
29
    }
30
31
32
    /**
33
     * @return null|string
34
     */
35
    public function getDatabaseHost()
36
    {
37
        return $this->getDsnParser()->getHost();
38
    }
39
40
    /**
41
     * @return null|string
42
     */
43
    public function getDatabasePort()
44
    {
45
        return $this->getDsnParser()->getPort();
46
    }
47
48
    /**
49
     * @return null|string
50
     */
51
    public function getDatabaseUsername()
52
    {
53
        return $this->getConfigValue('db/connection/default/username');
54
    }
55
56
    /**
57
     * @return null|string
58
     */
59
    public function getDatabasePassword()
60
    {
61
        return $this->getConfigValue('db/connection/default/password');
62
    }
63
64
    /**
65
     * @return null|string
66
     */
67
    public function getDatabaseName()
68
    {
69
        return $this->getConfigValue('db/connection/default/dbname');
70
    }
71
72
    /**
73
     * @return null|string
74
     */
75
    public function getInstallDate()
76
    {
77
        return $this->getConfigValue('install/date');
78
    }
79
80
    /**
81
     * @return null|string
82
     */
83
    public function getAdminFrontName()
84
    {
85
        return $this->getConfigValue('backend/frontName');
86
    }
87
88
    /**
89
     * @param $path
90
     * @return string
91
     */
92
    protected function getConfigValue($path)
93
    {
94
        return $this->config->query($path);
95
    }
96
97
    /**
98
     * @return DsnParser
99
     */
100
    protected function getDsnParser()
101
    {
102
        $rawHost = $this->getConfigValue('db/connection/default/host');
103
        return new DsnParser($rawHost);
104
    }
105
}