Completed
Push — master ( 1fad07...9ffd04 )
by Vladimir
08:28
created

SyncAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 0 3 1
A push() 0 4 1
A later() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Queue\Adapters;
6
7
use FondBot\Queue\Adapter;
8
use FondBot\Drivers\Driver;
9
use FondBot\Drivers\Command;
10
use FondBot\Channels\Channel;
11
12
class SyncAdapter extends Adapter
13
{
14
    /**
15
     * Establish connection to the queue.
16
     */
17
    public function connect(): void
18
    {
19
    }
20
21
    /**
22
     * Push command onto the queue.
23
     *
24
     * @param Channel $channel
25
     * @param Driver  $driver
26
     * @param Command $command
27
     */
28 2
    public function push(Channel $channel, Driver $driver, Command $command): void
29
    {
30 2
        $driver->handle($command);
31 2
    }
32
33
    /**
34
     * Push command onto the queue with a delay.
35
     *
36
     * @param Channel $channel
37
     * @param Driver  $driver
38
     * @param Command $command
39
     * @param int     $delay
40
     *
41
     * @return mixed|void
42
     */
43 1
    public function later(Channel $channel, Driver $driver, Command $command, int $delay): void
44
    {
45 1
        if ($delay > 0) {
46 1
            sleep($delay);
47
        }
48
49 1
        $this->push($channel, $driver, $command);
50 1
    }
51
}
52