ASocket   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 45
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __destruct() 0 3 1
A close() 0 5 2
A getResourcePointer() 0 8 2
1
<?php
2
3
namespace kalanis\RemoteRequest\Sockets;
4
5
6
use kalanis\RemoteRequest\Interfaces\IConnectionParams;
7
use kalanis\RemoteRequest\Interfaces\IRRTranslations;
8
use kalanis\RemoteRequest\RequestException;
9
use kalanis\RemoteRequest\Traits\TLang;
10
11
12
/**
13
 * Class ASocket
14
 * @package kalanis\RemoteRequest\Sockets
15
 * Network sockets to the remote server - base abstract method
16
 */
17
abstract class ASocket
18
{
19
    use TLang;
20
21
    /** @var resource|null */
22
    protected $pointer = null;
23
24 57
    public function __construct(?IRRTranslations $lang = null)
25
    {
26 57
        $this->setRRLang($lang);
27
    }
28
29 57
    public function __destruct()
30
    {
31 57
        $this->close();
32
    }
33
34 57
    public function close(): void
35
    {
36 57
        if (!empty($this->pointer)) {
37 5
            fclose($this->pointer);
38 5
            $this->pointer = null;
39
        }
40
    }
41
42
    /**
43
     * @param IConnectionParams $params
44
     * @throws RequestException
45
     * @return resource
46
     */
47
    abstract protected function remotePointer(IConnectionParams $params);
48
49
    /**
50
     * @param IConnectionParams $params
51
     * @throws RequestException
52
     * @return resource|null
53
     */
54 7
    public function getResourcePointer(IConnectionParams $params)
55
    {
56 7
        if (empty($this->pointer)) {
57 7
            $this->pointer = $this->remotePointer($params);
58
        } else {
59 1
            rewind($this->pointer);
60
        }
61 6
        return $this->pointer;
62
    }
63
}
64