Completed
Pull Request — master (#81)
by Charlotte
02:05
created

WrongOpcodeHandler::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
crap 2
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
19
class WrongOpcodeHandler implements Rfc6455MessageHandlerInterface
20
{
21
    /**
22
     * The following opcode are wrong for now but may represent something in the future depending on how the spec evolves.
23
     * https://tools.ietf.org/html/rfc6455#section-5.2
24
     *
25
     * @param Message $message
26
     * @return bool
27
     */
28
    public function supports(Message $message)
29
    {
30
        return in_array($message->getOpcode(), [3, 4, 5, 6, 7, 11, 12, 13, 14, 15]);
31
    }
32
33
    /**
34
     * @param Message             $message
35
     * @param MessageProcessor    $messageProcessor
36
     * @param ConnectionInterface $socket
37
     * @return null|void
38
     */
39
    public function process(Message $message, MessageProcessor $messageProcessor, ConnectionInterface $socket)
40
    {
41
        $messageProcessor->write($messageProcessor->getFrameFactory()->createCloseFrame(Frame::CLOSE_PROTOCOL_ERROR), $socket);
42
        $socket->end();
43
    }
44
}
45