TubeExistsCommand::parseResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Pheanstalk\Command;
4
5
use Pheanstalk\Structure\Tube;
6
7
/**
8
 * The 'TubeExists' command.
9
 *
10
 * Retrieve a tube by its name, if there is no tube 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 TubeExistsCommand extends ListTubesCommand
17
{
18
19
    /** @var string $name */
20
    private $name;
21
22
    /**
23
     * TubeExistsCommand constructor.
24
     *
25
     * @param string $name
26
     */
27 9
    public function __construct(string $name)
28
    {
29 9
        $this->name = $name;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35 9
    public function getResponseParser()
36
    {
37 9
        return $this;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 9
    public function parseResponse($responseLine, $responseData)
44
    {
45
46 9
        $tubes = parent::parseResponse($responseLine, $responseData);
47
48 9
        $name = $this->name;
49
        $matchingTubes = $tubes->filter(function (Tube $tube) use ($name) {
50 9
            return $tube->getName() === $name;
51 9
        });
52
53 9
        return !$matchingTubes->isEmpty() ? $matchingTubes->first() : false;
54
    }
55
}
56