Completed
Push — master ( d17d72...1ce681 )
by Mario
03:24
created

UsernameAndPasswordToken   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 45
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 16 5
A getAuthentication() 0 4 1
1
<?php
2
3
namespace Marek\Toggable\API\Security;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Class UsernameAndPasswordToken
9
 * @package Marek\Toggable\API\Security
10
 */
11
class UsernameAndPasswordToken implements TokenInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $username;
17
18
    /**
19
     * @var string
20
     */
21
    private $password;
22
23
    /**
24
     * UsernameAndPasswordToken constructor.
25
     *
26
     * @param string $username
27
     * @param string $password
28
     *
29
     * @throws \InvalidArgumentException
30
     */
31 4
    public function __construct($username, $password)
32
    {
33 4
        if (empty($username) || !is_string($username)) {
34 1
            throw new InvalidArgumentException(
35 1
                sprintf('Please provide username in %s', get_class($this))
36
            );
37
        }
38 4
        $this->username = $username;
39
40 4
        if (empty($password) || !is_string($password)) {
41 1
            throw new InvalidArgumentException(
42 1
                sprintf('Please provide password in %s', get_class($this))
43
            );
44
        }
45 4
        $this->password = $password;
46 4
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function getAuthentication()
52
    {
53 1
        return array($this->username, $this->password);
54
    }
55
}
56