Beanstalk::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace JCIT\jobqueue\components\jobQueues;
5
6
use Closure;
7
use JCIT\jobqueue\interfaces\JobFactoryInterface;
8
use JCIT\jobqueue\interfaces\JobInterface;
9
use JCIT\jobqueue\interfaces\JobQueueInterface;
10
use Pheanstalk\Connection;
11
use Pheanstalk\Contract\PheanstalkInterface;
12
use Pheanstalk\Pheanstalk;
13
14
class Beanstalk extends Pheanstalk implements JobQueueInterface
15
{
16 1
    public function __construct(
17
        Connection $connection,
18
        private JobFactoryInterface $jobFactory,
19
        private ?Closure $beforePut = null
20
    ) {
21 1
        parent::__construct($connection);
22 1
    }
23
24 1
    public function putJob(
25
        JobInterface $job,
26
        int $priority = PheanstalkInterface::DEFAULT_PRIORITY,
27
        int $delay = PheanstalkInterface::DEFAULT_DELAY,
28
        int $ttr = PheanstalkInterface::DEFAULT_TTR
29
    ): void {
30 1
        if (isset($this->beforePut)) {
31 1
            ($this->beforePut)($job);
32
        }
33
34 1
        $this->put(
35 1
            $this->jobFactory->saveToJson($job),
36
            $priority,
37
            $delay,
38
            $ttr
39
        );
40 1
    }
41
}
42