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

WorkflowExistsCommand::parseResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 6
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Pheanstalk\Command;
4
5
use Pheanstalk\Structure\Workflow;
6
7
/**
8
 * The 'WorkflowExists' command.
9
 *
10
 * Retrieve a workflow by its name, if there is no workflow named after the arg given in the construct, returns false
11
 *
12
 * @author  Valentin Corre
13
 * @package Pheanstalk
14
 * @license http://www.opensource.org/licenses/mit-license.php
15
 */
16
class WorkflowExistsCommand extends ListWorkflowsCommand
17
{
18
19
    /** @var string $name */
20
    private $name;
21
22
    /**
23
     * WorkflowExistsCommand constructor.
24
     *
25
     * @param string $name
26
     */
27 1
    public function __construct(string $name)
28
    {
29 1
        $this->name = $name;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35
    public function getResponseParser()
36
    {
37
        return $this;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function parseResponse($responseLine, $responseData)
44
    {
45
46
        $workflows = parent::parseResponse($responseLine, $responseData);
47
48
        $name = $this->name;
49
        $matchingWorkflows = $workflows->filter(function(Workflow $workflow) use ($name) {
1 ignored issue
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
50
            return $workflow->getName() === $name;
51
        });
52
53
        return !$matchingWorkflows->isEmpty() ? $matchingWorkflows->first() : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return ! $matchingWorkfl...kflows->first() : false also could return the type false which is incompatible with the return type mandated by Pheanstalk\ResponseParser::parseResponse() of Pheanstalk\Response.
Loading history...
54
    }
55
}
56