Completed
Push — master ( 820d65...c97c2d )
by Valentin
03:28
created

ListWorkflowsCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 45
ccs 15
cts 17
cp 0.8824
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponseParser() 0 3 1
A getGroup() 0 3 1
A parseResponse() 0 15 2
A getAction() 0 3 1
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 1
    public function getGroup(): string
28
    {
29 1
        return 'workflows';
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35 1
    public function getAction(): string
36
    {
37 1
        return 'list';
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function getResponseParser()
44
    {
45
        return $this;
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51 1
    public function parseResponse($responseLine, $responseData)
52
    {
53 1
        $workflows = [];
54 1
        foreach ($responseData['workflow'] as $workflow) {
55 1
            $workflow = $workflow['@attributes'] ?? $workflow;
56 1
            $object = new Workflow($workflow['name'], $workflow['group'], new ArrayCollection([]), $workflow['comment']);
57
            $object
58 1
                ->setId($workflow['id'])
59 1
                ->setBoundToSchedule((int) $workflow['bound-to-schedule'])
60 1
                ->setLastcommit((int) $workflow['lastcommit'])
61 1
                ->setModified((int) $workflow['modified'])
62
            ;
63 1
            $workflows[] = $object;
64
        }
65 1
        return new ArrayCollection($workflows);
66
    }
67
}
68