AbstractHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setId() 0 4 1
A setBody() 0 4 1
A run() 0 13 2
A setUp() 0 1 1
A tearDown() 0 1 1
perform() 0 1 ?
1
<?php
2
3
namespace DelayQueue\Handler;
4
5
use DelayQueue\Container\ContainerAwareTrait;
6
use Exception;
7
8
/**
9
 * Job处理抽象类
10
 *
11
 * Class AbstractHandler
12
 * @package DelayQueue\Handler
13
 */
14
abstract class AbstractHandler implements HandlerInterface
15
{
16
    use ContainerAwareTrait;
17
18
    /**
19
     * @var string Job唯一标识
20
     */
21
    protected $id;
22
23
    /**
24
     * @var array
25
     */
26
    protected $body;
27
28
    /**
29
     * @param string $id
30
     */
31
    public function setId($id)
32
    {
33
        $this->id = $id;
34
    }
35
36
    /**
37
     * @param array $body
38
     */
39
    public function setBody(array $body)
40
    {
41
        $this->body = $body;
42
    }
43
44
    public function run()
45
    {
46
        $this->setUp();
47
48
        try {
49
            $this->perform();
50
            $this->delayQueue->finish($this->id);
51
        } catch (Exception $exception) {
52
            $this->logger->warning(sprintf('Job execution failed %s', $exception->getMessage()));
53
        }
54
55
        $this->tearDown();
56
    }
57
58
    protected function setUp() { }
59
60
    protected function tearDown() { }
61
62
    abstract protected function perform();
63
}