Passed
Pull Request — master (#8)
by Sergey
02:17
created

StreamGroupConsumer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 22
c 2
b 0
f 2
dl 0
loc 59
ccs 0
cts 35
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 18 2
A destroy() 0 17 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Asiries335\redisSteamPhp;
5
6
7
use Asiries335\redisSteamPhp\Data\Constants;
8
use Asiries335\redisSteamPhp\Dto\StreamCommandCallTransporter;
9
10
final class StreamGroupConsumer extends RedisStream
11
{
12
    /**
13
     * Create group Consumer
14
     *
15
     * @param string $groupName
16
     * @param bool $isShowFullHistoryStream
17
     *
18
     * @return bool
19
     *
20
     * @throws \Exception
21
     */
22
    public function create(string $groupName, bool $isShowFullHistoryStream = true) : bool
23
    {
24
        $transporter = new StreamCommandCallTransporter(
25
            [
26
                'command' => Constants::COMMAND_XGROUP,
27
                'args'    => [
28
                    Constants::COMMAND_OPTION_XGROUP_CREATE,
29
                    $this->_streamName,
30
                    $groupName,
31
                    (int) $isShowFullHistoryStream
32
                ]
33
            ]
34
        );
35
36
        try {
37
            return (bool) $this->_client->call($transporter);
38
        } catch (\Exception $exception) {
39
            throw $exception;
40
        }
41
    }
42
43
    /**
44
     * Delete group Consumer
45
     *
46
     * @param string $groupName
47
     *
48
     * @return bool
49
     *
50
     * @throws \Exception
51
     */
52
    public function destroy(string $groupName) : bool
53
    {
54
        $transporter = new StreamCommandCallTransporter(
55
            [
56
                'command' => Constants::COMMAND_XGROUP,
57
                'args'    => [
58
                    Constants::COMMAND_OPTION_XGROUP_DESTROY,
59
                    $this->_streamName,
60
                    $groupName,
61
                ]
62
            ]
63
        );
64
65
        try {
66
            return (bool) $this->_client->call($transporter);
67
        } catch (\Exception $exception) {
68
            throw $exception;
69
        }
70
    }
71
}