Completed
Branch 0.4-dev (54e67b)
by Evgenij
02:52
created

AcceptedSocket   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 33
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createSocketResource() 0 11 2
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\Exception\NetworkSocketException;
13
14
/**
15
 * Class AcceptedSocket
16
 */
17
class AcceptedSocket extends AbstractClientSocket
18
{
19
    /**
20
     * Accepted client
21
     *
22
     * @var resource
23
     */
24
    private $acceptedResource;
25
26
    /**
27
     * AcceptedSocket constructor.
28
     *
29
     * @param resource $acceptedResource Accepted client socket
30
     */
31 16
    public function __construct($acceptedResource)
32
    {
33 16
        parent::__construct();
34 16
        $this->acceptedResource = $acceptedResource;
35 16
    }
36
37
    /** {@inheritdoc} */
38 11
    protected function createSocketResource($address, $context)
39
    {
40 11
        if ($this->acceptedResource) {
41 11
            $result                 = $this->acceptedResource;
42 11
            $this->acceptedResource = null;
43
44 11
            return $result;
45
        }
46
47 1
        throw new NetworkSocketException($this, 'Remote client socket can not be reopened.');
48
    }
49
}
50