Completed
Push — master ( 9cb483...15ad7c )
by Maik
03:24
created

SecureClientSocket::isWriteable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.0625
1
<?php
2
namespace Generics\Socket;
3
4
class SecureClientSocket extends SecureSocket
5
{
6
    /**
7
     * Whether the socket is connected
8
     *
9
     * @var boolean
10
     */
11
    private $conntected;
12
    
13
    /**
14
     * Create a new client socket
15
     *
16
     * @param Endpoint $endpoint
17
     *            The endpoint to use
18
     * @param resource $clientHandle
19
     *            optional existing client handle
20
     */
21 11 View Code Duplication
    public function __construct(Endpoint $endpoint, $clientHandle = null)
22
    {
23 11
        $this->endpoint = $endpoint;
24 11
        $this->handle = $clientHandle;
25 11
        $this->conntected = false;
26
        
27 11
        if (! is_resource($clientHandle)) {
28 11
            parent::__construct($endpoint);
29
        }
30 11
    }
31
    
32
    /**
33
     * Connect to remote endpoint
34
     *
35
     * @throws SocketException
36
     */
37 11
    public function connect()
38
    {
39 11
        $this->conntected = true;
40 11
    }
41
42
    /**
43
     * Disconnects the socket
44
     *
45
     * @throws SocketException
46
     */
47 5
    public function disconnect()
48
    {
49 5
        if (! $this->conntected) {
50
            throw new SocketException("Socket is not connected");
51
        }
52
        
53 5
        $this->close();
54 5
    }
55
    
56
    /**
57
     * Whether the client is connected
58
     *
59
     * @return bool
60
     */
61 11
    public function isConnected():bool
62
    {
63 11
        return $this->conntected;
64
    }
65
    
66
    /**
67
     *
68
     * @see \Generics\Socket\ClientSocket::disconnect()
69
     */
70 6
    public function close()
71
    {
72 6
        parent::close();
73 6
        $this->conntected = false;
74 6
    }
75
    
76
    /**
77
     *
78
     * {@inheritdoc}
79
     * @see \Generics\Socket\Socket::isWriteable()
80
     */
81 11
    public function isWriteable():bool
82
    {
83 11
        if (! $this->isConnected()) {
84
            return false;
85
        }
86
        
87 11
        return parent::isWriteable();
88
    }
89
}