LightningdRpcConnector::disconnect()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 6
rs 10
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