Completed
Push — master ( 89265b...110e58 )
by Alexpts
01:59
created

Socket   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 24
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A connect() 0 11 2
1
<?php
2
declare(strict_types=1);
3
4
namespace PTS\Transport;
5
6
class Socket extends BaseTransport
7
{
8
9
    protected $errorNumber = 0;
10
    protected $errorMessage = '';
11
12
    /**
13
     * @param string $address
14
     * @param array $options
15
     *
16
     * @return TransportInterface
17
     */
18 12
    public function connect(string $address, array $options = []): TransportInterface
19
    {
20 12
        if ($this->target === null) {
21 12
            $timeout = (float)($options['timeout'] ??(float) ini_get('default_socket_timeout'));
22 12
            $port = $options['port'] ?? 0;
23 12
            $url = $this->schema . $address;
24 12
            $this->target = fsockopen($url, $port, $this->errorNumber, $this->errorMessage, $timeout);
25
        }
26
27 12
        return $this;
28
    }
29
}
30