LightningdRpcConnector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 18
ccs 0
cts 7
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A disconnect() 0 6 2
A connect() 0 5 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the ngutech/lightningd-adapter project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace NGUtech\Lightningd\Connector;
10
11
use Daikon\Dbal\Connector\ConnectorInterface;
12
use Daikon\Dbal\Connector\ProvidesConnector;
13
use Socket\Raw\Factory;
14
use Socket\Raw\Socket;
15
16
final class LightningdRpcConnector implements ConnectorInterface
17
{
18
    use ProvidesConnector;
19
20
    protected function connect(): Socket
21
    {
22
        return (new Factory)->createClient(
23
            'unix://'.$this->settings['rpc_file'],
24
            $this->settings['socket_timeout'] ?? 30
25
        );
26
    }
27
28
    public function disconnect(): void
29
    {
30
        if ($this->isConnected()) {
31
            $this->connection->shutdown();
32
            $this->connection->close();
33
            $this->connection = null;
34
        }
35
    }
36
}
37