Completed
Pull Request — master (#591)
by thomas
22:54 queued 09:12
created

RpcCredential   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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