CreateCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 59
ccs 16
cts 16
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A parseResponse() 0 4 1
A getAction() 0 3 1
A getGroup() 0 3 1
A getFilters() 0 7 1
A __construct() 0 3 1
A getResponseParser() 0 3 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