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

TubeExistsCommand::getResponseParser()   A

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 0
Metric Value
eloc 1
c 0
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\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 1
    public function __construct(string $name)
28
    {
29 1
        $this->name = $name;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35 1
    public function getResponseParser()
36
    {
37 1
        return $this;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 1
    public function parseResponse($responseLine, $responseData)
44
    {
45
46 1
        $tubes = parent::parseResponse($responseLine, $responseData);
47
48 1
        $name = $this->name;
49
        $matchingTubes = $tubes->filter(function(Tube $tube) use ($name) {
1 ignored issue
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
50 1
            return $tube->getName() === $name;
51 1
        });
52
53 1
        return !$matchingTubes->isEmpty() ? $matchingTubes->first() : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return ! $matchingTubes-...gTubes->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