Passed
Push — master ( a2340d...9d7d2b )
by butschster
06:32
created

SyncDriver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Queue\Driver;
6
7
use Ramsey\Uuid\Uuid;
8
use Spiral\Queue\Interceptor\Consume\Handler;
9
use Spiral\Queue\OptionsInterface;
10
use Spiral\Queue\QueueInterface;
11
use Spiral\Queue\QueueTrait;
12
13
/**
14
 * Runs all the jobs in the same process.
15
 */
16
final class SyncDriver implements QueueInterface
17
{
18
    use QueueTrait;
19
20 3
    public function __construct(
21
        private readonly Handler $coreHandler
22
    ) {
23 3
    }
24
25
    /** @inheritdoc */
26 2
    public function push(string $name, array $payload = [], OptionsInterface $options = null): string
27
    {
28 2
        if ($options !== null && $options->getDelay()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $options->getDelay() of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
29
            \sleep($options->getDelay());
30
        }
31
32 2
        $id = (string)Uuid::uuid4();
33
34 2
        $this->coreHandler->handle(
35 2
            name: $name,
36 2
            driver: 'sync',
37 2
            queue: 'default',
38 2
            id: $id,
39 2
            payload: $payload
40 2
        );
41
42 2
        return $id;
43
    }
44
}
45