Completed
Push — master ( 59a424...016a1e )
by Charles
01:52
created

AbstractEvent   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handled() 0 6 1
A retry() 0 6 1
1
<?php
2
3
namespace yrc\events;
4
5
abstract class AbstractEvent extends \yii\base\Event
6
{
7
    protected $queue;
8
    protected $job;
9
10
    /**
11
     * Overloaded constructor
12
     * @param array $config
13
     * @param Disque\Queue $queue
14
     * @param Disque\Queue\Job $job
15
     */
16
    public function __construct($config = [], \Disque\Queue\Queue $queue, \Disque\Queue\Job $job)
17
    {
18
        parent::__construct($config);
19
        $this->queue = $queue;
20
        $this->job = $job;
21
    }
22
23
    /**
24
     * Mark the event as handled, then tell the queue it's been handled
25
     * @return true
26
     */
27
    public function handled()
28
    {
29
        $this->handled = true;
30
        $this->queue->processed($this->job);
31
        return true;
32
    }
33
    
34
    /**
35
     * Requeue the event
36
     * @return true
37
     */
38
    public function retry()
39
    {
40
        $this->handled = true;
41
        $this->queue->failed($this->job);
42
        return true;
43
    }
44
}