Completed
Branch master (1d1574)
by Evgenij
18:38
created

UdpClientSocket::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Async sockets
4
 *
5
 * @copyright Copyright (c) 2015-2016, 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
namespace AsyncSockets\Socket;
11
12
use AsyncSockets\Frame\FramePickerInterface;
13
use AsyncSockets\Socket\Io\DatagramMemorizedIo;
14
use AsyncSockets\Socket\Io\IoInterface;
15
16
/**
17
 * Class UdpClientSocket
18
 */
19
class UdpClientSocket implements SocketInterface, WithoutConnectionInterface
20
{
21
    /**
22
     * Original server socket
23
     *
24
     * @var SocketInterface
25
     */
26
    private $origin;
27
28
    /**
29
     * I/O interface
30
     *
31
     * @var IoInterface
32
     */
33
    private $ioInterface;
34
35
    /**
36
     * UdpClientSocket constructor.
37
     *
38
     * @param SocketInterface $origin Original server socket
39
     * @param string          $remoteAddress Client address
40
     * @param string          $data Data for this client
41
     */
42 8
    public function __construct(SocketInterface $origin, $remoteAddress, $data)
43
    {
44 8
        $this->origin      = $origin;
45 8
        $this->ioInterface = new DatagramMemorizedIo($this, $remoteAddress, $data);
46 8
    }
47
48
    /** {@inheritdoc} */
49 3
    public function open($address, $context = null)
50
    {
51
        // empty body
52 3
    }
53
54
    /** {@inheritdoc} */
55 1
    public function close()
56
    {
57
        // empty body
58 1
    }
59
60
    /** {@inheritdoc} */
61 1
    public function read(FramePickerInterface $picker)
62
    {
63 1
        return $this->ioInterface->read($picker);
64
    }
65
66
    /** {@inheritdoc} */
67 1
    public function write($data)
68
    {
69 1
        return $this->ioInterface->write($data);
70
    }
71
72
    /** {@inheritdoc} */
73 4
    public function getStreamResource()
74
    {
75 4
        return $this->origin->getStreamResource();
76
    }
77
78
    /**
79
     * @inheritDoc
80
     */
81 1
    public function __toString()
82
    {
83 1
        return (string) $this->origin;
84
    }
85
}
86