Event   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 116
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A cancelThisOperation() 0 4 1
A __construct() 0 8 1
A getSocket() 0 4 1
A getContext() 0 4 1
A getExecutor() 0 4 1
A getType() 0 4 1
A isOperationCancelled() 0 4 1
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
11
namespace AsyncSockets\Event;
12
13
use AsyncSockets\RequestExecutor\RequestExecutorInterface;
14
use AsyncSockets\Socket\SocketInterface;
15
16
/**
17
 * Class Event
18
 *
19
 * @api
20
 */
21
class Event extends AbstractEvent
22
{
23
    /**
24
     * Socket linked to this event
25
     *
26
     * @var SocketInterface
27
     */
28
    private $socket;
29
30
    /**
31
     * User data for this event
32
     *
33
     * @var mixed
34
     */
35
    private $context;
36
37
    /**
38
     * Request executor
39
     *
40
     * @var RequestExecutorInterface
41
     */
42
    private $executor;
43
44
    /**
45
     * This event type
46
     *
47
     * @var string
48
     */
49
    private $type;
50
51
    /**
52
     * Flag to stop this socket request
53
     *
54
     * @var bool
55
     */
56
    private $isCancelled;
57
58
    /**
59
     * Constructor
60
     *
61
     * @param RequestExecutorInterface $executor Request executor object
62
     * @param SocketInterface          $socket   Socket for this request
63
     * @param mixed                    $context  Any optional user data for event
64
     * @param string                   $type One of EventType::* constants
65
     */
66 222
    public function __construct(RequestExecutorInterface $executor, SocketInterface $socket, $context, $type)
67
    {
68 222
        $this->executor    = $executor;
69 222
        $this->socket      = $socket;
70 222
        $this->context     = $context;
71 222
        $this->type        = $type;
72 222
        $this->isCancelled = false;
73 222
    }
74
75
    /**
76
     * Return associated socket
77
     *
78
     * @return SocketInterface
79
     */
80 15
    public function getSocket()
81
    {
82 15
        return $this->socket;
83
    }
84
85
    /**
86
     * Return user specified context
87
     *
88
     * @return mixed
89
     */
90 30
    public function getContext()
91
    {
92 30
        return $this->context;
93
    }
94
95
    /**
96
     * Return RequestExecutor
97
     *
98
     * @return RequestExecutorInterface
99
     */
100 24
    public function getExecutor()
101
    {
102 24
        return $this->executor;
103
    }
104
105
    /**
106
     * Return type of this event
107
     *
108
     * @return string One of EventType::* consts
109
     */
110 170
    public function getType()
111
    {
112 170
        return $this->type;
113
    }
114
115
    /**
116
     * Return flag whether this socket operation is cancelled
117
     *
118
     * @return boolean
119
     */
120 142
    public function isOperationCancelled()
121
    {
122 142
        return $this->isCancelled;
123
    }
124
125
    /**
126
     * Sets cancel this operation flag
127
     *
128
     * @param boolean $isCancelled Cancel flag
129
     *
130
     * @return void
131
     */
132 12
    public function cancelThisOperation($isCancelled = true)
133
    {
134 12
        $this->isCancelled = $isCancelled;
135 12
    }
136
}
137