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

StreamedServerIo::read()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 7
nc 2
nop 1
crap 3
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\Io;
11
12
use AsyncSockets\Exception\AcceptException;
13
use AsyncSockets\Frame\AcceptedFrame;
14
use AsyncSockets\Frame\FramePickerInterface;
15
use AsyncSockets\Socket\AcceptedSocket;
16
17
/**
18
 * Class StreamedServerIo
19
 */
20
class StreamedServerIo extends AbstractServerIo
21
{
22
    /** {@inheritdoc} */
23 2
    public function read(FramePickerInterface $picker)
24
    {
25 2
        $client = stream_socket_accept($this->socket->getStreamResource(), 0, $peerName);
26 2
        if ($client === false) {
27 1
            throw new AcceptException($this->socket, 'Can not accept client connection.');
28
        }
29
30 1
        return new AcceptedFrame(
31 1
            $peerName ?: '',
32 1
            new AcceptedSocket($client)
33 1
        );
34
    }
35
}
36