Passed
Push — master ( c86b81...7621ad )
by Valentin
04:59 queued 02:13
created

PheanstalkLocator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 64
ccs 15
cts 15
cp 1
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPheanstalk() 0 9 3
A getPheanstalks() 0 3 1
A __construct() 0 3 1
A getDefaultPheanstalk() 0 3 1
A addPheanstalk() 0 7 2
1
<?php
2
3
namespace Pyrowman\PheanstalkBundle;
4
5
use Pheanstalk\PheanstalkInterface;
6
7
class PheanstalkLocator
8
{
9
    /**
10
     * @var PheanstalkInterface[]
11
     */
12
    private $pheanstalks;
13
14
    /**
15
     * @var string
16
     */
17
    private $default;
18
19
    /**
20
     * Constructor.
21
     */
22 5
    public function __construct()
23
    {
24 5
        $this->pheanstalks = [];
25
    }
26
27
    /**
28
     * @return PheanstalkInterface[]
29
     */
30 4
    public function getPheanstalks()
31
    {
32 4
        return $this->pheanstalks;
33
    }
34
35
    /**
36
     * @param string $name
37
     *
38
     * @return PheanstalkInterface
39
     */
40 4
    public function getPheanstalk($name = null)
41
    {
42 4
        $name = null !== $name ? $name : $this->default;
43
44 4
        if (array_key_exists($name, $this->pheanstalks)) {
45 3
            return $this->pheanstalks[$name];
46
        }
47
48 1
        return;
49
    }
50
51
    /**
52
     * @return array
53
     */
54 3
    public function getDefaultPheanstalk()
55
    {
56 3
        return $this->getPheanstalk();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getPheanstalk() returns the type Pheanstalk\PheanstalkInterface which is incompatible with the documented return type array.
Loading history...
57
    }
58
59
    /**
60
     * @param string              $name
61
     * @param PheanstalkInterface $pheanstalk
62
     * @param bool                $default
63
     */
64 4
    public function addPheanstalk($name, PheanstalkInterface $pheanstalk, bool $default = false)
65
    {
66 4
        $this->pheanstalks[$name] = $pheanstalk;
67
68
        // Set the default connection name
69 4
        if ($default) {
70 3
            $this->default = $name;
71
        }
72
    }
73
}
74