Passed
Push — master ( dbe0e9...183c61 )
by Sergei
03:16
created

QueueDecorator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 17.65%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 14
c 2
b 0
f 0
dl 0
loc 50
rs 10
ccs 3
cts 17
cp 0.1765

8 Methods

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