Beanstalk   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A putJob() 0 15 2
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