Passed
Pull Request — master (#190)
by Dmitriy
04:22 queued 01:36
created

QueueDecorator   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 55
ccs 22
cts 24
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A push() 0 7 1
A withChannelName() 0 5 1
A __construct() 0 4 1
A withAdapter() 0 3 1
A status() 0 6 1
A getChannelName() 0 3 1
A listen() 0 3 1
A run() 0 3 1
A getAdapter() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Queue\Debug;
6
7
use Yiisoft\Queue\Adapter\AdapterInterface;
8
use Yiisoft\Queue\Enum\JobStatus;
9
use Yiisoft\Queue\Message\MessageInterface;
10
use Yiisoft\Queue\Middleware\MiddlewareInterface;
11
use Yiisoft\Queue\QueueInterface;
12
13
final class QueueDecorator implements QueueInterface
14
{
15 9
    public function __construct(
16
        private QueueInterface $queue,
17
        private QueueCollector $collector,
18
    ) {
19 9
    }
20
21 1
    public function status(string|int $id): JobStatus
22
    {
23 1
        $result = $this->queue->status($id);
24 1
        $this->collector->collectStatus($id, $result);
25
26 1
        return $result;
27
    }
28
29 1
    public function push(
30
        MessageInterface $message,
31
        string|array|callable|MiddlewareInterface ...$middlewareDefinitions
32
    ): MessageInterface {
33 1
        $message = $this->queue->push($message, ...$middlewareDefinitions);
34 1
        $this->collector->collectPush($this->queue->getChannelName(), $message, ...$middlewareDefinitions);
35 1
        return $message;
36
    }
37
38 1
    public function run(int $max = 0): int
39
    {
40 1
        return $this->queue->run($max);
41
    }
42
43 1
    public function listen(): void
44
    {
45 1
        $this->queue->listen();
46
    }
47
48 2
    public function withAdapter(AdapterInterface $adapter): QueueInterface
49
    {
50 2
        return new self($this->queue->withAdapter($adapter), $this->collector);
51
    }
52
53 1
    public function getChannelName(): string
54
    {
55 1
        return $this->queue->getChannelName();
56
    }
57
58 2
    public function withChannelName(string $channel): QueueInterface
59
    {
60 2
        $new = clone $this;
61 2
        $new->queue = $this->queue->withChannelName($channel);
62 2
        return $new;
63
    }
64
65
    public function getAdapter(): ?AdapterInterface
66
    {
67
        return $this->queue->getAdapter();
68
    }
69
}
70