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::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * Laravel-Mns -- 阿里云消息队列(MNS)的 Laravel 适配。
5
 *
6
 * This file is part of the abe/laravel-mns.
7
 *
8
 * (c) Abraham Greyson <[email protected]>
9
 * @link: https://github.com/abrahamgreyson/laravel-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 LaravelMns;
16
17
use AliyunMNS\Client as MnsClient;
18
19
/**
20
 * Class MnsAdapter.
21
 *
22
 * @method string getQueueName()
23
 * @method \AliyunMNS\Responses\SetQueueAttributeResponse setAttribute(\AliyunMNS\Model\QueueAttributes $attributes)
24
 * @method \AliyunMNS\Responses\MnsPromise setAttributeAsync(\AliyunMNS\Model\QueueAttributes $attributes, \AliyunMNS\AsyncCallback $callback = null)
25
 * @method \AliyunMNS\Responses\GetQueueAttributeResponse getAttribute(\AliyunMNS\Model\QueueAttributes $attributes)
26
 * @method \AliyunMNS\Responses\MnsPromise getAttributeAsync(\AliyunMNS\Model\QueueAttributes $attributes, \AliyunMNS\AsyncCallback $callback = null)
27
 * @method \AliyunMNS\Responses\SendMessageResponse sendMessage(\AliyunMNS\Requests\SendMessageRequest $request)
28
 * @method \AliyunMNS\Responses\MnsPromise sendMessageAsync(\AliyunMNS\Requests\SendMessageRequest $request, \AliyunMNS\AsyncCallback $callback = null)
29
 * @method \AliyunMNS\Responses\PeekMessageResponse peekMessage()
30
 * @method \AliyunMNS\Responses\MnsPromise peekMessageAsync(\AliyunMNS\AsyncCallback $callback = null)
31
 * @method \AliyunMNS\Responses\ReceiveMessageResponse receiveMessage()
32
 * @method \AliyunMNS\Responses\MnsPromise receiveMessageAsync(\AliyunMNS\AsyncCallback $callback = null)
33
 * @method \AliyunMNS\Responses\ReceiveMessageResponse deleteMessage(string $receiptHandle)
34
 * @method \AliyunMNS\Responses\MnsPromise deleteMessageAsync(string $receiptHandle, \AliyunMNS\AsyncCallback $callback = null)
35
 * @method \AliyunMNS\Responses\ChangeMessageVisibilityResponse changeMessageVisibility(string $receiptHandle, int $visibilityTimeout)
36
 * @method \AliyunMNS\Responses\BatchSendMessageResponse batchSendMessage(\AliyunMNS\Requests\BatchSendMessageRequest $request)
37
 * @method \AliyunMNS\Responses\MnsPromise batchSendMessageAsync(\AliyunMNS\Requests\BatchSendMessageRequest $request, \AliyunMNS\AsyncCallback $callback = null)
38
 * @method \AliyunMNS\Responses\BatchReceiveMessageResponse batchReceiveMessage(\AliyunMNS\Requests\BatchReceiveMessageRequest $request)
39
 * @method \AliyunMNS\Responses\MnsPromise batchReceiveMessageAsync(\AliyunMNS\Requests\BatchReceiveMessageRequest $request, \AliyunMNS\AsyncCallback $callback = null)
40
 * @method \AliyunMNS\Responses\BatchPeekMessageResponse batchPeekMessage(\AliyunMNS\Requests\BatchPeekMessageRequest $request)
41
 * @method \AliyunMNS\Responses\MnsPromise batchPeekMessageAsync(\AliyunMNS\Requests\BatchPeekMessageRequest $request, \AliyunMNS\AsyncCallback $callback = null)
42
 * @method \AliyunMNS\Responses\BatchDeleteMessageResponse batchDeleteMessage(\AliyunMNS\Requests\BatchDeleteMessageRequest $request)
43
 * @method \AliyunMNS\Responses\MnsPromise batchDeleteMessageAsync(\AliyunMNS\Requests\BatchDeleteMessageRequest $request, \AliyunMNS\AsyncCallback $callback = null)
44
 */
45
class MnsAdapter
46
{
47
    /**
48
     * @var string 适配的阿里云消息服务 SDK 版本,仅用作记录。
49
     *
50
     * @see https://help.aliyun.com/document_detail/mns/sdk/php-sdk.html
51
     */
52
    const ADAPTER_TO_ALIYUN_MNS_SDK_VERSION = '1.3.0@2016-02-25';
53
54
    /**
55
     * Aliyun MNS SDK Client.
56
     *
57
     * @var MnsClient
58
     */
59
    private $client;
60
61
    /**
62
     * Aliyun MNS SDK Queue.
63
     *
64
     * @var \AliyunMNS\Queue
65
     */
66
    private $queue;
67
68 8
    public function __construct(MnsClient $client, $queueName)
69
    {
70 8
        $this->client = $client;
71 8
        $this->setQueue($queueName);
72 8
    }
73
74
    /**
75
     * 转化 \AliyunMNS\Client 对象,
76
     * 可以通过本对象直接访问(而无需通过 \AliyunMNS\Client 对象构建)。
77
     *
78
     * @param $method
79
     * @param $parameters
80
     *
81
     * @return mixed
82
     */
83 7
    public function __call($method, $parameters)
84
    {
85 7
        return call_user_func_array([$this->queue, $method], $parameters);
86
    }
87
88
    /**
89
     * 将队列设定为特定队列。
90
     *
91
     * @param $queue
92
     *
93
     * @return self
94
     */
95 8
    public function setQueue($queue)
96
    {
97 8
        if (null !== $queue) {
98 8
            $this->queue = $this->client->getQueueRef($queue);
99 8
        }
100
101 8
        return $this;
102
    }
103
}
104