Completed
Push — master ( c97103...9edfc5 )
by Evgenij
03:08
created

AbstractClientSocket   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 35
c 0
b 0
f 0
ccs 13
cts 16
cp 0.8125
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B createIoInterface() 0 15 5
A isServer() 0 4 1
A isClient() 0 4 1
1
<?php
2
/**
3
 * Async sockets
4
 *
5
 * @copyright Copyright (c) 2015-2017, Efimov Evgenij <[email protected]>
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace AsyncSockets\Socket;
12
13
use AsyncSockets\Socket\Io\DatagramClientIo;
14
use AsyncSockets\Socket\Io\StreamedClientIo;
15
16
/**
17
 * Class AbstractClientSocket
18
 */
19
abstract class AbstractClientSocket extends AbstractSocket
20
{
21
    /** {@inheritdoc} */
22 37
    protected function createIoInterface($type, $address)
23
    {
24
        switch ($type) {
25 37
            case self::SOCKET_TYPE_UNIX:
26
                return new StreamedClientIo($this, 0);
27 37
            case self::SOCKET_TYPE_TCP:
28 34
                return new StreamedClientIo($this, 1);
29 3
            case self::SOCKET_TYPE_UDG:
30
                return new DatagramClientIo($this, null);
31 3
            case self::SOCKET_TYPE_UDP:
32
                return new DatagramClientIo($this, $address);
33 3
            default:
34 3
                throw new \LogicException("Unsupported socket resource type {$type}");
35 3
        }
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41 9
    public function isServer()
42
    {
43 9
        return false;
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49 3
    public function isClient()
50
    {
51 3
        return true;
52
    }
53
}
54