Completed
Push — master ( 104e68...b4839f )
by Maxime
12s
created

WrongOpcodeHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 4 1
A process() 0 5 1
1
<?php
2
/**
3
 * This file is a part of Woketo package.
4
 *
5
 * (c) Nekland <[email protected]>
6
 *
7
 * For the full license, take a look to the LICENSE file
8
 * on the root directory of this project
9
 */
10
11
namespace Nekland\Woketo\Rfc6455\MessageHandler;
12
13
14
use Nekland\Woketo\Rfc6455\Frame;
15
use Nekland\Woketo\Rfc6455\Message;
16
use Nekland\Woketo\Rfc6455\MessageProcessor;
17
use React\Socket\ConnectionInterface;
18
use React\Stream\Stream;
19
20
class WrongOpcodeHandler implements Rfc6455MessageHandlerInterface
21
{
22
    /**
23
     * The following opcode are wrong for now but may represent something in the future depending on how the spec evolves.
24
     * https://tools.ietf.org/html/rfc6455#section-5.2
25
     *
26
     * @param Message $message
27
     * @return bool
28
     */
29 16
    public function supports(Message $message)
30
    {
31 16
        return \in_array($message->getOpcode(), [3, 4, 5, 6, 7, 11, 12, 13, 14, 15]);
32
    }
33
34
    /**
35
     * @param Message             $message
36
     * @param MessageProcessor    $messageProcessor
37
     * @param ConnectionInterface $socket
38
     * @return null|void
39
     */
40 1
    public function process(Message $message, MessageProcessor $messageProcessor, Stream $socket)
41
    {
42 1
        $messageProcessor->write($messageProcessor->getFrameFactory()->createCloseFrame(Frame::CLOSE_PROTOCOL_ERROR), $socket);
43 1
        $socket->end();
44 1
    }
45
}
46