ListWorkflowsCommand::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 Doctrine\Common\Collections\ArrayCollection;
6
use Pheanstalk\ResponseParser;
7
use Pheanstalk\Structure\Workflow;
8
9
/**
10
 * The 'ListWorkflows' command.
11
 *
12
 * Inserts a new workflow into the client.
13
 *
14
 *
15
 * @author  Valentin Corre
16
 * @package Pheanstalk
17
 * @license http://www.opensource.org/licenses/mit-license.php
18
 */
19
class ListWorkflowsCommand extends AbstractCommand implements ResponseParser
20
{
21
22
    /**
23
     * @inheritDoc
24
     */
25 10
    public function getGroup(): string
26
    {
27 10
        return 'workflows';
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33 10
    public function getAction(): string
34
    {
35 10
        return 'list';
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41 3
    public function getResponseParser()
42
    {
43 3
        return $this;
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49 10
    public function parseResponse($responseLine, $responseData)
50
    {
51 10
        $workflows = [];
52 10
        if (isset($responseData['workflow'])) {
53 10
            foreach ($responseData['workflow'] as $workflow) {
54 10
                $workflow = $workflow['@attributes'] ?? $workflow;
55
                $object = new Workflow($workflow['name'], $workflow['group'], new ArrayCollection([]), $workflow['comment']);
56 10
                $object
57 10
                    ->setId($workflow['id'])
58 10
                    ->setBoundToSchedule((int) $workflow['bound-to-schedule'])
59 10
                    ->setLastcommit((int) $workflow['lastcommit'])
60
                    ->setModified((int) $workflow['modified'])
61 10
                ;
62
                $workflows[] = $object;
63 10
            }
64
        }
65
        return new ArrayCollection($workflows);
66
    }
67
}
68