Passed
Pull Request — master (#464)
by Kirill
06:05
created

Options::withDelay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Jobs;
6
7
use Spiral\RoadRunner\Jobs\Options as RoadRunnerOptions;
8
use Spiral\RoadRunner\Jobs\OptionsInterface;
9
10
/**
11
 * @deprecated Since 2.9. Please use {@see RoadRunnerOptions} instead.
12
 */
13
class Options implements OptionsInterface, \JsonSerializable
14
{
15
    /**
16
     * @var OptionsInterface
17
     */
18
    private OptionsInterface $base;
19
20
    /**
21
     * Options constructor
22
     */
23
    public function __construct()
24
    {
25
        $this->base = new RoadRunnerOptions();
26
    }
27
28
    /**
29
     * @var string|null
30
     */
31
    private ?string $pipeline = null;
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function getDelay(): int
37
    {
38
        return $this->base->getDelay();
39
    }
40
41
    /**
42
     * @param int|null $delay
43
     * @return $this
44
     */
45
    public function withDelay(?int $delay): self
46
    {
47
        $options = clone $this;
48
        $options->base = $options->base->withDelay($delay ?? 0);
49
50
        return $options;
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56
    public function getPriority(): int
57
    {
58
        return $this->base->getPriority();
59
    }
60
61
    /**
62
     * @return string|null
63
     */
64
    public function getPipeline(): ?string
65
    {
66
        return $this->pipeline;
67
    }
68
69
    /**
70
     * @param string|null $pipeline
71
     * @return self
72
     */
73
    public function withPipeline(?string $pipeline): self
74
    {
75
        $options = clone $this;
76
        $options->pipeline = $pipeline;
77
78
        return $options;
79
    }
80
81
    /**
82
     * @return array
83
     */
84
    public function jsonSerialize(): array
85
    {
86
        return [
87
            'delay'    => $this->base->delay ?: null,
0 ignored issues
show
Bug introduced by
Accessing delay on the interface Spiral\RoadRunner\Jobs\OptionsInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
88
            'pipeline' => $this->pipeline
89
        ];
90
    }
91
92
    /**
93
     * @param positive-int|0 $delay
0 ignored issues
show
Documentation Bug introduced by
The doc comment positive-int|0 at position 0 could not be parsed: Unknown type name 'positive-int' at position 0 in positive-int|0.
Loading history...
94
     * @return Options
95
     */
96
    public static function delayed(int $delay): self
97
    {
98
        $options = new self();
99
        $options->base = $options->base->withDelay($delay);
100
101
        return $options;
102
    }
103
}
104