Passed
Push — master ( a3b0d7...035240 )
by Gabor
03:51
created

NameAndPasswordCredential   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 49
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addCredential() 0 23 3
A getCredentials() 0 4 1
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Auth\Credential;
15
16
use InvalidArgumentException;
17
use WebHemi\Adapter\Auth\AuthCredentialInterface;
18
19
/**
20
 * Interface NameAndPasswordCredential
21
 */
22
class NameAndPasswordCredential implements AuthCredentialInterface
23
{
24
    /** @var string */
25
    private $username = '';
26
    /** @var string */
27
    private $password = '';
28
29
    /**
30
     * Set a credential.
31
     *
32
     * @param string $key
33
     * @param string $value
34
     * @throws InvalidArgumentException
35
     * @return AuthCredentialInterface
36
     */
37 1
    public function addCredential(string $key, string $value) : AuthCredentialInterface
38
    {
39
        switch ($key) {
40 1
            case 'username':
41 1
                $this->username = $value;
42 1
                break;
43
44 1
            case 'password':
45 1
                $this->password = $value;
46 1
                break;
47
48
            default:
49 1
                throw new InvalidArgumentException(
50
                    sprintf(
51 1
                        'Parameter #1 must be either "usenrame" or "password", %s given.',
52
                        $key
53
                    ),
54 1
                    1000
55
                );
56
        }
57
58 1
        return $this;
59
    }
60
61
    /**
62
     * Returns the credentials in a key => value array.
63
     *
64
     * @return array
65
     */
66 1
    public function getCredentials() : array
67
    {
68 1
        return ['username' => $this->username, 'password' => $this->password];
69
    }
70
}
71