Passed
Push — master ( 4a6f0d...73b924 )
by Valentin
03:29
created

getResponseParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Pheanstalk\Command;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Pheanstalk\Structure\JobInstance;
7
use Pheanstalk\Structure\TaskInstance;
8
use Pheanstalk\Structure\Workflow;
9
use Pheanstalk\Structure\WorkflowInstance;
10
11
/**
12
 * The 'GetWorkflow' command.
13
 *
14
 * Retrieve a workflow by its id, if there is no workflow for the id given in the construct, returns false
15
 *
16
 * @author  Valentin Corre
17
 * @package Pheanstalk
18
 * @license http://www.opensource.org/licenses/mit-license.php
19
 */
20
class GetWorkflowInstancesDetailCommand extends GetWorkflowInstancesCommand
21
{
22
    /** @var WorkflowInstance $workflowInstance */
23
    private $workflowInstance;
24
25
    /**
26
     * GetWorkflowCommand constructor.
27
     *
28
     * @param Workflow $workflow
29
     */
30
    public function __construct(WorkflowInstance $workflowInstance)
31
    {
32
//        dump($workflowInstance);
33
        $this->workflowInstance = $workflowInstance;
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function getGroup(): string
40
    {
41
        return 'instance';
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47
    public function getAction(): string
48
    {
49
        return 'query';
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function getFilters(): array
56
    {
57
        $filters = [
58
            'id' => $this->workflowInstance->getId(),
59
        ];
60
61
        return $filters;
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67
    public function getResponseParser()
68
    {
69
        return $this;
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75
    public function parseResponse($responseLine, $responseData)
76
    {
77
78
        if (!(isset($responseData['workflow']))) {
79
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by Pheanstalk\ResponseParser::parseResponse() of Pheanstalk\Response.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
80
        }
81
82
        $subjobs = $responseData['workflow']['subjobs'];
83
        $jobInstances = new ArrayCollection([]);
84
        foreach ($subjobs as $subjob) {
85
            $taskInstances = new ArrayCollection([]);
86
            foreach ($subjob['tasks'] as $tasks) {
87
                $task = $tasks['@attributes'];
88
89
                if (isset($task['execution_time'])) {
90
                    $task['execution_time'] = new \DateTime($task['execution_time']);
91
                }
92
                foreach ($task as $key => $val) {
93
                    if (ctype_digit($val)) {
94
                        $task[$key] = (int) $task[$key];
95
                    }
96
                }
97
                $taskInstances[] = new TaskInstance($task);
98
            }
99
            $jobInstances[] = new JobInstance($taskInstances);
100
        }
101
        $this->workflowInstance->setJobInstances($jobInstances);
102
103
        return $this->workflowInstance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->workflowInstance returns the type Pheanstalk\Structure\WorkflowInstance which is incompatible with the return type mandated by Pheanstalk\ResponseParser::parseResponse() of Pheanstalk\Response.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
104
    }
105
}
106