Completed
Pull Request — master (#546)
by thomas
75:01 queued 05:00
created

RpcCredential::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 5
dl 0
loc 8
rs 9.4285
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 string
62
     */
63
    public function getConfig()
64
    {
65
        return sprintf(self::CONFIG_TEMPLATE, $this->username, $this->password, $this->port);
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getDsn()
72
    {
73
        $prefix = "http" . ($this->isHttps ? "s" : "");
74
        return "$prefix://{$this->username}:{$this->password}@{$this->host}:{$this->port}";
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getHost()
81
    {
82
        return $this->host;
83
    }
84
85
    /**
86
     * @return int
87
     */
88
    public function getPort()
89
    {
90
        return $this->port;
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public function getUsername()
97
    {
98
        return $this->username;
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function getPassword()
105
    {
106
        return $this->password;
107
    }
108
109
    /**
110
     * @return bool
111
     */
112
    public function isHttps()
113
    {
114
        return $this->isHttps;
115
    }
116
117
}
118