Completed
Branch master (450f26)
by Valentin
01:46
created

ListWorkflowsCommand::parseResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

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