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

CreateCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 59
ccs 16
cts 16
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getAction() 0 3 1
A getGroup() 0 3 1
A getFilters() 0 7 1
A __construct() 0 3 1
A parseResponse() 0 4 1
A getResponseParser() 0 3 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