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

CreateCommand::getResponseParser()   A

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 Pheanstalk\Exception;
6
use Pheanstalk\Response;
7
use Pheanstalk\Structure\Workflow;
8
use Pheanstalk\XmlResponseParser;
9
10
/**
11
 * The 'Create' command.
12
 *
13
 * Inserts a new workflow into the client.
14
 *
15
 *
16
 * @author  Valentin Corre
17
 * @package Pheanstalk
18
 * @license http://www.opensource.org/licenses/mit-license.php
19
 */
20
class CreateCommand extends AbstractCommand implements \Pheanstalk\ResponseParser
21
{
22
    /** @var Workflow $workflow */
23
    private $workflow;
24
25
    /**
26
     * Puts a job on the queue.
27
     *
28
     * @param Workflow    $workflow     The workflow to create
29
     */
30 1
    public function __construct(Workflow $workflow)
31
    {
32 1
        $this->workflow = $workflow;
33
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38 1
    public function getGroup(): string
39
    {
40 1
        return 'workflow';
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46 1
    public function getAction(): string
47
    {
48 1
        return 'create';
49
    }
50
51
    /**
52
     * @inheritDoc
53
     */
54 1
    public function getFilters(): array
55
    {
56
        return [
57 1
            'name' => $this->workflow->getName(),
58 1
            "group" => $this->workflow->getGroup(),
59 1
            'content' => base64_encode($this->workflow->getXml()->saveXML()),
60 1
            'comment' => $this->workflow->getComment()
61
        ];
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67 1
    public function getResponseParser()
68
    {
69 1
        return $this;
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75 1
    public function parseResponse($responseLine, $responseData)
76
    {
77 1
        $this->workflow->setId($responseData['@attributes']['workflow-id']);
78 1
        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...
79
    }
80
}
81