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

UpdateCommand::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 Pheanstalk\Exception;
6
use Pheanstalk\Response;
7
use Pheanstalk\Structure\Workflow;
8
9
/**
10
 * The 'update' command.
11
 *
12
 * Update an existing job.
13
 *
14
 * @author  Valentin Corre
15
 * @package Pheanstalk
16
 * @license http://www.opensource.org/licenses/mit-license.php
17
 */
18
class UpdateCommand extends AbstractCommand implements \Pheanstalk\ResponseParser
19
{
20
    /** @var Workflow $workflow */
21
    private $workflow;
22
23
    /**
24
     * @param Workflow $workflow
25
     */
26
    public function __construct(Workflow $workflow)
27
    {
28
        $this->workflow = $workflow;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function getGroup(): string
35
    {
36
        return 'workflow';
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public function getAction(): string
43
    {
44
        return 'edit';
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function getFilters(): array
51
    {
52
        return [
53
            'id' => $this->workflow->getId(),
54
            'name' => $this->workflow->getName(),
55
            "group" => $this->workflow->getGroup(),
56
            'content' => base64_encode($this->workflow->getXml()->saveXML()),
57
            'comment' => $this->workflow->getComment()
58
        ];
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function getResponseParser()
65
    {
66
        return $this;
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function parseResponse($responseLine, $responseData)
73
    {
74
        return $this->workflow;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->workflow returns the type Pheanstalk\Structure\Workflow 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...
75
    }
76
}
77