JobQueue   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 110
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A push() 0 4 1
A pushUnique() 0 8 2
A bulk() 0 4 1
A later() 0 4 1
A laterUnique() 0 8 2
1
<?php
2
3
namespace SfCod\QueueBundle\Service;
4
5
use SfCod\QueueBundle\Base\JobQueueInterface;
6
7
/**
8
 * JobQueue service
9
 *
10
 * @author Virchenko Maksim <[email protected]>
11
 * @author Orlov Alexey <[email protected]>
12
 */
13
class JobQueue implements JobQueueInterface
14
{
15
    /**
16
     * QueueManager instance
17
     *
18
     * @var QueueManager
19
     */
20
    protected $manager;
21
22
    /**
23
     * JobQueue constructor.
24
     *
25
     * @param QueueManager $manager
26
     *
27
     * @internal param array $config
28
     */
29
    public function __construct(QueueManager $manager)
30
    {
31
        $this->manager = $manager;
32
    }
33
34
    /**
35
     * Push new job to queue
36
     *
37
     * @author Virchenko Maksim <[email protected]>
38
     *
39
     * @param string $job
40
     * @param array $data
41
     * @param string $queue
42
     * @param string $connection
43
     *
44
     * @return mixed
45
     */
46
    public function push(string $job, array $data = [], string $queue = 'default', string $connection = 'default')
47
    {
48
        return $this->manager->push($job, $data, $queue, $connection);
0 ignored issues
show
Documentation Bug introduced by
The method push does not exist on object<SfCod\QueueBundle\Service\QueueManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
49
    }
50
51
    /**
52
     * Push new job to queue if this job is not exist
53
     *
54
     * @author Virchenko Maksim <[email protected]>
55
     *
56
     * @param string $job
57
     * @param array $data
58
     * @param string $queue
59
     * @param string $connection
60
     *
61
     * @return mixed
62
     */
63
    public function pushUnique(string $job, array $data = [], string $queue = 'default', string $connection = 'default')
64
    {
65
        if (false === $this->manager->connection($connection)->exists($job, $data, $queue)) {
66
            return $this->manager->push($job, $data, $queue, $connection);
0 ignored issues
show
Documentation Bug introduced by
The method push does not exist on object<SfCod\QueueBundle\Service\QueueManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
67
        }
68
69
        return null;
70
    }
71
72
    /**
73
     * Push a new an array of jobs onto the queue.
74
     *
75
     * @param array $jobs
76
     * @param mixed $data
77
     * @param string $queue
78
     * @param string $connection
79
     *
80
     * @return mixed
81
     */
82
    public function bulk(array $jobs, array $data = [], string $queue = 'default', string $connection = 'default')
83
    {
84
        return $this->manager->bulk($jobs, $data, $queue, $connection);
0 ignored issues
show
Documentation Bug introduced by
The method bulk does not exist on object<SfCod\QueueBundle\Service\QueueManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
85
    }
86
87
    /**
88
     * Push a new job onto the queue after a delay.
89
     *
90
     * @param \DateInterval|int $delay
91
     * @param string $job
92
     * @param mixed $data
93
     * @param string $queue
94
     * @param string $connection
95
     *
96
     * @return mixed
97
     */
98
    public function later($delay, string $job, array $data = [], string $queue = 'default', string $connection = 'default')
99
    {
100
        return $this->manager->later($delay, $job, $data, $queue, $connection);
0 ignored issues
show
Documentation Bug introduced by
The method later does not exist on object<SfCod\QueueBundle\Service\QueueManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
101
    }
102
103
    /**
104
     * Push a new job into the queue after a delay if job does not exist.
105
     *
106
     * @param \DateInterval|int $delay
107
     * @param string $job
108
     * @param mixed $data
109
     * @param string $queue
110
     * @param string $connection
111
     *
112
     * @return mixed
113
     */
114
    public function laterUnique($delay, string $job, array $data = [], string $queue = 'default', string $connection = 'default')
115
    {
116
        if (false === $this->manager->connection($connection)->exists($job, $data, $queue)) {
117
            return $this->manager->later($delay, $job, $data, $queue, $connection);
0 ignored issues
show
Documentation Bug introduced by
The method later does not exist on object<SfCod\QueueBundle\Service\QueueManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
118
        }
119
120
        return null;
121
    }
122
}
123