Completed
Pull Request — master (#5)
by Eugene
02:50
created

Queue::bury()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
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
namespace Tarantool\Queue;
13
14
class Queue
15
{
16
    private $client;
17
    private $tubeName;
18
    private $prefix;
19
20 135
    public function __construct(\Tarantool $client, $tubeName)
21
    {
22 135
        $this->client = $client;
23 135
        $this->tubeName = $tubeName;
24 135
        $this->prefix = "queue.tube.$tubeName:";
25 135
    }
26
27
    /**
28
     * @param mixed      $data
29
     * @param array|null $options
30
     *
31
     * @return Task
32
     */
33 34 View Code Duplication
    public function put($data, array $options = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35 34
        $args = $options ? [$data, $options] : [$data];
36 34
        $result = $this->client->call($this->prefix.'put', $args);
37
38 34
        return Task::createFromTuple($result[0]);
39
    }
40
41
    /**
42
     * @param int|float|null $timeout
43
     *
44
     * @return Task|null
45
     */
46 20
    public function take($timeout = null)
47
    {
48 20
        $args = null === $timeout ? [] : [$timeout];
49 20
        $result = $this->client->call($this->prefix.'take', $args);
50
51 20
        return empty($result[0]) ? null : Task::createFromTuple($result[0]);
52
    }
53
54
    /**
55
     * @param int $taskId
56
     *
57
     * @return Task
58
     */
59 9
    public function ack($taskId)
60
    {
61 9
        $result = $this->client->call($this->prefix.'ack', [$taskId]);
62
63 5
        return Task::createFromTuple($result[0]);
64
    }
65
66
    /**
67
     * @param int        $taskId
68
     * @param array|null $options
69
     *
70
     * @return Task
71
     */
72 12 View Code Duplication
    public function release($taskId, array $options = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74 12
        $args = $options ? [$taskId, $options] : [$taskId];
75 12
        $result = $this->client->call($this->prefix.'release', $args);
76
77 8
        return Task::createFromTuple($result[0]);
78
    }
79
80
    /**
81
     * @param int $taskId
82
     *
83
     * @return Task
84
     */
85 13
    public function peek($taskId)
86
    {
87 13
        $result = $this->client->call($this->prefix.'peek', [$taskId]);
88
89 9
        return Task::createFromTuple($result[0]);
90
    }
91
92
    /**
93
     * @param int $taskId
94
     *
95
     * @return Task
96
     */
97 9
    public function bury($taskId)
98
    {
99 9
        $result = $this->client->call($this->prefix.'bury', [$taskId]);
100
101 5
        return Task::createFromTuple($result[0]);
102
    }
103
104
    /**
105
     * @param int $count
106
     *
107
     * @return int
108
     */
109 13
    public function kick($count)
110
    {
111 13
        $result = $this->client->call($this->prefix.'kick', [$count]);
112
113 9
        return $result[0][0];
114
    }
115
116
    /**
117
     * @param int $taskId
118
     *
119
     * @return Task
120
     */
121 11
    public function delete($taskId)
122
    {
123 11
        $result = $this->client->call($this->prefix.'delete', [$taskId]);
124
125 7
        return Task::createFromTuple($result[0]);
126
    }
127
128
    /**
129
     * @param string|null $path
130
     *
131
     * @return array|int|null
132
     */
133 22
    public function statistics($path = null)
134
    {
135 22
        $result = $this->client->call('queue.statistics', [$this->tubeName]);
136
137 22
        if (empty($result[0][0])) {
138 1
            return;
139
        }
140 21
        if (null === $path) {
141 9
            return $result[0][0];
142
        }
143
144 12
        $result = $result[0][0];
145 12
        foreach (explode('.', $path) as $key) {
146 12
            if (!isset($result[$key])) {
147 5
                return;
148
            }
149 9
            $result = $result[$key];
150 9
        }
151
152 7
        return $result;
153
    }
154
}
155