KillCommand::getFilters()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Pheanstalk\Command;
4
5
use Pheanstalk\Exception\ServerException;
6
use Pheanstalk\Parser\RequestOkResponseParser;
7
use Pheanstalk\Structure\TaskInstance;
8
use Pheanstalk\Structure\WorkflowInstance;
9
10
/**
11
 * The 'Kill' command.
12
 *
13
 * Kills a running workflow instance
14
 *
15
 *
16
 * @author  Valentin Corre
17
 * @package Pheanstalk
18
 * @license http://www.opensource.org/licenses/mit-license.php
19
 */
20
class KillCommand extends AbstractCommand
21
{
22
23
    /** @var WorkflowInstance $workflowInstance */
24
    private $workflowInstance;
25
26
    /** @var TaskInstance $taskInstance */
27
    private $taskInstance;
28
29
    /**
30
     * Kills a running task instance
31
     *
32
     * @param WorkflowInstance $workflowInstance     The WorkflowInstance
33
     */
34 2
    public function __construct(WorkflowInstance $workflowInstance, TaskInstance $taskInstance)
35
    {
36 2
        $this->workflowInstance = $workflowInstance;
37 2
        $this->taskInstance = $taskInstance;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 2
    public function getGroup(): string
44
    {
45 2
        return 'instance';
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51 2
    public function getAction(): string
52
    {
53 2
        return 'killtask';
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59 2
    public function getFilters(): array
60
    {
61 2
        $pid = $this->taskInstance->getPid();
62 2
        if (empty($pid)) {
63 2
            throw new ServerException("Pid Should not be empty");
64
        }
65
        return [
66 1
            'id' => $this->workflowInstance->getId(),
67 1
            'pid' => $pid,
68
        ];
69
    }
70
71
    /**
72
     * @inheritDoc
73
     */
74 1
    public function getResponseParser()
75
    {
76 1
        return new RequestOkResponseParser();
77
    }
78
}
79