Completed
Pull Request — master (#52)
by Ujjwal
08:48
created

QueueCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 65
c 1
b 0
f 0
wmc 6
lcom 0
cbo 2
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 3
A getCommand() 0 4 1
A getName() 0 4 1
A getQueueName() 0 4 1
1
<?php
2
3
namespace League\Tactician\Bernard;
4
5
use Bernard\Message\PlainMessage;
6
use Bernard\Util;
7
8
/**
9
 * Wraps any command to be queueable
10
 */
11
final class QueueCommand implements QueueableCommand
12
{
13
    /**
14
     * @var object
15
     */
16
    private $command;
17
18
    /**
19
     * @var string
20
     */
21
    private $name;
22
23
    /**
24 8
     * @var string
25
     */
26 8
    private $queueName;
27
28 8
    /**
29 5
     * @param object $command
30 5
     * @param string|null $name
31 5
     * @param string|null $queueName
32
     */
33 8
    public function __construct($command, $name = null, $queueName = null)
34 8
    {
35
        $this->command = $command;
36
37
        if (is_null($name)) {
38
            $className = get_class($command);
39
            $name = substr($className, strrpos($className, '\\') + 1);
40
        }
41 4
42
        if (null === $queueName) {
43 4
            $queueName = Util::guessQueue(new PlainMessage($name));
44
45
        }
46
        $this->name = $name;
47
        $this->queueName = $queueName;
48
    }
49 4
50
    /**
51 4
     * Returns the wrapped command
52
     *
53
     * @return object
54
     */
55
    public function getCommand()
56
    {
57
        return $this->command;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getName()
64
    {
65
        return $this->name;
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getQueueName(): string
72
    {
73
        return $this->queueName;
74
    }
75
}
76