GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MnsAdapter   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 16
eloc 34
dl 0
loc 160
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 3 1
A listQueue() 0 7 2
A listQueueAsync() 0 7 2
A deleteQueueAsync() 0 5 2
A deleteQueue() 0 7 2
A __construct() 0 5 1
A createQueueAsync() 0 6 2
A useQueue() 0 7 2
A createQueue() 0 8 2
1
<?php
2
3
/*
4
 * Laravel-Mns -- 阿里云消息队列(MNS)的 Laravel 适配。
5
 *
6
 * This file is part of the milkmeowo/laravel-mns.
7
 *
8
 * (c) Milkmeowo <[email protected]>
9
 * @link: https://github.com/milkmeowo/laravel-queue-aliyun-mns
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace Milkmeowo\LaravelMns\Adaptors;
16
17
use AliyunMNS\Queue;
18
use AliyunMNS\AsyncCallback;
19
use AliyunMNS\Client as MnsClient;
20
use AliyunMNS\Responses\MnsPromise;
21
use AliyunMNS\Model\QueueAttributes;
22
use AliyunMNS\Exception\MnsException;
23
use AliyunMNS\Requests\ListQueueRequest;
24
use AliyunMNS\Requests\CreateQueueRequest;
25
use AliyunMNS\Requests\SendMessageRequest;
26
use AliyunMNS\Responses\PeekMessageResponse;
27
use AliyunMNS\Responses\SendMessageResponse;
28
use AliyunMNS\Requests\BatchPeekMessageRequest;
29
use AliyunMNS\Requests\BatchSendMessageRequest;
30
use AliyunMNS\Responses\ReceiveMessageResponse;
31
use AliyunMNS\Requests\BatchDeleteMessageRequest;
32
use AliyunMNS\Responses\BatchPeekMessageResponse;
33
use AliyunMNS\Responses\BatchSendMessageResponse;
34
use AliyunMNS\Requests\BatchReceiveMessageRequest;
35
use AliyunMNS\Responses\GetQueueAttributeResponse;
36
use AliyunMNS\Responses\SetQueueAttributeResponse;
37
use AliyunMNS\Responses\BatchDeleteMessageResponse;
38
use AliyunMNS\Responses\BatchReceiveMessageResponse;
39
use AliyunMNS\Responses\ChangeMessageVisibilityResponse;
40
41
/**
42
 * Class MNSAdapter.
43
 *
44
 * @method string getQueueName()
45
 * @method SetQueueAttributeResponse setAttribute(QueueAttributes $attributes)
46
 * @method MnsPromise setAttributeAsync(QueueAttributes $attributes, AsyncCallback $callback = null)
47
 * @method GetQueueAttributeResponse getAttribute()
48
 * @method MnsPromise getAttributeAsync(AsyncCallback $callback = null)
49
 * @method SendMessageResponse sendMessage(SendMessageRequest $request)
50
 * @method MnsPromise sendMessageAsync(SendMessageRequest $request, AsyncCallback $callback = null)
51
 * @method PeekMessageResponse peekMessage()
52
 * @method MnsPromise peekMessageAsync(AsyncCallback $callback = null)
53
 * @method ReceiveMessageResponse receiveMessage(int $waitSeconds = null)
54
 * @method MnsPromise receiveMessageAsync(AsyncCallback $callback = null)
55
 * @method ReceiveMessageResponse deleteMessage(string $receiptHandle)
56
 * @method MnsPromise deleteMessageAsync(string $receiptHandle, AsyncCallback $callback = null)
57
 * @method ChangeMessageVisibilityResponse changeMessageVisibility(string $receiptHandle, int $visibilityTimeout)
58
 * @method BatchSendMessageResponse batchSendMessage(BatchSendMessageRequest $request)
59
 * @method MnsPromise batchSendMessageAsync(BatchSendMessageRequest $request, AsyncCallback $callback = null)
60
 * @method BatchReceiveMessageResponse batchReceiveMessage(BatchReceiveMessageRequest $request)
61
 * @method MnsPromise batchReceiveMessageAsync(BatchReceiveMessageRequest $request, AsyncCallback $callback = null)
62
 * @method BatchPeekMessageResponse batchPeekMessage(BatchPeekMessageRequest $request)
63
 * @method MnsPromise batchPeekMessageAsync(BatchPeekMessageRequest $request, AsyncCallback $callback = null)
64
 * @method BatchDeleteMessageResponse batchDeleteMessage(BatchDeleteMessageRequest $request)
65
 * @method MnsPromise batchDeleteMessageAsync(BatchDeleteMessageRequest $request, AsyncCallback $callback = null)
66
 */
67
class MnsAdapter
68
{
69
    /**
70
     * @var string 适配的阿里云消息服务 SDK 版本,仅用作记录。
71
     *
72
     * @see https://help.aliyun.com/document_detail/32381.html
73
     */
74
    const ADAPTER_TO_ALIYUN_MNS_SDK_VERSION = '1.3.5@2017-06-06';
75
    /**
76
     * Aliyun MNS Client.
77
     *
78
     * @var MnsClient
79
     */
80
    private $client;
81
    /**
82
     * Aliyun MNS SDK Queue.
83
     *
84
     * @var Queue
85
     */
86
    private $queue;
87
88
    /**
89
     * MnsAdapter constructor.
90
     *
91
     * @param MnsClient $client
92
     * @param string    $queue
93
     */
94
    public function __construct(MnsClient $client, string $queue)
95
    {
96
        $this->client = $client;
97
98
        $this->useQueue($queue);
99
    }
100
101
    /**
102
     * 转化 \AliyunMNS\Client 对象,
103
     * 可以通过本对象直接访问(而无需通过 \AliyunMNS\Client 对象构建)。
104
     *
105
     * @param $method
106
     * @param $parameters
107
     *
108
     * @return mixed
109
     */
110
    public function __call($method, $parameters)
111
    {
112
        return call_user_func_array([$this->queue, $method], $parameters);
113
    }
114
115
    /**
116
     * 将队列设定为特定队列。
117
     *
118
     * @param string $queue
119
     *
120
     * @return self
121
     */
122
    public function useQueue($queue)
123
    {
124
        if (null != $queue) {
125
            $this->queue = $this->client->getQueueRef($queue);
126
        }
127
128
        return $this;
129
    }
130
131
    /**
132
     * 创建队列.
133
     *
134
     * @param string $queueName 队列名
135
     */
136
    public function createQueue($queueName)
137
    {
138
        try {
139
            $request = new CreateQueueRequest($queueName);
140
            $response = $this->client->createQueue($request);
141
142
            return $response->isSucceed();
143
        } catch (MnsException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
144
        }
145
    }
146
147
    /**
148
     * 异步创建队列.
149
     *
150
     * @param string             $queueName 队列名
151
     * @param AsyncCallback|null $callback  异步回调
152
     */
153
    public function createQueueAsync($queueName, AsyncCallback $callback = null)
154
    {
155
        try {
156
            $request = new CreateQueueRequest($queueName);
157
            $this->client->createQueueAsync($request, $callback);
158
        } catch (MnsException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
159
        }
160
    }
161
162
    /**
163
     * 获取队列列表.
164
     *
165
     * @param null $retNum 单次请求结果的最大返回个数,可以取1-1000范围内的整数值,默认值为1000。
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $retNum is correct as it would always require null to be passed?
Loading history...
166
     * @param null $prefix 按照该前缀开头的 queueName 进行查找。
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $prefix is correct as it would always require null to be passed?
Loading history...
167
     * @param null $marker 请求下一个分页的开始位置,一般从上次分页结果返回的NextMarker获取。
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $marker is correct as it would always require null to be passed?
Loading history...
168
     *
169
     * @return \AliyunMNS\Responses\ListQueueResponse
170
     */
171
    public function listQueue($retNum = null, $prefix = null, $marker = null)
172
    {
173
        try {
174
            $request = new ListQueueRequest($retNum, $prefix, $marker);
175
176
            return $this->client->listQueue($request);
177
        } catch (MnsException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
178
        }
179
    }
180
181
    /**
182
     * 获取队列列表.
183
     *
184
     * @param int                $retNum   单次请求结果的最大返回个数,可以取1-1000范围内的整数值,默认值为1000。
185
     * @param string             $prefix   按照该前缀开头的 queueName 进行查找。
186
     * @param string             $marker   请求下一个分页的开始位置,一般从上次分页结果返回的NextMarker获取。
187
     * @param AsyncCallback|null $callback
188
     *
189
     * @return mixed
190
     */
191
    public function listQueueAsync($retNum = null, $prefix = null, $marker = null, AsyncCallback $callback = null)
192
    {
193
        try {
194
            $request = new ListQueueRequest($retNum, $prefix, $marker);
195
196
            return $this->client->listQueueAsync($request, $callback);
197
        } catch (MnsException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
198
        }
199
    }
200
201
    /**
202
     * 删除队列.
203
     *
204
     * @param string $queueName 队列名
205
     */
206
    public function deleteQueue($queueName)
207
    {
208
        try {
209
            $response = $this->client->deleteQueue($queueName);
210
211
            return $response->isSucceed();
212
        } catch (MnsException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
213
        }
214
    }
215
216
    /**
217
     * 异步删除队列.
218
     *
219
     * @param string             $queueName 队列名
220
     * @param AsyncCallback|null $callback
221
     */
222
    public function deleteQueueAsync($queueName, AsyncCallback $callback = null)
223
    {
224
        try {
225
            $this->client->deleteQueueAsync($queueName, $callback);
226
        } catch (MnsException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
227
        }
228
    }
229
}
230