Credentials::toArray()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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