WorkflowExistsCommand::getResponseParser()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
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\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 8
    public function __construct(string $name)
28
    {
29 8
        $this->name = $name;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35 7
    public function getResponseParser()
36
    {
37 7
        return $this;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 7
    public function parseResponse($responseLine, $responseData)
44
    {
45
46 7
        $workflows = parent::parseResponse($responseLine, $responseData);
47
48 7
        $name = $this->name;
49
        $matchingWorkflows = $workflows->filter(function (Workflow $workflow) use ($name) {
50 7
            return $workflow->getName() === $name;
51 7
        });
52
53 7
        return !$matchingWorkflows->isEmpty() ? $matchingWorkflows->first() : false;
54
    }
55
}
56