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

SyncDriver::push()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
ccs 11
cts 12
cp 0.9167
rs 9.9332
c 0
b 0
f 0
cc 3
nc 2
nop 3
crap 3.0052
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