Test Failed
Pull Request — master (#12)
by
unknown
02:46
created

ProducterConfig::setRequestTimeout()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 3
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Seasx\SeasLogger\Kafka;
5
6
use Exception;
7
use Seasx\SeasLogger\Exceptions\NotSupportedException;
8
use function in_array;
9
10
/**
11
 * @method int getRequestTimeout()
12
 * @method int getProduceInterval()
13
 * @method int getTimeout()
14
 * @method int getRequiredAck()
15
 * @method bool getIsAsyn()
16
 * @method int getCompression()
17
 */
18
class ProducterConfig extends Config
19
{
20
    private const COMPRESSION_OPTIONS = [
21
        Produce::COMPRESSION_NONE,
22
        Produce::COMPRESSION_GZIP,
23
        Produce::COMPRESSION_SNAPPY,
24
    ];
25
26
    /**
27
     * @var mixed[]
28
     */
29
    protected static $defaults = [
30
        'clientId' => 'seaslog-kafka',
31
        'brokerVersion' => '0.10.1.0',
32
        'metadataBrokerList' => '',
33
        'messageMaxBytes' => 1000000,
34
        'metadataRequestTimeoutMs' => 60000,
35
        'metadataRefreshIntervalMs' => 300000,
36
        'metadataMaxAgeMs' => -1,
37
        'requiredAck' => 1,
38
        'timeout' => 5000,
39
        'requestTimeout' => 6000,
40
        'compression' => Protocol::COMPRESSION_NONE,
41
    ];
42
43
    /**
44
     * @param int $requestTimeout
45
     * @throws Exception
46
     */
47
    public function setRequestTimeout(int $requestTimeout): void
48
    {
49
        if ($requestTimeout < 1 || $requestTimeout > 900000) {
50
            throw new NotSupportedException('Set request timeout value is invalid, must set it 1 .. 900000');
51
        }
52
53
        $this->options['requestTimeout'] = $requestTimeout;
54
    }
55
56
    /**
57
     * @param int $timeout
58
     * @throws Exception
59
     */
60
    public function setTimeout(int $timeout): void
61
    {
62
        if ($timeout < 1 || $timeout > 900000) {
63
            throw new NotSupportedException('Set timeout value is invalid, must set it 1 .. 900000');
64
        }
65
66
        $this->options['timeout'] = $timeout;
67
    }
68
69
    /**
70
     * @param int $requiredAck
71
     * @throws Exception
72
     */
73
    public function setRequiredAck(int $requiredAck): void
74
    {
75
        if ($requiredAck < -1 || $requiredAck > 1000) {
76
            throw new NotSupportedException('Set required ack value is invalid, must set it -1 .. 1000');
77
        }
78
79
        $this->options['requiredAck'] = $requiredAck;
80
    }
81
82
    /**
83
     * @param int $compression
84
     * @throws Exception
85
     */
86
    public function setCompression(int $compression): void
87
    {
88
        if (!in_array($compression, self::COMPRESSION_OPTIONS, true)) {
89
            throw new NotSupportedException('Compression must be one the Produce::COMPRESSION_* constants');
90
        }
91
92
        $this->options['compression'] = $compression;
93
    }
94
}
95