Completed
Push — master ( 0c14ec...48a895 )
by Nicolas
04:31 queued 02:03
created

WorkerContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 8
c 2
b 1
f 0
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Puzzle\AMQP\Workers;
4
5
use Psr\Log\LoggerAwareTrait;
6
use Puzzle\AMQP\Consumer;
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\NullLogger;
9
10
class WorkerContext
11
{
12
    use LoggerAwareTrait;
13
14
    private
15
        $queueName,
16
        $description,
17
        $consumer,
18
        $worker;
19
20 4
    public function __construct(\Closure $worker, Consumer $consumer, $queueName)
21
    {
22 4
        $this->worker = $worker;
23 4
        $this->consumer = $consumer;
24 4
        $this->queueName = $queueName;
25 4
        $this->description = null;
26 4
        $this->logger = new NullLogger();
27 4
    }
28
29 1
    public function getWorker()
30
    {
31 1
        if($this->worker instanceof \Closure)
32 1
        {
33 1
            $closure = $this->worker;
34 1
            $this->worker = $closure();
35 1
            $this->worker->setLogger($this->logger);
36 1
        }
37
38 1
        return $this->worker;
39
    }
40
41
    public function setLogger(LoggerInterface $logger)
42
    {
43
        $this->logger = $logger;
44
        $this->consumer->setLogger($logger);
45
46
        return $this;
47
    }
48
49 1
    public function getLogger()
50
    {
51 1
        return $this->logger;
52
    }
53
54
    public function getConsumer()
55
    {
56
        return $this->consumer;
57
    }
58
59 1
    public function setDescription($description)
60
    {
61 1
        $this->description = $description;
62
63 1
        return $this;
64
    }
65
66 2
    public function getDescription()
67
    {
68 2
        return $this->description;
69
    }
70
71 3
    public function getQueueName()
72
    {
73 3
        return $this->queueName;
74
    }
75
}
76