Credentials   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 7
c 3
b 0
f 1
lcom 1
cbo 1
dl 0
loc 44
ccs 17
cts 17
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 17 5
A getKey() 0 4 1
A toArray() 0 4 1
1
<?php
2
namespace Wonnova\SDK\Auth;
3
4
use Wonnova\SDK\Exception\InvalidArgumentException;
5
6
/**
7
 * Class Credentials
8
 * @author Wonnova
9
 * @link http://www.wonnova.com
10
 */
11
class Credentials implements CredentialsInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $key;
17
18
    /**
19
     * @param string|array $key
20
     */
21 48
    public function __construct($key)
22
    {
23 48
        if (is_array($key)) {
24 3
            if (! isset($key['key'])) {
25 1
                throw new InvalidArgumentException('Provided array doesn\'t include a "key" element');
26
            }
27
28 2
            $this->key = $key['key'];
29 47
        } elseif (is_string($key)) {
30 44
            $this->key = $key;
31 44
        } else {
32 1
            throw new InvalidArgumentException(sprintf(
33 1
                'Expected "array" or "string", provided "%s"',
34 1
                is_object($key) ? get_class($key) : gettype($key)
35 1
            ));
36
        }
37 46
    }
38
39
    /**
40
     * @return string
41
     */
42 46
    public function getKey()
43
    {
44 46
        return $this->key;
45
    }
46
47
    /**
48
     * @return array
49
     */
50 42
    public function toArray()
51
    {
52 42
        return ['key' => $this->getKey()];
53
    }
54
}
55