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

ListTubesCommand::getResponseParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Pheanstalk\Command;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Pheanstalk\Structure\Tube;
7
use Pheanstalk\XmlResponseParser;
8
use Pheanstalk\YamlResponseParser;
9
10
/**
11
 * The 'list-tubes' command.
12
 *
13
 * List all existing tubes.
14
 *
15
 * @author  Paul Annesley
16
 * @package Pheanstalk
17
 * @license http://www.opensource.org/licenses/mit-license.php
18
 */
19
class ListTubesCommand extends AbstractCommand implements \Pheanstalk\ResponseParser
20
{
21
    /**
22
     * @inheritDoc
23
     */
24 1
    public function getGroup(): string
25
    {
26 1
        return 'queuepool';
27
    }
28
29
    /**
30
     * @inheritDoc
31
     */
32 1
    public function getAction(): string
33
    {
34 1
        return 'list';
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40
    public function getResponseParser()
41
    {
42
        return $this;
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48 1
    public function parseResponse($responseLine, $responseData)
49
    {
50 1
        $responseData = $responseData['queue'];
51 1
        $queues = [];
52 1
        foreach ($responseData as $queue) {
53 1
            $queue = $queue['@attributes'] ?? $queue;
54 1
            $queueObject = new Tube($queue['name'], $queue['concurrency']);
55
            $queueObject
56 1
                ->setId($queue['id'])
57 1
                ->setDynamic($queue['dynamic'])
58 1
                ->setScheduler($queue['scheduler'])
59
            ;
60 1
            $queues[] = $queueObject;
61
        }
62
63 1
        return new ArrayCollection($queues);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Doctrine\Comm...rrayCollection($queues) returns the type Doctrine\Common\Collections\ArrayCollection which is incompatible with the return type mandated by Pheanstalk\ResponseParser::parseResponse() of Pheanstalk\Response.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
64
    }
65
}
66