Queue::touch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
/**
4
 * This file is part of the tarantool/queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Tarantool\Queue;
15
16
use Tarantool\Client\Client;
17
18
class Queue
19
{
20
    private $client;
21
    private $name;
22
23 172
    public function __construct(Client $client, string $name)
24
    {
25 172
        $this->client = $client;
26 172
        $this->name = $name;
27
    }
28
29 1
    public function getClient() : Client
30
    {
31 1
        return $this->client;
32
    }
33
34 1
    public function getName() : string
35
    {
36 1
        return $this->name;
37
    }
38
39
    /**
40
     * @param mixed $data
41
     */
42 32
    public function put($data, array $options = []) : Task
43
    {
44 32
        return Task::fromTuple(
45 32
            $this->client->call("queue.tube.$this->name:put", $data, $options)[0]
46 32
        );
47
    }
48
49 24
    public function take(float $timeout = null) : ?Task
50
    {
51 24
        $result = $this->client->call("queue.tube.$this->name:take", $timeout);
52
53 24
        return empty($result[0]) ? null : Task::fromTuple($result[0]);
54
    }
55
56 6
    public function touch(int $taskId, float $increment) : ?Task
57
    {
58 6
        $result = $this->client->call("queue.tube.$this->name:touch", $taskId, $increment);
59
60 6
        return empty($result[0]) ? null : Task::fromTuple($result[0]);
61
    }
62
63 8
    public function ack(int $taskId) : Task
64
    {
65 8
        return Task::fromTuple(
66 8
            $this->client->call("queue.tube.$this->name:ack", $taskId)[0]
67 8
        );
68
    }
69
70 12
    public function release(int $taskId, array $options = []) : Task
71
    {
72 12
        return Task::fromTuple(
73 12
            $this->client->call("queue.tube.$this->name:release", $taskId, $options)[0]
74 12
        );
75
    }
76
77 12
    public function peek(int $taskId) : Task
78
    {
79 12
        return Task::fromTuple(
80 12
            $this->client->call("queue.tube.$this->name:peek", $taskId)[0]
81 12
        );
82
    }
83
84 8
    public function bury(int $taskId) : Task
85
    {
86 8
        return Task::fromTuple(
87 8
            $this->client->call("queue.tube.$this->name:bury", $taskId)[0]
88 8
        );
89
    }
90
91 8
    public function kick(int $count) : int
92
    {
93 8
        return $this->client->call("queue.tube.$this->name:kick", $count)[0];
94
    }
95
96 10
    public function delete(int $taskId) : Task
97
    {
98 10
        return Task::fromTuple(
99 10
            $this->client->call("queue.tube.$this->name:delete", $taskId)[0]
100 10
        );
101
    }
102
103 8
    public function truncate() : void
104
    {
105 8
        $this->client->call("queue.tube.$this->name:truncate");
106
    }
107
108
    /**
109
     * @throws \InvalidArgumentException
110
     *
111
     * @return array|int
112
     */
113 58
    public function stats(?string $path = null)
114
    {
115 58
        [$stats] = $this->client->call('queue.stats', $this->name);
116
117 58
        if (null === $path) {
118 8
            return $stats;
119
        }
120
121 50
        foreach (\explode('.', $path) as $key) {
122 50
            if (!isset($stats[$key])) {
123 36
                throw new \InvalidArgumentException(\sprintf('Invalid path "%s"', $path));
124
            }
125 30
            $stats = $stats[$key];
126
        }
127
128 14
        return $stats;
129
    }
130
131
    /**
132
     * @param mixed ...$args
133
     */
134 4
    public function call(string $methodName, ...$args) : array
135
    {
136 4
        return $this->client->call("queue.tube.$this->name:$methodName", ...$args);
137
    }
138
}
139