Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractAdapter
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
7 / 7
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 setPriority
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getPriority
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isFifo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isFilo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isLilo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isLifo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 push
n/a
0 / 0
n/a
0 / 0
0
 reserve
n/a
0 / 0
n/a
0 / 0
0
 release
n/a
0 / 0
n/a
0 / 0
0
 delete
n/a
0 / 0
n/a
0 / 0
0
 bury
n/a
0 / 0
n/a
0 / 0
0
 hasJobs
n/a
0 / 0
n/a
0 / 0
0
 count
n/a
0 / 0
n/a
0 / 0
0
 clear
n/a
0 / 0
n/a
0 / 0
0
 hasDeadJobs
n/a
0 / 0
n/a
0 / 0
0
 countDead
n/a
0 / 0
n/a
0 / 0
0
 getDeadJobs
n/a
0 / 0
n/a
0 / 0
0
 getDeadJob
n/a
0 / 0
n/a
0 / 0
0
 retryDeadJob
n/a
0 / 0
n/a
0 / 0
0
 deleteDeadJob
n/a
0 / 0
n/a
0 / 0
0
 clearDead
n/a
0 / 0
n/a
0 / 0
0
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Queue\Adapter;
16
17use Pop\Queue\Queue;
18use Pop\Queue\Process\AbstractJob;
19
20/**
21 * Adapter abstract class
22 *
23 * @category   Pop
24 * @package    Pop\Queue
25 * @author     Nick Sagona, III <nick@popphp.org>
26 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
27 * @license    https://www.popphp.org/license     New BSD License
28 * @version    3.0.0
29 */
30abstract class AbstractAdapter implements AdapterInterface
31{
32
33    /**
34     * Queue priority
35     * @var string
36     */
37    protected string $priority = 'FIFO';
38
39    /**
40     * Constructor
41     *
42     * @param ?string $priority
43     */
44    public function __construct(?string $priority = null)
45    {
46        if ($priority !== null) {
47            $this->setPriority($priority);
48        }
49    }
50
51    public function setPriority(string $priority = 'FIFO'): AbstractAdapter
52    {
53        if (defined('Pop\Queue\Queue::' . $priority)) {
54            $this->priority = $priority;
55        }
56        return $this;
57    }
58
59    public function getPriority(): string
60    {
61        return $this->priority;
62    }
63
64    public function isFifo(): bool
65    {
66        return ($this->priority == Queue::FIFO);
67    }
68
69    public function isFilo(): bool
70    {
71        return ($this->priority == Queue::FILO);
72    }
73
74    public function isLilo(): bool
75    {
76        return ($this->priority == Queue::FIFO);
77    }
78
79    public function isLifo(): bool
80    {
81        return ($this->priority == Queue::FILO);
82    }
83
84    abstract public function push(AbstractJob $job): AdapterInterface;
85
86    abstract public function reserve(): ?AbstractJob;
87
88    abstract public function release(AbstractJob $job, ?int $delay = null): AdapterInterface;
89
90    abstract public function delete(AbstractJob $job): AdapterInterface;
91
92    abstract public function bury(AbstractJob $job, ?string $reason = null): AdapterInterface;
93
94    abstract public function hasJobs(): bool;
95
96    abstract public function count(): int;
97
98    abstract public function clear(): AdapterInterface;
99
100    abstract public function hasDeadJobs(): bool;
101
102    abstract public function countDead(): int;
103
104    abstract public function getDeadJobs(bool $unserialize = true): array;
105
106    abstract public function getDeadJob(string $jobId, bool $unserialize = true): mixed;
107
108    abstract public function retryDeadJob(string $jobId): AdapterInterface;
109
110    abstract public function deleteDeadJob(string $jobId): AdapterInterface;
111
112    abstract public function clearDead(): AdapterInterface;
113
114}