CreateCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Pheanstalk\Command;
4
5
use Pheanstalk\ResponseParser;
6
use Pheanstalk\Structure\Workflow;
7
8
/**
9
 * The 'Create' command.
10
 *
11
 * Inserts a new workflow into the client.
12
 *
13
 *
14
 * @author  Valentin Corre
15
 * @package Pheanstalk
16
 * @license http://www.opensource.org/licenses/mit-license.php
17
 */
18
class CreateCommand extends AbstractCommand implements ResponseParser
19
{
20
    /** @var Workflow $workflow */
21
    private $workflow;
22
23
    /**
24
     * Puts a job on the queue.
25
     *
26
     * @param Workflow    $workflow     The workflow to create
27
     */
28 6
    public function __construct(Workflow $workflow)
29
    {
30 6
        $this->workflow = $workflow;
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36 6
    public function getGroup(): string
37
    {
38 6
        return 'workflow';
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44 6
    public function getAction(): string
45
    {
46 6
        return 'create';
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52 6
    public function getFilters(): array
53
    {
54
        return [
55 6
            'name' => $this->workflow->getName(),
56 6
            "group" => $this->workflow->getGroup(),
57 6
            'content' => base64_encode($this->workflow->getXml()->saveXML()),
58 6
            'comment' => $this->workflow->getComment()
59
        ];
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65 6
    public function getResponseParser()
66
    {
67 6
        return $this;
68
    }
69
70
    /**
71
     * @inheritDoc
72
     */
73 6
    public function parseResponse($responseLine, $responseData)
74
    {
75 6
        $this->workflow->setId($responseData['@attributes']['workflow-id']);
76 6
        return $this->workflow;
77
    }
78
}
79