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

ListTubesCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 45
ccs 15
cts 17
cp 0.8824
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAction() 0 3 1
A getGroup() 0 3 1
A getResponseParser() 0 3 1
A parseResponse() 0 16 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