Completed
Push — master ( 5c8063...9a2413 )
by Taosikai
13:00
created

PublicConnection::pause()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Spike library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Spike\Server\TunnelServer;
7
8
use React\Socket\ConnectionInterface;
9
10
/**
11
 * @method write($data)
12
 * @method on($eventName, callable $listener)
13
 * @method pipe($dst, array $options = []);
14
 * @method removeListener($eventName, callable $listener);
15
 * @method removeAllListeners($eventName = null);
16
 * @method end($data = null);
17
 * @method pause();
18
 * @method resume();
19
 */
20
class PublicConnection
21
{
22
    /**
23
     * @var ConnectionInterface
24
     */
25
    protected $connection;
26
27
    /**
28
     * @var string
29
     */
30
    protected $initBuffer;
31
32
    /**
33
     * @var string
34
     */
35
    protected $id;
36
37
    /**
38
     * The create time
39
     * @var int
40
     */
41
    protected $createAt;
42
43
    public function __construct(ConnectionInterface $connection, $initBuffer = '')
44
    {
45
        $this->connection =  $connection;
46
        $this->initBuffer = $initBuffer;
47
        $this->id = spl_object_hash($connection);
48
        $this->createAt = microtime(true);
0 ignored issues
show
Documentation Bug introduced by
The property $createAt was declared of type integer, but microtime(true) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
49
    }
50
51
    public function __call($name, $arguments)
52
    {
53
        return call_user_func_array([$this->connection, $name], $arguments);
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getId()
60
    {
61
        return $this->id;
62
    }
63
64
    /**
65
     * @return ConnectionInterface
66
     */
67
    public function getConnection()
68
    {
69
        return $this->connection;
70
    }
71
72
    /**
73
     * @param string $initBuffer
74
     */
75
    public function setInitBuffer($initBuffer)
76
    {
77
        $this->initBuffer = $initBuffer;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getInitBuffer()
84
    {
85
        return $this->initBuffer;
86
    }
87
88
    /**
89
     * Gets the waiting duration of the connection
90
     * @return float
91
     */
92
    public function getWaitingDuration()
93
    {
94
        return microtime(true) - $this->createAt;
95
    }
96
}