SlowSpeedTransferException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 52.17%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 93
ccs 12
cts 23
cp 0.5217
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A getSpeed() 0 4 1
A getDuration() 0 4 1
A tooSlowDataReceiving() 0 10 1
A tooSlowDataSending() 0 10 1
1
<?php
2
/**
3
 * Async sockets
4
 *
5
 * @copyright Copyright (c) 2015-2017, 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 SlowSpeedTransferException. Thrown when transfer speed is slow then given in socket setup
16
 */
17
class SlowSpeedTransferException extends TransferException
18
{
19
    /**
20
     * Speed at the moment of exception in bytes per second
21
     *
22
     * @var double
23
     */
24
    private $speed;
25
26
    /**
27
     * Duration of low speed in seconds
28
     *
29
     * @var int
30
     */
31
    private $duration;
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 1
    public function __construct(
37
        SocketInterface $socket,
38
        $direction,
39
        $speed,
40
        $duration,
41
        $message = '',
42
        $code = 0,
43
        \Exception $previous = null
44
    ) {
45 1
        parent::__construct($socket, $direction, $message, $code, $previous);
46 1
        $this->speed    = $speed;
47 1
        $this->duration = $duration;
48 1
    }
49
50
    /**
51
     * Create exception for slow receive speed
52
     *
53
     * @param SocketInterface $socket Socket
54
     * @param double          $speed Speed at the moment of exception in bytes per second
55
     * @param int             $duration Duration of low speed in seconds
56
     *
57
     * @return SlowSpeedTransferException
58
     */
59 1
    public static function tooSlowDataReceiving(SocketInterface $socket, $speed, $duration)
60
    {
61 1
        return new self(
62 1
            $socket,
63 1
            self::DIRECTION_RECV,
64 1
            $speed,
65 1
            $duration,
66
            'Data transfer is going to be aborted because of too slow speed.'
67 1
        );
68
    }
69
70
    /**
71
     * Create exception for slow send speed
72
     *
73
     * @param SocketInterface $socket Socket
74
     * @param double          $speed Speed at the moment of exception in bytes per second
75
     * @param int             $duration Duration of low speed in seconds
76
     *
77
     * @return SlowSpeedTransferException
78
     */
79
    public static function tooSlowDataSending(SocketInterface $socket, $speed, $duration)
80
    {
81
        return new self(
82
            $socket,
83
            self::DIRECTION_SEND,
84
            $speed,
85
            $duration,
86
            'Data transfer is going to be aborted because of too slow speed.'
87
        );
88
    }
89
90
    /**
91
     * Return speed at the moment of exception in bytes per second
92
     *
93
     * @return float
94
     */
95
    public function getSpeed()
96
    {
97
        return $this->speed;
98
    }
99
100
    /**
101
     * Return duration of low speed in seconds
102
     *
103
     * @return int
104
     */
105
    public function getDuration()
106
    {
107
        return $this->duration;
108
    }
109
}
110