WorkflowExistsCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 2
b 0
f 0
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getResponseParser() 0 3 1
A parseResponse() 0 11 2
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