PheanstalkLocator::getPheanstalk()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
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