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.

MnsQueue   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
eloc 29
dl 0
loc 148
rs 10
c 0
b 0
f 0
ccs 34
cts 34
cp 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getQueue() 0 3 2
A getMns() 0 3 1
A size() 0 3 1
A pop() 0 11 3
A push() 0 5 1
A __construct() 0 5 1
A later() 0 11 1
A pushRaw() 0 9 1
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;
16
17
use Illuminate\Queue\Queue;
0 ignored issues
show
Bug introduced by
The type Illuminate\Queue\Queue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Milkmeowo\LaravelMns\Jobs\MnsJob;
19
use AliyunMNS\Requests\SendMessageRequest;
20
use Milkmeowo\LaravelMns\Adaptors\MnsAdapter;
21
use AliyunMNS\Exception\MessageNotExistException;
22
use Illuminate\Contracts\Queue\Queue as QueueContract;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Queue\Queue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
24
class MnsQueue extends Queue implements QueueContract
25
{
26
    /**
27
     * Mns 适配器.
28
     *
29
     * @var MnsAdapter
30
     */
31
    protected $adapter;
32
    /**
33
     * 默认队列.
34
     *
35
     * @var string
36
     */
37
    protected $default;
38
    /**
39
     * 等待秒数.
40
     *
41
     * @var null
42
     */
43
    private $waitSeconds;
44
45
    /**
46
     * MnsQueue 构造.
47
     *
48
     * @param MnsAdapter $adapter     Mns 适配器
49
     * @param int        $waitSeconds 等待秒数
50
     */
51 8
    public function __construct(MnsAdapter $adapter, int $waitSeconds = 0)
52
    {
53 8
        $this->adapter = $adapter;
54 8
        $this->default = $this->adapter->getQueueName();
55 8
        $this->waitSeconds = $waitSeconds;
0 ignored issues
show
Documentation Bug introduced by
It seems like $waitSeconds of type integer is incompatible with the declared type null of property $waitSeconds.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56 8
    }
57
58
    /**
59
     * 获取队列长度.
60
     *
61
     * @param null $queue
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $queue is correct as it would always require null to be passed?
Loading history...
62
     *
63
     * @throws \Exception
64
     *
65
     * @return int|void
66
     */
67 1
    public function size($queue = null)
68
    {
69 1
        throw new \Exception('The size method is not support for aliyun-mns');
70
    }
71
72
    /**
73
     * 推送新的 Job 进队列.
74
     *
75
     * @param string|object $job   任务
76
     * @param mixed         $data  数据
77
     * @param string        $queue 队列
78
     *
79
     * @return mixed
80
     */
81 1
    public function push($job, $data = '', $queue = null)
82
    {
83 1
        $payload = $this->createPayload($job, $data);
84
85 1
        return $this->pushRaw($payload, $queue);
86
    }
87
88
    /**
89
     * 推送 raw payload 进队列.
90
     *
91
     * @param string $payload 数据
92
     * @param string $queue   队列
93
     * @param array  $options 选项
94
     *
95
     * @return mixed
96
     */
97 1
    public function pushRaw($payload, $queue = null, array $options = [])
98
    {
99 1
        $message = new SendMessageRequest($payload);
100
101 1
        $queue = $this->getQueue($queue);
102
103 1
        $response = $this->adapter->useQueue($queue)->sendMessage($message);
104
105 1
        return $response->getMessageId();
106
    }
107
108
    /**
109
     *  获取默认队列名(如果当前队列名为 null)。
110
     *
111
     * @param $queue
112
     *
113
     * @return string
114
     */
115 6
    public function getQueue($queue)
116
    {
117 6
        return $queue ?: $this->default;
118
    }
119
120
    /**
121
     * 延迟推送 Job 进队列.
122
     *
123
     * @param \DateTimeInterface|\DateInterval|int $delay 延迟时间 秒
124
     * @param string|object                        $job   任务
125
     * @param mixed                                $data  数据
126
     * @param string                               $queue 队列
127
     *
128
     * @return mixed
129
     */
130 2
    public function later($delay, $job, $data = '', $queue = null)
131
    {
132 2
        $seconds = $this->secondsUntil($delay);
133 2
        $payload = $this->createPayload($job, $data);
134 2
        $queue = $this->getQueue($queue);
135
136 2
        $message = new SendMessageRequest($payload, $seconds);
137
138 2
        $response = $this->adapter->useQueue($queue)->sendMessage($message);
139
140 2
        return $response->getMessageId();
141
    }
142
143
    /**
144
     * 从队列弹出下一个 Job.
145
     *
146
     * @param string $queue 队列
147
     *
148
     * @return \Illuminate\Contracts\Queue\Job|null
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Queue\Job was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
149
     */
150 2
    public function pop($queue = null)
151
    {
152 2
        $queue = $this->getQueue($queue);
153
154
        try {
155 2
            $response = $this->adapter->useQueue($queue)->receiveMessage($this->waitSeconds);
156 1
        } catch (MessageNotExistException $e) {
157 1
            $response = null;
158
        }
159 2
        if ($response) {
160 1
            return new MnsJob($this->container, $this->adapter, $queue, $response);
161
        }
162 1
    }
163
164
    /**
165
     * 获取 Mns 适配器.
166
     *
167
     * @return MnsAdapter
168
     */
169 1
    public function getMns()
170
    {
171 1
        return $this->adapter;
172
    }
173
}
174