CloudManager::getClouds()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the XabbuhPandaClient package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\PandaClient\Api;
13
14
/**
15
 * Manages all configured Panda clouds.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
class CloudManager implements CloudManagerInterface
20
{
21
    /**
22
     * Key to which the default Cloud is being mapped
23
     * @var string
24
     */
25
    private $defaultCloudKey;
26
27
    /**
28
     * The Clouds being managed by this CloudManager
29
     * @var CloudInterface[]
30
     */
31
    private $clouds = array();
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 9
    public function registerCloud($key, CloudInterface $cloud)
37
    {
38 9
        $this->clouds[$key] = $cloud;
39 9
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 7
    public function hasCloud($key)
45
    {
46 7
        return isset($this->clouds[$key]);
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52 7
    public function getCloud($key = null)
53
    {
54 7
        if (null === $key) {
55
            $key = $this->defaultCloudKey;
56
        }
57
58 7
        if (!$this->hasCloud($key)) {
59 3
            throw new \InvalidArgumentException('No cloud for key '.$key.' configured.');
60
        }
61
62 4
        return $this->clouds[$key];
63
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68 12
    public function setDefaultCloud($key)
69
    {
70 12
        $this->defaultCloudKey = $key;
71 12
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76 4
    public function getDefaultCloud()
77
    {
78 4
        return $this->getCloud($this->defaultCloudKey);
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84 2
    public function getClouds()
85
    {
86 2
        return $this->clouds;
87
    }
88
}
89