CreateScheduleCommand::getAction()   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 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Pheanstalk\Command;
4
5
use Pheanstalk\ResponseParser;
6
use Pheanstalk\Structure\Schedule;
7
use Pheanstalk\Structure\TimeSchedule;
8
use Pheanstalk\Structure\Workflow;
9
10
/**
11
 * The 'CreateSchedule' command.
12
 *
13
 * Inserts a new workflow_schedule into the client.
14
 *
15
 *
16
 * @author  Valentin Corre
17
 * @package Pheanstalk
18
 * @license http://www.opensource.org/licenses/mit-license.php
19
 */
20
class CreateScheduleCommand extends AbstractCommand implements ResponseParser
21
{
22
23
    const FAILURE_TYPE_CONTINUE = "CONTINUE";
24
    const FAILURE_TYPE_SUSPEND = "SUSPEND";
25
26
    /** @var Schedule $schedule */
27
    private $schedule;
28
29
30
    /**
31
     * CreateScheduleCommand constructor.
32
     *
33
     * @param Schedule     $schedule
34
     */
35 1
    public function __construct(Schedule $schedule)
36
    {
37 1
        $this->schedule = $schedule;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 1
    public function getGroup(): string
44
    {
45 1
        return 'workflow_schedule';
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51 1
    public function getAction(): string
52
    {
53 1
        return 'create';
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59 1
    public function getFilters(): array
60
    {
61
        return[
62 1
            'workflow_id' => $this->schedule->getWorkflow(),
63 1
            'schedule' => $this->schedule->getSchedule()->__toString(),
64 1
            "onfailure" => $this->schedule->getOnFailure(),
65 1
            'active' => $this->schedule->isActive(),
66 1
            'comment' => $this->schedule->getComment(),
67 1
            'node' => $this->schedule->getNode()
68
        ];
69
    }
70
71
    /**
72
     * @inheritDoc
73
     */
74 1
    public function getResponseParser()
75
    {
76 1
        return $this;
77
    }
78
79
    /**
80
     * @inheritDoc
81
     */
82 1
    public function parseResponse($responseLine, $responseData)
83
    {
84 1
        $this->schedule->setId((int) $responseData['@attributes']['schedule-id']);
85 1
        return $this->schedule;
86
    }
87
}
88