MemcacheService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 58
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A setCloudEnvironment() 0 5 1
A getCloudEnvironment() 0 4 1
A credentials() 0 16 3
1
<?php
2
3
namespace Acquia\Cloud\Memcache;
4
5
use Acquia\Cloud\Environment\CloudEnvironment;
6
use Acquia\Cloud\Environment\CloudEnvironmentAware;
7
use Acquia\Cloud\Environment\CloudEnvironmentInterface;
8
9
class MemcacheService implements CloudEnvironmentAware, MemcacheServiceInterface
10
{
11
    /**
12
     * @var \Acquia\Cloud\Environment\CloudEnvironmentInterface
13
     */
14
    private $cloudEnvironment;
15
16
    /**
17
     * @param \Acquia\Cloud\Environment\CloudEnvironmentInterface $cloudEnvironment
18
     */
19 15
    public function __construct(CloudEnvironmentInterface $cloudEnvironment = null)
20
    {
21 15
        if ($cloudEnvironment === null) {
22 12
            $cloudEnvironment = new CloudEnvironment();
23 12
        }
24
25 15
        $this->setCloudEnvironment($cloudEnvironment);
26 15
    }
27
28
    /**
29
     * {@inheritDoc}
30
     *
31
     * @return \Acquia\Cloud\Memcache\MemcacheService
32
     */
33 15
    public function setCloudEnvironment(CloudEnvironmentInterface $cloudEnvironment)
34
    {
35 15
        $this->cloudEnvironment = $cloudEnvironment;
36 15
        return $this;
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 6
    public function getCloudEnvironment()
43
    {
44 6
        return $this->cloudEnvironment;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 9
    public function credentials()
51
    {
52 9
        $creds = $this->cloudEnvironment->serviceCredentials();
53
54 9
        if (!isset($creds['memcached_servers'])) {
55 3
            throw new \OutOfBoundsException('Memcache credentials not found');
56
        }
57
58 6
        $servers = array();
59 6
        foreach ($creds['memcached_servers'] as $id => $url) {
60 6
            $data = parse_url($url);
61 6
            $servers[$id] = new MemcacheCredentials($data);
62 6
        }
63
64 6
        return $servers;
65
    }
66
}
67