AcceptedSocket   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

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-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
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 20
    public function __construct($acceptedResource)
32
    {
33 20
        parent::__construct();
34 20
        $this->acceptedResource = $acceptedResource;
35 20
    }
36
37
    /** {@inheritdoc} */
38 12
    protected function createSocketResource($address, $context)
39
    {
40 12
        if ($this->acceptedResource) {
41 12
            $result                 = $this->acceptedResource;
42 12
            $this->acceptedResource = null;
43
44 12
            return $result;
45
        }
46
47 1
        throw new NetworkSocketException($this, 'Remote client socket can not be reopened.');
48
    }
49
}
50