Completed
Pull Request — master (#64)
by thomas
56:33 queued 53:42
created

Factory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 68.75%

Importance

Changes 9
Bugs 0 Features 1
Metric Value
wmc 6
c 9
b 0
f 1
lcom 2
cbo 5
dl 0
loc 59
ccs 11
cts 16
cp 0.6875
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDns() 0 4 1
A __construct() 0 5 2
A getMessages() 0 7 2
A getAddress() 0 8 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Networking;
4
5
use BitWasp\Bitcoin\Bitcoin;
6
use BitWasp\Bitcoin\Crypto\Random\Random;
7
use BitWasp\Bitcoin\Network\NetworkInterface;
8
use BitWasp\Bitcoin\Networking\Ip\IpInterface;
9
use BitWasp\Bitcoin\Networking\Structure\NetworkAddress;
10
use React\EventLoop\LoopInterface;
11
12
class Factory
13
{
14
15
    /**
16
     * @var NetworkInterface
17
     */
18
    private $network;
19
20
    /**
21
     * @var LoopInterface
22
     */
23
    private $loop;
24
25
    /**
26
     * @param NetworkInterface $network
27
     * @param LoopInterface $loop
28
     */
29 9
    public function __construct(LoopInterface $loop, NetworkInterface $network = null)
30
    {
31 9
        $this->loop = $loop;
32 9
        $this->network = $network ?: Bitcoin::getNetwork();
33 9
    }
34
35
    /**
36
     * @param string $host
37
     * @return Dns\Resolver
38
     */
39 9
    public function getDns($host = '8.8.8.8')
40
    {
41 9
        return (new Dns\Factory())->create($host, $this->loop);
42
    }
43
44
    /**
45
     * @param Random|null $random
46
     * @return Messages\Factory
47
     */
48 3
    public function getMessages(Random $random = null)
49
    {
50 3
        return new Messages\Factory(
51 3
            $this->network,
52 3
            $random ?: new Random()
53 2
        );
54
    }
55
56
    /**
57
     * @param IpInterface $ipAddress
58
     * @param int $port
59
     * @param int $services
60
     * @return NetworkAddress
61
     */
62
    public function getAddress(IpInterface $ipAddress, $port = 8333, $services = Services::NONE)
63
    {
64
        return new NetworkAddress(
65
            $services,
66
            $ipAddress,
67
            $port
68
        );
69
    }
70
}
71