MemcacheService::getCloudEnvironment()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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