AccountManager::getDefaultAccount()   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
 * Manager of all accounts which can be used in the application.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
class AccountManager implements AccountManagerInterface
20
{
21
    /**
22
     * The default account's configuration key
23
     * @var string
24
     */
25
    private $defaultAccountKey;
26
27
    /**
28
     * The accounts being managed
29
     * @var Account[]
30
     */
31
    private $accounts = array();
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 10
    public function registerAccount($key, Account $account)
37
    {
38 10
        $this->accounts[$key] = $account;
39 10
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 9
    public function hasAccount($key)
45
    {
46 9
        return isset($this->accounts[$key]);
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52 9
    public function getAccount($key = null)
53
    {
54 9
        if (null === $key) {
55 2
            $key = $this->defaultAccountKey;
56
        }
57
58 9
        if (!$this->hasAccount($key)) {
59 3
            throw new \InvalidArgumentException('No account for key '.$key.' configured.');
60
        }
61
62 6
        return $this->accounts[$key];
63
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68 9
    public function setDefaultAccount($key)
69
    {
70 9
        $this->defaultAccountKey = $key;
71 9
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76 4
    public function getDefaultAccount()
77
    {
78 4
        return $this->getAccount($this->defaultAccountKey);
79
    }
80
}
81