Completed
Pull Request — master (#567)
by thomas
72:50
created

RpcCredential::getConfigArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\RpcTest;
4
5
6
class RpcCredential
7
{
8
    const CONFIG_TEMPLATE = <<<EOF
9
rpcuser=%s
10
rpcpassword=%s
11
rpcport=%d
12
rpcallowip=127.0.0.1
13
server=1
14
daemon=1
15
regtest=1
16
EOF;
17
18
    /**
19
     * @var string
20
     */
21
    private $host;
22
23
    /**
24
     * @var int
25
     */
26
    private $port;
27
28
    /**
29
     * @var string
30
     */
31
    private $username;
32
33
    /**
34
     * @var string
35
     */
36
    private $password;
37
38
    /**
39
     * @var bool
40
     */
41
    private $isHttps;
42
43
    /**
44
     * RpcCredential constructor.
45
     * @param string $host
46
     * @param int $port
47
     * @param string $user
48
     * @param string $pass
49
     * @param bool $isHttps
50
     */
51
    public function __construct($host, $port, $user, $pass, $isHttps = false)
52
    {
53
        $this->host = $host;
54
        $this->username = $user;
55
        $this->port = $port;
56
        $this->password = $pass;
57
        $this->isHttps = $isHttps;
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getConfigArray()
64
    {
65
        return [
66
            "rpcuser" => $this->username,
67
            "rpcpassword" => $this->password,
68
            "rpcport" => $this->port,
69
            "rpcallowip" => "127.0.0.1",
70
        ];
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getDsn()
77
    {
78
        $prefix = "http" . ($this->isHttps ? "s" : "");
79
        return "$prefix://{$this->username}:{$this->password}@{$this->host}:{$this->port}";
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getHost()
86
    {
87
        return $this->host;
88
    }
89
90
    /**
91
     * @return int
92
     */
93
    public function getPort()
94
    {
95
        return $this->port;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    public function getUsername()
102
    {
103
        return $this->username;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getPassword()
110
    {
111
        return $this->password;
112
    }
113
114
    /**
115
     * @return bool
116
     */
117
    public function isHttps()
118
    {
119
        return $this->isHttps;
120
    }
121
122
}
123