Completed
Branch 0.4-dev (bf83d7)
by Evgenij
03:03
created

oobDataUnsupported()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Async sockets
4
 *
5
 * @copyright Copyright (c) 2015-2016, 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
namespace AsyncSockets\Exception;
11
12
use AsyncSockets\Socket\SocketInterface;
13
14
/**
15
 * Class UnsupportedOperationException
16
 */
17
class UnsupportedOperationException extends NetworkSocketException
18
{
19
    /**
20
     * Throw OOB unsupported error for given socket
21
     *
22
     * @param SocketInterface $socket Socket object tried to perform operation
23
     *
24
     * @return UnsupportedOperationException
25
     */
26 8
    public static function oobDataUnsupported(SocketInterface $socket)
27
    {
28 8
        return new self(
29 8
            $socket,
30 8
            sprintf(
31 8
                'Out-of-band data are unsupported for "%s".',
32
                (string) $socket
33 8
            )
34 8
        );
35
    }
36
37
    /**
38
     * Throw OOB data size exceeded for given socket
39
     *
40
     * @param SocketInterface $socket Socket object tried to perform operation
41
     * @param int             $packetSize Size of packet in bytes
42
     * @param int             $size Size of data about to sent
43
     *
44
     * @return UnsupportedOperationException
45
     */
46 4
    public static function oobDataPackageSizeExceeded(SocketInterface $socket, $packetSize, $size)
47
    {
48 4
        return new self(
49 4
            $socket,
50 4
            sprintf(
51 4
                'Out-of-band data size is exceeded for socket "%s", (%s bytes allowed, %s bytes tried to sent).',
52 4
                (string) $socket,
53 4
                $packetSize,
54
                $size
55 4
            )
56 4
        );
57
    }
58
}
59