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

WrongOpcodeHandler::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
crap 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