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

UnsupportedOperationException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A oobDataUnsupported() 0 10 1
A oobDataPackageSizeExceeded() 0 12 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